Instagram API for Python
Instagram API for Python Developers
HikerAPI provides a REST API that works with any HTTP library. For Python, you can use the official hikerapi PyPI package or plain requests/httpx.
Installation
pip install hikerapi
Or use any HTTP library:
pip install requests
# or
pip install httpx
Quick Start with requests
import requests
API_KEY = "your_access_key"
BASE = "https://api.hikerapi.com"
headers = {"x-access-key": API_KEY}
# Get user profile
user = requests.get(
f"{BASE}/v1/user/by/username",
params={"username": "instagram"},
headers=headers,
).json()
print(f"Name: {user['full_name']}")
print(f"Followers: {user['follower_count']:,}")
print(f"Posts: {user['media_count']:,}")
Async with httpx
import httpx
import asyncio
API_KEY = "your_access_key"
BASE = "https://api.hikerapi.com"
headers = {"x-access-key": API_KEY}
async def get_profiles(usernames):
async with httpx.AsyncClient() as client:
tasks = [
client.get(
f"{BASE}/v1/user/by/username",
params={"username": u},
headers=headers,
)
for u in usernames
]
responses = await asyncio.gather(*tasks)
return [r.json() for r in responses]
profiles = asyncio.run(get_profiles(["instagram", "nike", "natgeo"]))
for p in profiles:
print(f"{p['username']}: {p['follower_count']:,} followers")
Fetch User Posts with Pagination
import requests
headers = {"x-access-key": "your_api_key"}
BASE = "https://api.hikerapi.com"
all_posts = []
max_id = None
user_id = 25025320 # instagram's user ID
while True:
params = {"user_id": user_id}
if max_id:
params["max_id"] = max_id
resp = requests.get(
f"{BASE}/v1/user/medias/chunk",
params=params,
headers=headers,
).json()
all_posts.extend(resp["items"])
max_id = resp.get("next_max_id")
if not max_id:
break
print(f"Collected {len(all_posts)} posts")
Error Handling
import requests
def api_request(endpoint, params):
resp = requests.get(
f"https://api.hikerapi.com{endpoint}",
params=params,
headers={"x-access-key": "your_api_key"},
)
if resp.status_code == 200:
return resp.json()
elif resp.status_code == 404:
print(f"Not found: {params}")
return None
else:
print(f"Error {resp.status_code}: {resp.text}")
return None
user = api_request("/v1/user/by/username", {"username": "instagram"})
FAQ
Do you have an official Python SDK?
Yes — pip install hikerapi. It wraps all endpoints with type hints. You can also use plain requests or httpx.
Does it support async?
Yes. Use httpx.AsyncClient for concurrent requests or the async methods in the SDK.
What Python version is required?
Python 3.7+ for requests, Python 3.8+ for httpx async.