Search for an Instagram API in Python and you land on three very different things: the official Graph API from Meta, data APIs that read public profiles for you, and open source libraries that drive Instagram from your own account. They do not answer the same question, so the first step is to know which data you need.
| Route | Best for | Needs | Main limit |
|---|---|---|---|
| Official Graph API | Managing your own professional account | Meta app, access token, App Review for other accounts | No followers list, no contact details |
| Data API | Followers, hashtags and emails of public accounts | An API key | Public data only |
| Instaloader | Downloading posts and metadata for personal projects | Often your own Instagram login | Your account can be limited or blocked |
1. The official Graph API with requests
The official API is plain HTTP. With a token from an Instagram professional account you can read your own media and insights, publish content and answer comments. For another business or creator account, Business Discovery returns a few public fields.
import requests
IG_USER_ID = "YOUR_IG_USER_ID"
ACCESS_TOKEN = "YOUR_ACCESS_TOKEN"
response = requests.get(
f"https://graph.facebook.com/v27.0/{IG_USER_ID}",
params={
"fields": "business_discovery.username(yourcompetitor){followers_count,media_count}",
"access_token": ACCESS_TOKEN,
},
timeout=30,
)
print(response.json()["business_discovery"])You get counts. The followers themselves and the contact email of the account are not part of the response. The details and the rate limits are in the Instagram API guide.
2. A data API with requests
When the goal is a list of people, the followers of an account or the accounts behind a hashtag with their public email, a data API does the reading and returns rows. The script below uses the IGLeads API: it starts a search, waits for it and writes a CSV file.
import csv
import time
import requests
API_KEY = "YOUR_API_KEY"
BASE_URL = "https://api.igleads.ai/v1"
HEADERS = {"Authorization": f"Bearer {API_KEY}"}
def start_search(usernames, limit):
response = requests.post(
f"{BASE_URL}/leads/competitors",
headers=HEADERS,
json={"usernames": usernames, "limit": limit, "filters": {"minFollowers": 500}},
timeout=30,
)
response.raise_for_status()
return response.json()["jobId"]
def wait_for(job_id, every=15):
while True:
job = requests.get(f"{BASE_URL}/leads/jobs/{job_id}", headers=HEADERS, timeout=30).json()["job"]
print(job["status"], job["leadsCount"], "leads")
if job["status"] in ("completed", "failed"):
return job
time.sleep(every)
def save(job_id, path):
leads = requests.get(f"{BASE_URL}/leads/jobs/{job_id}/results", headers=HEADERS, timeout=60).json()["leads"]
with open(path, "w", newline="", encoding="utf-8") as handle:
writer = csv.DictWriter(handle, fieldnames=["username", "fullName", "email", "phone", "followers", "category", "city"], extrasaction="ignore")
writer.writeheader()
writer.writerows(leads)
return len(leads)
job_id = start_search(["yourcompetitor"], limit=500)
wait_for(job_id)
print(save(job_id, "leads.csv"), "rows written")Swap the endpoint to change the audience: /leads/hashtag with a hashtags list, /leads/engagers with post links, /leads/location for a place. The followers API guide and the email API guide go through the fields and filters.
3. Instaloader
Instaloader is an open source Python tool that downloads posts, captions and profile metadata from Instagram. It is handy for archiving your own content or for a small research project.
- Many features, the followers list among them, only work when you log in with an Instagram account.
- Instagram limits or blocks accounts that request too much. The account you log in with carries that risk.
- You run, schedule and repair it yourself each time Instagram changes something.
For a one-off download it is a fine choice. For a product or a recurring pipeline, an API with a key and no Instagram login is easier to keep running. The Instaloader guide covers its limits and alternatives in detail.
Which one to pick
- You manage an account: the official API.
- You need people and contact details from public audiences: a data API.
- You archive a few profiles for yourself: Instaloader.
Frequently asked questions
Is there an official Instagram API for Python?
Meta publishes HTTP endpoints, not a Python library for the Instagram API. In Python you call them with requests or any HTTP client, using an access token from a professional account.
Can Python get the followers of an Instagram account?
Not through the official API, which returns a follower count only. A data API returns followers with their public contact details. Instaloader can list followers when you log in with your own Instagram account, which puts that account at risk.
Do I need an Instagram account to use a data API?
No. You call the API with an API key. Your code never logs in to Instagram, so there is no account to get limited or blocked.