Python

Instagram API in Python

Fetch public Instagram profiles, posts, reels, comments, and hashtags from Python with nothing but requests. No Instagram login, no session files, no proxies. One API key and a GET request.

50 free credits on signup · no card required

curl "https://api.profilequery.com/v1/profile?handle=nike" \
  -H "Authorization: Bearer $PROFILEQUERY_KEY"

What you get

Structured JSON, not raw HTML

  • ▹Works with requests, httpx, or aiohttp. There's no SDK to install
  • ▹Flat JSON that drops straight into a pandas DataFrame
  • ▹One `cursor` param for pagination on every list endpoint
  • ▹No Instagram account, so nothing gets challenged or banned
  • ▹Failed calls (bad handle, private account, upstream errors) are never billed
  • ▹50 free credits on signup to try it

Tutorial

Get Instagram data with Python

1. Get a profile

Create an API key in the dashboard and export it as PROFILEQUERY_KEY. Every endpoint is a GET request that returns { "data": ... }.

# pip install requests
import os, requests

API = "https://api.profilequery.com/v1"
session = requests.Session()
session.headers["Authorization"] = f"Bearer {os.environ['PROFILEQUERY_KEY']}"

def get(path, **params):
    r = session.get(f"{API}/{path}", params=params, timeout=60)
    r.raise_for_status()
    return r.json()["data"]

profile = get("profile", handle="nike")
print(profile["username"], profile["followers"], profile["is_verified"])

2. Page through posts

List endpoints return items plus next_cursor. Pass next_cursor back as cursor until it comes back null.

def paginate(path, max_pages=5, **params):
    cursor = None
    for _ in range(max_pages):
        page = get(path, cursor=cursor, **params) if cursor else get(path, **params)
        yield from page["items"]
        cursor = page.get("next_cursor")
        if not cursor:
            break

posts = list(paginate("profile/posts", handle="nike", max_pages=3))
print(len(posts), "posts")

3. Load into pandas

import pandas as pd

df = pd.DataFrame(posts)[["shortcode", "taken_at", "like_count", "comment_count", "view_count", "caption"]]
df["taken_at"] = pd.to_datetime(df["taken_at"])
df["engagement_rate"] = (df.like_count + df.comment_count) / profile["followers"]
print(df.sort_values("engagement_rate", ascending=False).head(10))

4. Comments and hashtags

# Comments on a post: accepts a URL, shortcode, or media id
for c in get("post/comments", post="https://www.instagram.com/p/C1a2b3c4d5e/")["items"]:
    print(c["author"]["username"], c["text"])

# Top posts for a hashtag (no #)
top = get("hashtag/top", tag="sunset")["items"]

5. Handle errors and retries

Errors come back as { "error": { "code", "message" } } with a normal HTTP status. 404 means the account or post doesn't exist or is private, 429 means slow down, and 502 is a safe-to-retry upstream hiccup. None of them cost credits.

from requests.adapters import HTTPAdapter
from urllib3.util.retry import Retry

session.mount("https://", HTTPAdapter(max_retries=Retry(
    total=3, backoff_factor=1, status_forcelist=[429, 502, 503, 504],
)))

Example response

What comes back

{
  "data": {
    "id": "13460080",
    "username": "nike",
    "full_name": "Nike",
    "biography": "Just Do It.",
    "is_verified": true,
    "is_private": false,
    "is_business": true,
    "category": null,
    "followers": 291952375,
    "following": 264,
    "posts": 1657,
    "external_url": "http://empli.fi/nike",
    "profile_pic_url": "https://instagram.com/.../nike.jpg",
    "public_email": null,
    "public_phone_number": null
  }
}

Response fields

Fields returned by GET /v1/profile

FieldDescription
idNumeric account id (stable even if the username changes).
usernameThe account's @handle.
full_nameDisplay name shown on the profile.
biographyThe profile's bio text.
is_verifiedWhether the account has a verified badge.
is_privateWhether the account is private.
is_businessWhether this is a business/professional account.
categoryBusiness category label when set (e.g. "Sportswear"); null otherwise.
followersNumber of accounts following this account.
followingNumber of accounts this account follows.
postsTotal number of posts on the profile.
external_urlThe clickable link in the bio, if any.
profile_pic_urlURL of the account's profile picture.
public_emailPublic contact email, if the account exposes one; null otherwise.
public_phone_numberPublic contact phone number, if exposed; null otherwise.

No login required

Nothing to authenticate but your API key

No OAuth flow

One static API key in an Authorization: Bearer header. No redirect, no refresh tokens, no expiring session.

No Meta app review

Never touch Meta's developer platform, Business Verification, or a connected Facebook Page. Sign up directly with Profile Query.

Public data only

Every endpoint returns only what's already visible on Instagram without logging in. Private accounts are never accessible.

Pricing

1 credit per request. Credits start at $8.00 per 1,000 and drop to $6.00 per 1,000 at volume — no subscription, no minimums. New accounts get 50 free credits.

See full pricing

FAQ

Instagram API in Python, explained

Is there an official Instagram API for Python?

Meta has no official Python SDK for reading arbitrary public accounts. The Graph API only covers business/creator accounts you connect. This API is plain REST, so it works from Python with requests or httpx and needs no SDK.

How is this different from instagrapi?

instagrapi logs in with a real Instagram account and emulates the mobile app, so you manage sessions, proxies, and bans. Here you send an API key and get JSON back. There's no Instagram login and no account at risk. instagrapi can also post and DM; this API is read-only public data.

Can I use it asynchronously?

Yes. Use httpx.AsyncClient or aiohttp with the same Authorization header and run requests concurrently with asyncio.gather.

How much does it cost to run from Python?

Most calls are 1–2 credits. Credits start at $8.00 per 1,000 and drop to $6.00 at volume, with no subscription.

Start pulling python data

Create a free key and make your first request in under a minute — 50 credits on us.