The InstaClient class

InstaTweet.instaclient.USER_AGENT

Hardcoded user agent proven to work with the get_user() endpoint introduced in v2.0.0b13

InstaClient.DOWNLOAD_DIR

[Optional] – Directory to temporarily download media to

class InstaTweet.instaclient.InstaClient(session_id, user_agent=USER_AGENT, proxies=None)[source]View on GitHub

Bases: object

Minimalistic class for scraping/downloading Instagram user/media data

__init__(session_id, user_agent=USER_AGENT, proxies=None)[source]View on GitHub

Initialize an InstaClient with an Instagram sessionid cookie (at minimum)

Note

As of v2.0.0b13, the endpoint used by get_user() seems to require a specific USER_AGENT You can override the hardcoded one if you’d like, but you’ll likely get a "useragent mismatch" response

Parameters
  • session_id (str) – valid Instagram sessionid cookie from a browser

  • user_agent (str) – user agent to use in requests made by the class

  • proxies (Optional[dict]) – proxies to use in requests made by the class

request(url)[source]View on GitHub

Sends a request using the cookies, headers, and proxies

Parameters

url (str) – the Instagram URL to send the request to

Return type

Response

get_user(username)[source]View on GitHub

Scrapes an Instagram user’s profile and wraps the response

Parameters

username (str) – the username of the IG user to scrape (without the @)

Returns

an InstaUser object, which wraps the response data

Return type

InstaUser

download_post(post, filepath=None)[source]View on GitHub

Downloads the media from an Instagram post

Parameters
Return type

bool

property headers: dict

Headers to use in request()

property cookies: dict

Cookies to use in request()