Skip to main content

A client interface for the Instagram automation.

Project description

Insta_cs API

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

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.

Features

  • Supports many functions that are only available through the official app, such as:
    • Multiple feeds, such as [user feed], [location feed], [tag feed], [popular feed]
    • Post a [photo]or [video] to your feed or stories
    • [Like]/[unlike] posts
    • Get [post comments]
    • [Post]/[delete] comments
    • [Like]/[unlike] comments
    • [Follow]/[unfollow] users
    • User [stories]
    • And [more]
  • The web api client supports a subset of functions that do not require login, such as:
    • Get user [info] and [feed]
    • Get [post comments]
    • And [more]
  • 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

Documentation is available at https://github.com/Charanpreet-Singh-AI/Insta_cs

Install

Install with pip:

pip install insta_cs

To update:

pip install insta_cs --upgrade

To update with latest repo code:

pip install insta_cs --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 insta_cs 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 insta_web_cs 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/firstmodified

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.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

insta_cs-1.0.4.tar.gz (68.3 kB view details)

Uploaded Source

Built Distribution

insta_cs-1.0.4-py3-none-any.whl (78.0 kB view details)

Uploaded Python 3

File details

Details for the file insta_cs-1.0.4.tar.gz.

File metadata

  • Download URL: insta_cs-1.0.4.tar.gz
  • Upload date:
  • Size: 68.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for insta_cs-1.0.4.tar.gz
Algorithm Hash digest
SHA256 9694cb0380c74f937379447e55cf726a0a41471ef5e8211df40448f6effd0003
MD5 588757a7a3490322a2c2bf762997e7e1
BLAKE2b-256 b80ea899d253cfd5e0f02bbd37f963b2235d7612092f572ee3560dc0273e00f6

See more details on using hashes here.

File details

Details for the file insta_cs-1.0.4-py3-none-any.whl.

File metadata

  • Download URL: insta_cs-1.0.4-py3-none-any.whl
  • Upload date:
  • Size: 78.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.11.1

File hashes

Hashes for insta_cs-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 ffc2406d8966b4a03c98dfc7b6a004ac6db7eeae96df11c3ed5e5d4507208d71
MD5 7f8f9dd453d89856f046e18a6e80e09c
BLAKE2b-256 288d0bdef944d52907528440ee4a7c9199bba039e81bce5aca57d285630bce50

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page