Asynchronous Instagram Private API wrapper
Project description
aiograpi - Asynchronous Instagram API for Python
If you want to work with aiograpi (business interests), we strongly advise you to prefer HikerAPI project. However, you won't need to spend weeks or even months setting it up. The best service available today is HikerAPI, which handles 4–5 million daily requests, provides support around-the-clock, and offers partners a special rate. In many instances, our clients tried to save money and preferred aiograpi, but in our experience, they ultimately returned to HikerAPI after spending much more time and money. It will be difficult to find good accounts, good proxies, or resolve challenges, and IG will ban your accounts.
The aiograpi more suits for testing or research than a working business!
We recommend using our services:
- LamaTok for TikTok API 🔥
- HikerAPI for Instagram API ⚡⚡⚡
- DataLikers for Instagram Datasets 🚀
Features:
- Getting public data of user, posts, stories, highlights, followers and following users
- Getting public email and phone number, if the user specified them in his business profile
- Getting public data of post, story, album, Reels, IGTV data and the ability to download content
- Getting public data of hashtag and location data, as well as a list of posts for them
- Getting public data of all comments on a post and a list of users who liked it
- Management of proxy servers, mobile devices and challenge resolver
- Login by username and password, sessionid and support 2FA
- Managing messages and threads for Direct and attach files
- Download and upload a Photo, Video, IGTV, Reels, Albums and Stories
- Work with Users, Posts, Comments, Insights, Collections, Location and Hashtag
- Insights by account, posts and stories
- Like, following, commenting, editing account (Bio) and much more else
Asynchronous Instagram Private API wrapper without selenium. Use the most recent version of the API from Instagram, which was obtained using reverse-engineering with Charles Proxy and Proxyman.
Support Python >= 3.10
For any other languages (e.g. C++, C#, F#, D, Golang, Erlang, Elixir, Nim, Haskell, Lisp, Closure, Julia, R, Java, Kotlin, Scala, OCaml, JavaScript, Crystal, Ruby, Rust, Swift, Objective-C, Visual Basic, .NET, Pascal, Perl, Lua, PHP and others), I suggest using instagrapi-rest
Support Chat in Telegram
and GitHub Discussions
Features
- Performs Web API or Mobile API requests depending on the situation (to avoid Instagram limits)
- Login by username and password, including 2FA and by sessionid (and uses Authorization header instead Cookies)
- Challenge Resolver have Email and SMS handlers
- Support upload a Photo, Video, IGTV, Reels, Albums and Stories
- Support work with User, Media, Comment, Insights, Collections, Location (Place), Hashtag and Direct Message objects
- Like, Follow, Edit account (Bio) and much more else
- Insights by account, posts and stories
- Build stories with custom background, font animation, link sticker and mention users
- Account registration and captcha passing will appear
Versioning policy — we stay in 0.x
aiograpi follows ZeroVer. We will not ship 1.0,
because it would be a misleading promise. Instagram's private API
rotates doc_ids, deprecates endpoints, and changes response shapes
without notice — we cannot guarantee a stable API surface across
versions. Pretending otherwise hurts users who'd take "1.0" to mean
"safe to pin and forget".
What you can rely on instead:
- Breaking changes are flagged in the CHANGELOG with a
Breakingsection per affected release. No silent breakage. - Deprecated methods stay around for ≥2 minor releases with
DeprecationWarningbefore removal — you'll get loud warnings, not surpriseAttributeErrors. - Live CI smoke runs on every push:
tests/live/smoke.pyagainst a real account through a real proxy. If we ship something that breaks the basic happy path, CI catches it. - Migration Guide at docs/migration.md — every breaking change documented with before/after.
What's new in 0.6.x and 0.7.x
- Sync with instagrapi 2.4.4 — every mixin and infrastructure module ported, plus three new mixins:
ExploreMixin,FundraiserMixin, and opt-inCaptchaHandlerMixin. - doc_id GraphQL primitive —
Client.public_doc_id_graphql_request(doc_id, variables)andClient.private_graphql_query_request(...)for the newi.instagram.com/graphql/querysurface IG migrated to. New high-level methods:user_info_v2_gql,user_info_by_username_v2_gql,private_graphql_followers_list/following_list/clips_profile/inbox_tray_for_user,private_graphql_memories_pog/realtime_region_hint/top_audio_trends_eligible_categories, plusfbsearch_keyword_typeahead/fbsearch_typeahead_stream/fbsearch_item,feed_user_stream_item,media_comment_infos. All live-verified. - Pure helpers go sync (breaking from 0.0.x):
media_pk_from_code,media_code_from_pk,media_pk,share_info,share_code_from_url,share_info_by_url,highlight_pk_from_url,handle_challenge_result,challenge_resolve_new_password_formno longer requireawait. See Migration Guide for the full list. - PEP 561 typed (
py.typed) — mypy / pyright pick up annotations from the installed package. - CI publish-on-tag with PyPI trusted publishing — push a version tag, GitHub Actions builds, publishes, and creates a release.
Full per-release notes: CHANGELOG.md.
Migrating from 0.0.x?
See the Migration Guide.
Installation
pip install aiograpi
Basic Usage
from aiograpi import Client
cl = Client()
await cl.login(ACCOUNT_USERNAME, ACCOUNT_PASSWORD)
user_id = await cl.user_id_from_username(ACCOUNT_USERNAME)
medias = await cl.user_medias(user_id, 20)
Session Persistence
Logging in fresh on every run is the fastest way to get your account flagged. Persist the session and reuse it:
from aiograpi import Client
cl = Client()
await cl.login(USERNAME, PASSWORD)
cl.dump_settings("session.json")
# reload later without entering credentials again
cl = Client()
cl.load_settings("session.json")
await cl.login(USERNAME, PASSWORD)
If you want explicit control over the loaded session object:
from aiograpi import Client
cl = Client()
cl.set_settings(cl.load_settings("session.json"))
await cl.login(USERNAME, PASSWORD)
Login by sessionid
from aiograpi import Client
cl = Client()
await cl.login_by_sessionid("<your_sessionid>")
login_by_sessionid() is a lightweight compatibility path. For long-lived
automation prefer the regular login() → dump_settings() →
load_settings() / set_settings() flow.
Typical Tasks
List and download another user's posts
target_id = await cl.user_id_from_username("target_user")
posts = await cl.user_medias(target_id, amount=10)
for media in posts:
await cl.photo_download(media.pk)
Search a location by name
places = await cl.location_search("Times Square")
print(places[0].name, places[0].pk)
Followers via the new private GraphQL surface
import uuid
data = await cl.private_graphql_followers_list(
user_id="25025320",
rank_token=str(uuid.uuid4()),
)
# Raw GraphQL envelope: {"data": {...}, "status": "ok", ...}
See Private GraphQL & doc_id for the full new-mobile-API surface (followers, clips, search, inbox).
Additional example (story upload with mentions / hashtags / media)
from aiograpi import Client
from aiograpi.types import StoryMention, StoryMedia, StoryLink, StoryHashtag
cl = Client()
await cl.login(USERNAME, PASSWORD, verification_code="<2FA CODE HERE>")
media_pk = await cl.media_pk_from_url('https://www.instagram.com/p/CGgDsi7JQdS/')
media_path = await cl.video_download(media_pk)
subzeroid = await cl.user_info_by_username('subzeroid')
hashtag = await cl.hashtag_info('dhbastards')
await cl.video_upload_to_story(
media_path,
"Credits @subzeroid",
mentions=[StoryMention(user=subzeroid, x=0.49892962, y=0.703125, width=0.8333333333333334, height=0.125)],
links=[StoryLink(webUri='https://github.com/subzeroid/aiograpi')],
hashtags=[StoryHashtag(hashtag=hashtag, x=0.23, y=0.32, width=0.5, height=0.22)],
medias=[StoryMedia(media_pk=media_pk, x=0.5, y=0.5, width=0.6, height=0.8)]
)
Documentation
- Index
- Getting Started
- Migration Guide — for users coming from
0.0.x - Usage Guide
- Interactions
Media- Publication (also called post): Photo, Video, Album, IGTV and ReelsResource- Part of Media (for albums)MediaOembed- Short version of MediaAccount- Full private info for your account (e.g. email, phone_number)TOTP- 2FA TOTP helpers (generate seed, enable/disable TOTP, generate code as Google Authenticator)User- Full public user dataUserShort- Short public user data (used in Usertag, Comment, Media, Direct Message)Usertag- Tag user in Media (coordinates + UserShort)Location- GEO location (GEO coordinates, name, address)Hashtag- Hashtag object (id, name, picture)Collection- Collection of medias (name, picture and list of medias)Comment- Comments to MediaHighlight- HighlightsNotes- NotesStory- StoryStoryLink- Link StickerStoryLocation- Tag Location in Story (as sticker)StoryMention- Mention users in Story (user, coordinates and dimensions)StoryHashtag- Hashtag for story (as sticker)StorySticker- Tag sticker to story (for example from giphy)StoryBuild- StoryBuilder return path to photo/video and mention co-ordinatesDirectThread- Thread (topic) with messages in Direct MessageDirectMessage- Message in Direct MessageInsight- Insights for a postTrack- Music track (for Reels/Clips)
- Captcha - Opt-in handler interface for solver integrations
- Explore - Explore page methods
- Fundraiser - Fundraiser info
- Best Practices
- Development Guide
- Handle Exceptions
- Challenge Resolver
- Exceptions
Contributing
Releasing
Releases are automated via the publish.yml GitHub Actions workflow with PyPI
trusted publishing. To cut a new release:
- Bump
version=insetup.py. - Add a section to
CHANGELOG.md. - Commit and push to
main. - Tag:
git tag -a 0.x.y -m "Release 0.x.y" && git push origin 0.x.y.
The workflow then builds sdist + wheel, verifies the tag matches setup.py,
publishes to PyPI, and creates the GitHub release with both artefacts attached
— no API tokens needed.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file aiograpi-0.8.9.tar.gz.
File metadata
- Download URL: aiograpi-0.8.9.tar.gz
- Upload date:
- Size: 151.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
43a1143503ef349a44845f22b592f6e1f80980417bd7c33c235fed8034f0a799
|
|
| MD5 |
7c0cc26d497de3d8d85ef3e9dd28488a
|
|
| BLAKE2b-256 |
b60c7a29cc01a00604a1bb6fef42cb05a7666dd858f30eae6c195c51c899a8b5
|
Provenance
The following attestation bundles were made for aiograpi-0.8.9.tar.gz:
Publisher:
publish.yml on subzeroid/aiograpi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aiograpi-0.8.9.tar.gz -
Subject digest:
43a1143503ef349a44845f22b592f6e1f80980417bd7c33c235fed8034f0a799 - Sigstore transparency entry: 1398949240
- Sigstore integration time:
-
Permalink:
subzeroid/aiograpi@7165f444810dc78cf7837518e47d944740772f36 -
Branch / Tag:
refs/tags/0.8.9 - Owner: https://github.com/subzeroid
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7165f444810dc78cf7837518e47d944740772f36 -
Trigger Event:
push
-
Statement type:
File details
Details for the file aiograpi-0.8.9-py3-none-any.whl.
File metadata
- Download URL: aiograpi-0.8.9-py3-none-any.whl
- Upload date:
- Size: 165.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
ad075ee6e375eaa2600c85fcac3333c19f39c32af0e2f73320019c0b452821a2
|
|
| MD5 |
9f5fc10bcbb1ed916c327cfb7c871316
|
|
| BLAKE2b-256 |
b80f23454e99eb2d490dfaab5db89238879b87f3c5f6c92a98d53137eb2c13d8
|
Provenance
The following attestation bundles were made for aiograpi-0.8.9-py3-none-any.whl:
Publisher:
publish.yml on subzeroid/aiograpi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
aiograpi-0.8.9-py3-none-any.whl -
Subject digest:
ad075ee6e375eaa2600c85fcac3333c19f39c32af0e2f73320019c0b452821a2 - Sigstore transparency entry: 1398949259
- Sigstore integration time:
-
Permalink:
subzeroid/aiograpi@7165f444810dc78cf7837518e47d944740772f36 -
Branch / Tag:
refs/tags/0.8.9 - Owner: https://github.com/subzeroid
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yml@7165f444810dc78cf7837518e47d944740772f36 -
Trigger Event:
push
-
Statement type: