Huge News!Announcing our $40M Series B led by Abstract Ventures.Learn More
Socket
Sign inDemoInstall
Socket

instpector

Package Overview
Dependencies
Maintainers
1
Alerts
File Explorer

Advanced tools

Socket logo

Install Socket

Detect and block malicious and high-risk dependencies

Install

instpector

A simple Instagram's web API library

  • 0.2.7
  • PyPI
  • Socket score

Maintainers
1

Instpector

A simple Instagram's web API library written in Python. Supports login with two-factor authentication enabled. No selenium or webdriver required.

Installation

pip install instpector

Sample usage

from instpector import Instpector, endpoints

instpector = Instpector()
instpector.login("my_username", "my_password")

profile = endpoints.factory.create("profile", instpector)
followers = endpoints.factory.create("followers", instpector)

insta_profile = profile.of_user("some_username")

# Loop through all followers
for follower in followers.of_user(insta_profile.id):
    print(follower.username)

instpector.logout()

Using 2FA

For login in using two-factor authentication, generate your 2fa key once on the Instagram's app and provide the code when logging in with instpector. The following example uses pytop library to demonstrate the usage:

from pyotp import TOTP
from instpector import Instpector, endpoints

instpector = Instpector()
totp = TOTP("my_2fa_key") # Input without spaces

# Login into Instagram's web
instpector.login("my_username", "my_password", totp.now())

Examples

Check out more examples here.

Endpoints

  • Followers
  • Following
  • Timeline
  • Comments
  • Profile
  • Story Reel
  • Story

More to come

API

Classes

Instpector

MethodDetails
login(user: str, password: str, two_factor_code: str = None) -> boolLogin to an Instagram account. If your account is 2FA protected provide the 2FA code as in the provided example.
logout()Logouts from an Instagram account.
session() -> SessionReturns the current session used by instpector.

EndpointFactory

MethodDetails
create(endpoint_name: str, instpector_instance: Instpector)Creates and returns an endpoint instance based on the provided name. Available endpoint names are: "followers", "following", "profile", "timeline", "comments" "story_reel" and "story".

Endpoints

Profile

Gets the profile of any public or friend user account.

MethodDetails
of_user(username: str) -> TProfileReturns a TProfile instance for the provided username.
follow(user: TProfile | str) -> boolFollows a user. You can provide a TProfile instance or an Instagram's user Id.
unfollow(user: TProfile | str) -> boolUnfollows a user. You can provide a TProfile instance or an Instagram's user Id.
activity() -> TActivityYields a list of TActivity items for the current logged in account.

Followers

Endpoint for accessing the follower list of any public or friend user account.

MethodDetails
of_user(user_id: str) -> TUserYields a list of TUser instances with all followers. Note the method receives a user id and not a username. To get the user id use the Profile endpoint.

Following

Endpoint for accessing the followees list of any public or friend user account.

MethodDetails
of_user(user_id: str) -> TUserYields a list of TUser instances with all followees. Note the method receives a user id and not a username. To get the user id use the Profile endpoint.

Timeline

Endpoint for accessing the timeline of any public or friend account.

MethodDetails
of_user(user_id: str) -> TTimelinePostYields a list of TTimelinePost instances with all timeline posts. Note the method receives a user id and not a username. To get the user id use the Profile endpoint.
download(timeline_post: TTimelinePost, only_image: bool = False, low_quality: bool = False)Downloads and save the available resources (image and video) for the provided TTimelinePost. The file name convention is ownerid_resourceid.extension and saved in the execution directory. If low_quality is True the resource will be the downloaded with the lowest size available (only for image). If only_image is True a video file resource won't be downloaded.
like(timeline_post: TTimelinePost | TActivityPost) -> boolLikes a post.
unlike(timeline_post: TTimelinePost | TActivityPost) -> boolUnlikes a post.

Comments

Endponint for accessing comments and threaded comments of any public or friends post or comment.

MethodDetails
of_post(timeline_post: TTimelinePost | TActivityPost) -> TCommentYields a list of TComment instances with all post comments.
of_comment(comment: TComment) -> TCommentYields a list of TComment instances with all threaded comments of a comment.
like(comment: TComment) -> boolLikes a comment.
unlike(comment: TComment) -> boolUnlikes a comment.
add(timeline_post: TTimelinePost | TActivityPost, text: str, parent_comment: TComment = None) -> TComment | NoneAdds a new comment to a post. You can reply to a comment if parent_comment argument is provided. An instance of the created comment is return if succeeded otherwise None.
remove(timeline_post: TTimelinePost | TActivityPost, comment: TComment) -> boolRemoves a comment from a post. Only comments authored by the current logged in account can be removed.

StoryReel

Endpoint for accessing the story reel (stories) of any public or friend user account.

MethodDetails
of_user(user_id: str) -> TStoryReelItemYields a list of TStoryReelItem instances with all stories. Note the method receives a user id and not a username. To get a user id use the Profile endpoint.
download(story_item: TStoryReelItem, only_image: bool = False, low_quality: bool = False)Downloads and save the available resources (image and video) for the provided TStoryReelItem. The file name convention is ownerid_resourceid.extension and saved in the execution directory. If low_quality is True the resource will be the downloaded with the lowest size available. If only_image is True a video file resource won't be downloaded.

Story

Endpoint for accessing the story details of a story reel item. This endpoint is only available for stories posted by the current logged in user.

MethodDetails
viewers_for(story_id: str) -> TStoryViewerYields a list of TStoryViewer instances with all viewers of the provided story id.

Types

TUser

FieldTypeDetails
idstrThe Instagram Id of the user
usernamestrThe user's name
full_namestrThe full name of the user
is_privateboolA flag to show if the user account is private

TProfile

FieldTypeDetails
idstrThe Instagram Id of the user
usernamestrThe user's name
biographystrThe biography of the user
is_privateboolA flag to show if the user account is private
followers_countintegerThe follower count of the user
following_countintegerThe following count of the user

TTimelinePost

FieldTypeDetails
idstrThe Instagram Id of the post
shortcodestrThe Instagram shortcode Id of the post
ownerstrThe post author's Instagram Id
timestampintegerThe created timestamp of the post
captionstrThe caption of the post
is_videoboolA flag to know if the post is a video
like_countintegerThe like count of the post
comment_countintegerThe comment count of the post
display_resourceslistA list of image URL strings associated with the post
video_urlstrThe video URL (if available) associated with the post

TComment

FieldTypeDetails
idstrThe Instagram Id of the comment
textstrThe text of the comment
usernamestrThe author's username
timestampintegerThe timestamp of the comment
viewer_has_likedboolA flag to know if the viewer liked the comment
liked_countintegerThe like count of the comment
thread_countinteger | NoneThe comment's thread comments count. This value is None if the instance is a threaded comment.

TStoryReelItem

FieldTypeDetails
idstrThe Instagram Id of the story
ownerstrThe story author's Instagram Id
timestampintegerThe created timestamp of the story
expire_atintegerThe expiration timestamp of the story
audiencestrThe type of audience of the story. If public the value is MediaAudience.DEFAULT, if private the value is MediaAudience.BESTIES
is_videoboolA flag to know if the story is a video
view_countintegerThe view count of the story. The count is only available for stories posted by the currently logged in user. Other accounts will have a count equal to 0
display_resourceslistA list of image URL strings associated with the story
video_resourceslistA list of video URL strings associated with the story

TStoryViewer

FieldTypeDetails
idstrThe Instagram Id of the story viewer
usernamestrThe user name of the viewer

TActivity

FieldTypeDetails
idstrThe Instagram Id of the activity
timestampintegerThe timestamp of the activity
usernamestrThe user name linked to the activity
activity_typestrThe activity type. Either NEW_LIKE or NEW_FOLLOW
liked_postTActivityPost | NoneIf the activity type is NEW_LIKE, an TActivityPost instance is returned

TActivityPost

FieldTypeDetails
idstrThe Instagram Id of the post
shortcodestrThe Instagram shortcode Id of the post
thumbnail_resourceslistA list of thumbnails URL strings associated with the post

Development dependencies

  • requests

Tests

  1. Create a pytest.ini file with the sample contents of pytest.sample.ini in the tests directory.

  2. Add your account information.

  3. Run with pytest:

(env)$ pytest -qs tests

Disclaimer

This tool is not affiliated with, authorized, maintained or endorsed by Instagram or any of its affiliates or subsidiaries. Use at your own risk.

License

Licensed under MIT License.

Keywords

FAQs


Did you know?

Socket

Socket for GitHub automatically highlights issues in each pull request and monitors the health of all your open source dependencies. Discover the contents of your packages and block harmful activity before you install or update your dependencies.

Install

Related posts

SocketSocket SOC 2 Logo

Product

  • Package Alerts
  • Integrations
  • Docs
  • Pricing
  • FAQ
  • Roadmap
  • Changelog

Packages

npm

Stay in touch

Get open source security insights delivered straight into your inbox.


  • Terms
  • Privacy
  • Security

Made with ⚡️ by Socket Inc