Skip to main content

Instagram Private API

A Python wrapper for the Instagram private API with no 3rd party dependencies. Supports both the app and web APIs.

Python 2.7, 3.5 Release Docs Build

Build

Overview

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.

Features

An extension module is available to help with common tasks like pagination, posting photos or videos.

Documentation

Documentation is available at https://instagram-private-api.readthedocs.io/en/latest/

Install

Install with pip:

pip install git+https://git@github.com/ping/instagram_private_api.git@1.6.0

To update:

pip install git+https://git@github.com/ping/instagram_private_api.git@1.6.0 --upgrade

To update with latest repo code:

pip install git+https://git@github.com/ping/instagram_private_api.git --upgrade --force-reinstall

Tested on Python 2.7 and 3.5.

Usage

The app API client emulates the official app and has a larger set of functions. The web API client has a smaller set but can be used without logging in.

Your choice will depend on your use case.

The examples/ and tests/ are a good source of detailed sample code on how to use the clients, including a simple way to save the auth cookie for reuse.

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.

Avoiding Re-login

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.

Donate

Want to keep this project going? Please donate generously https://www.buymeacoffee.com/ping

Build

Support

Make sure to review the contributing documentation before submitting an issue report or pull request.

Legal

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.

Release files for instagram-private-api 1.6.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for instagram-private-api 1.6.0.0
File Size Uploaded
instagram_private_api-1.6.0.0.tar.gz 66.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for instagram-private-api 1.6.0.0
File Interpreter ABI Platform
instagram_private_api-1.6.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 145.4 kB

Release files / instagram_private_api-1.6.0.0.tar.gz

Download URL instagram_private_api-1.6.0.0.tar.gz
Size 66.5 kB
Tags Source
SHA-256 checksum
How to use checksums
dfe0c2cb5aa881b98b2e428c3b02fa664a52af3f2d2354c19c4a8967cedf5d8e
BLAKE2b-256 checksum
How to use checksums
ca81282d8f016de44260296e1fd50ec6aaadb6c542d3bab982eb14783b54cf8b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1

Release files / instagram_private_api-1.6.0.0-py3-none-any.whl

Download URL instagram_private_api-1.6.0.0-py3-none-any.whl
Size 78.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
5f9403fbd359764b2d070fa8ac22bc4546ec5a53c45676bcddafa66dc74d2f07
BLAKE2b-256 checksum
How to use checksums
554c6a37c5f1f2777191104970452ff495d2579ffcdfa73d2cb617e865f9c554
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/1.13.0 pkginfo/1.5.0.1 requests/2.20.0 setuptools/40.5.0 requests-toolbelt/0.9.1 tqdm/4.31.1 CPython/3.7.1

Release history Release notifications | RSS feed

This release

1.6.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page