A client interface for the private Instagram API.
Instagram Private API
A Python wrapper for the Instagram private API with no 3rd party dependencies. Supports both the app and web APIs.
I wrote this to access Instagram's API when they clamped down on developer access. Because this is meant to achieve parity with the official public API, methods not available in the public API will generally have lower priority.
Problems? Please check the docs before submitting an issue.
- Supports many functions that are only available through the official app, such as:
- The web api client supports a subset of functions that do not require login, such as:
- Compatible with functions available through the public API using the ClientCompatPatch (app/web) utility class
- Beta Python 3 support
An extension module is available to help with common tasks like pagination, posting photos or videos.
Documentation is available at https://instagram-private-api.readthedocs.io/en/latest/
Install with pip:
pip install git+https://firstname.lastname@example.orgemail@example.com
pip install git+https://firstname.lastname@example.orgemail@example.com --upgrade
To update with latest repo code:
pip install git+https://firstname.lastname@example.org/ping/instagram_private_api.git --upgrade --force-reinstall
Tested on Python 2.7 and 3.5.
Your choice will depend on your use case.
Option 1: Use the official app's API
from instagram_private_api import Client, ClientCompatPatch user_name = 'YOUR_LOGIN_USER_NAME' password = 'YOUR_PASSWORD' api = Client(user_name, password) results = api.feed_timeline() items = [item for item in results.get('feed_items', ) if item.get('media_or_ad')] for item in items: # Manually patch the entity to match the public api as closely as possible, optional # To automatically patch entities, initialise the Client with auto_patch=True ClientCompatPatch.media(item['media_or_ad']) print(item['media_or_ad']['code'])
Option 2: Use the official website's API
from instagram_web_api import Client, ClientCompatPatch, ClientError, ClientLoginError # Without any authentication web_api = Client(auto_patch=True, drop_incompat_keys=False) user_feed_info = web_api.user_feed('329452045', count=10) for post in user_feed_info: print('%s from %s' % (post['link'], post['user']['username'])) # Some endpoints, e.g. user_following are available only after authentication authed_web_api = Client( auto_patch=True, authenticate=True, username='YOUR_USERNAME', password='YOUR_PASSWORD') following = authed_web_api.user_following('123456') for user in following: print(user['username']) # Note: You can and should cache the cookie even for non-authenticated sessions. # This saves the overhead of a single http request when the Client is initialised.
You are advised to persist/cache the auth cookie details to avoid logging in every time you make an api call. Excessive logins is a surefire way to get your account flagged for removal. It's also advisable to cache the client details such as user agent, etc together with the auth details.
The saved auth cookie can be reused for up to 90 days.
Want to keep this project going? Please donate generously https://www.buymeacoffee.com/ping
Make sure to review the contributing documentation before submitting an issue report or pull request.
Disclaimer: This is not affliated, endorsed or certified by Instagram. This is an independent and unofficial API. Strictly not for spam. Use at your own risk.
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
|Filename, size||File type||Python version||Upload date||Hashes|
|Filename, size instagram_private_api-22.214.171.124-py3-none-any.whl (78.9 kB)||File type Wheel||Python version py3||Upload date||Hashes View|
|Filename, size instagram_private_api-126.96.36.199.tar.gz (66.5 kB)||File type Source||Python version None||Upload date||Hashes View|
Hashes for instagram_private_api-188.8.131.52-py3-none-any.whl
Hashes for instagram_private_api-184.108.40.206.tar.gz