Package: instpector
InstpectorA simple Instagram's web API library written in Python. Supports login with two-factor authentication enabled. No selenium or webdriver required.Installationpip install instpectorSample usagefrominstpectorimportInstpector,endpointsinstpector=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 followersforfollowerinfollowers.of_user(insta_profile.id):print(follower.username)instpector.logout()Using 2FAFor login in using two-factor authentication, generate your 2fa key once on the  Instagram's app and provide the code when logging in withinstpector. The following example usespytoplibrary to demonstrate the usage:frompyotpimportTOTPfrominstpectorimportInstpector,endpointsinstpector=Instpector()totp=TOTP("my_2fa_key")# Input without spaces# Login into Instagram's webinstpector.login("my_username","my_password",totp.now())ExamplesCheck out more exampleshere.EndpointsFollowersFollowingTimelineCommentsProfileStory ReelStoryMore to comeAPIClassesInstpectorMethodDetailslogin(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 theprovided example.logout()Logouts from an Instagram account.session() ->SessionReturns the current session used byinstpector.EndpointFactoryMethodDetailscreate(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".EndpointsProfileGets the profile of any public or friend user account.MethodDetailsof_user(username:str) ->TProfileReturns aTProfileinstance for the provided username.follow(user:TProfile|str) ->boolFollows a user. You can provide aTProfileinstance or an Instagram's user Id.unfollow(user:TProfile|str) ->boolUnfollows a user. You can provide aTProfileinstance or an Instagram's user Id.activity() ->TActivityYields a list ofTActivityitems for the current logged in account.FollowersEndpoint for accessing the follower list of any public or friend user account.MethodDetailsof_user(user_id:str) ->TUserYields a list ofTUserinstances with all followers. Note the method receives a user id and not a username. To get the user id use theProfileendpoint.FollowingEndpoint for accessing the followees list of any public or friend user account.MethodDetailsof_user(user_id:str) ->TUserYields a list ofTUserinstances with all followees. Note the method receives a user id and not a username. To get the user id use theProfileendpoint.TimelineEndpoint for accessing the timeline of any public or friend account.MethodDetailsof_user(user_id:str) ->TTimelinePostYields a list ofTTimelinePostinstances with all timeline posts. Note the method receives a user id and not a username. To get the user id use theProfileendpoint.download(timeline_post:TTimelinePost, only_image:bool= False, low_quality:bool= False)Downloads and save the available resources (image and video) for the providedTTimelinePost. The file name convention isownerid_resourceid.extensionand saved in the execution directory. Iflow_qualityisTruethe resource will be the downloaded with the lowest size available (only for image). Ifonly_imageisTruea video file resource won't be downloaded.like(timeline_post:TTimelinePost|TActivityPost) ->boolLikes a post.unlike(timeline_post:TTimelinePost|TActivityPost) ->boolUnlikes a post.CommentsEndponint for accessing comments and threaded comments of any public or friends post or comment.MethodDetailsof_post(timeline_post:TTimelinePost|TActivityPost) ->TCommentYields a list ofTCommentinstances with all post comments.of_comment(comment:TComment) ->TCommentYields a list ofTCommentinstances 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 ifparent_commentargument is provided. An instance of the created comment is return if succeeded otherwiseNone.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.StoryReelEndpoint for accessing the story reel (stories) of any public or friend user account.MethodDetailsof_user(user_id:str) ->TStoryReelItemYields a list ofTStoryReelIteminstances with all stories. Note the method receives a user id and not a username. To get a user id use theProfileendpoint.download(story_item:TStoryReelItem, only_image:bool= False, low_quality:bool= False)Downloads and save the available resources (image and video) for the providedTStoryReelItem. The file name convention isownerid_resourceid.extensionand saved in the execution directory. Iflow_qualityisTruethe resource will be the downloaded with the lowest size available. Ifonly_imageisTruea video file resource won't be downloaded.StoryEndpoint for accessing the story details of a story reel item. This endpoint is only available for stories posted by the current logged in user.MethodDetailsviewers_for(story_id:str) ->TStoryViewerYields a list ofTStoryViewerinstances with all viewers of the provided story id.TypesTUserFieldTypeDetailsidstrThe Instagram Id of the userusernamestrThe user's namefull_namestrThe full name of the useris_privateboolA flag to show if the user account is privateTProfileFieldTypeDetailsidstrThe Instagram Id of the userusernamestrThe user's namebiographystrThe biography of the useris_privateboolA flag to show if the user account is privatefollowers_countintegerThe follower count of the userfollowing_countintegerThe following count of the userTTimelinePostFieldTypeDetailsidstrThe Instagram Id of the postshortcodestrThe Instagram shortcode Id of the postownerstrThe post author's Instagram IdtimestampintegerThe created timestamp of the postcaptionstrThe caption of the postis_videoboolA flag to know if the post is a videolike_countintegerThe like count of the postcomment_countintegerThe comment count of the postdisplay_resourceslistA list of image URL strings associated with the postvideo_urlstrThe video URL (if available) associated with the postTCommentFieldTypeDetailsidstrThe Instagram Id of the commenttextstrThe text of the commentusernamestrThe author's usernametimestampintegerThe timestamp of the commentviewer_has_likedboolA flag to know if the viewer liked the commentliked_countintegerThe like count of the commentthread_countinteger|NoneThe comment's thread comments count. This value isNoneif the instance is a threaded comment.TStoryReelItemFieldTypeDetailsidstrThe Instagram Id of the storyownerstrThe story author's Instagram IdtimestampintegerThe created timestamp of the storyexpire_atintegerThe expiration timestamp of the storyaudiencestrThe type of audience of the story. If public the value isMediaAudience.DEFAULT, if private the value isMediaAudience.BESTIESis_videoboolA flag to know if the story is a videoview_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 to0display_resourceslistA list of image URL strings associated with the storyvideo_resourceslistA list of video URL strings associated with the storyTStoryViewerFieldTypeDetailsidstrThe Instagram Id of the story viewerusernamestrThe user name of the viewerTActivityFieldTypeDetailsidstrThe Instagram Id of the activitytimestampintegerThe timestamp of the activityusernamestrThe user name linked to the activityactivity_typestrThe activity type. EitherNEW_LIKEorNEW_FOLLOWliked_postTActivityPost|NoneIf the activity type isNEW_LIKE, anTActivityPostinstance is returnedTActivityPostFieldTypeDetailsidstrThe Instagram Id of the postshortcodestrThe Instagram shortcode Id of the postthumbnail_resourceslistA list of thumbnails URL strings associated with the postDevelopment dependenciesrequestsTestsCreate apytest.inifile with the sample contents ofpytest.sample.iniin thetestsdirectory.Add your account information.Run withpytest:(env)$ pytest -qs testsDisclaimerThis tool is not affiliated with, authorized, maintained or endorsed by Instagram or any of its affiliates or subsidiaries. Use at your own risk.LicenseLicensed under MIT License.