Package: threads-py-wrapper
threads.pyUnofficial API for Threads by Instagram. With type hints.InstallingTo install the library on Linux:python3 -m pip install threads-py-wrapperTo install the library on Windows:py -m pip install threads-py-wrapperPython 3.8 or higher is needed for the libraryThis library will be under active development so please raise the issue with your concerns and errors.WrapperAvailable MethodsExpandlogin(self) -> boolDescription: Logs in the user and obtains the private API token.Returns: bool - True if login is successful, False otherwise.get_user_id(self, username: str, instagram: bool = False) -> intDescription: Gets the user ID from either Threads or Instagram for the corresponding username.Parameters:username (str): The username to get the ID for.instagram (bool, optional): If True, search for the user on Instagram. Default is False.Returns: int - The user ID.get_user_profile(self, user_id: int) -> ThreadsUserDescription: Gets the user profile for a given user ID.Parameters:user_id (int): The user ID.Returns: ThreadsUser - The ThreadsUser object containing user profile information.search_user(self, query: str) -> SearchUsersResponseDescription: Searches for users based on a query string provided.Parameters:query (str): The search query.Returns: SearchUsersResponse - The response object containing search results.get_thread(self, user_id: int) -> ThreadResponseDescription: Gets the thread information for a given thread ID.Parameters:user_id (int): The thread ID.Returns: ThreadResponse - The response object containing thread information.get_user_threads(self, user_id: int) -> List[Thread]Description: Gets the threads associated with a user with the provided user ID.Parameters:user_id (int): The user ID.Returns: List[Thread] - A list of Thread objects.get_user_followers(self, user_id: int) -> UserFollowersResponseDescription: Gets the followers of a user with the provided user ID.Parameters:user_id (int): The user ID.Returns: UserFollowersResponse - The response object containing follower information.get_user_following(self, user_id: int) -> UserFollowingResponseDescription: Gets the users a user is following.Parameters:user_id (int): The user ID.Returns: UserFollowingResponse - The response object containing following information.get_friendship_status(self, user_id: int) -> FriendshipStatusResponseDescription: Gets the friendship status with another user.Parameters:user_id (int): The user ID.Returns: FriendshipStatusResponse - The response object containing friendship status.follow_user(self, user_id: int) -> FriendshipStatusResponseDescription: Follows a user with the provided user ID.Parameters:user_id (int): The user ID.Returns: FriendshipStatusResponse - The response object containing friendship status after following.unfollow_user(self, user_id: int) -> FriendshipStatusResponseDescription: Unfollows a user with the provided user ID.Parameters:user_id (int): The user ID.Returns: FriendshipStatusResponse - The response object containing friendship status after unfollowing.mute_user(self, user_id: int) -> FriendshipStatusResponseDescription: Mutes a user with the provided user ID.Parameters:user_id (int): The user ID.Returns: FriendshipStatusResponse - The response object containing friendship status after muting.unmute_user(self, user_id: int) -> FriendshipStatusResponseDescription: Unmutes a user with the provided user ID.Parameters:user_id (int): The user ID.Returns: FriendshipStatusResponse - The response object containing friendship status after unmuting.restrict_user(self, user_id: int) -> RestrictResponseDescription: Restricts a user with the provided user ID.Parameters:user_id (int): The user ID.Returns: RestrictResponse - The response object containing restrict status.unrestrict_user(self, user_id: int) -> RestrictResponseDescription: Unrestricts a user with the provided user ID.Parameters:user_id (int): The user ID.Returns: RestrictResponse - The response object containing restrict status after unrestricting.block_user(self, user_id: int) -> FriendshipStatusResponseDescription: Blocks a user with the provided user ID.Parameters:user_id (int): The user ID.Returns: FriendshipStatusResponse - The response object containing friendship status after blocking.unblock_user(self, user_id: int) -> FriendshipStatusResponseDescription: Unblocks a user with the provided user ID.Parameters:user_id (int): The user ID.Returns: FriendshipStatusResponse - The response object containing friendship status after unblocking.like(self, thread_id: int) -> boolDescription: Likes a thread with the provided thread ID.Parameters:thread_id (int): The ID of the thread to like.Returns: bool - True if the like is successful, False otherwise.unlike(self, thread_id: int) -> boolDescription: Unlikes a thread with the provided thread ID.Parameters:thread_id (int): The ID of the thread to unlike.Returns: bool - True if the unlike is successful, False otherwise.repost(self, thread_id: int) -> RepostDataDescription: Reposts a thread with the provided thread ID.Parameters:thread_id (int): The ID of the thread to repost.Returns: RepostData - The response object containing repost data.unrepost(self, original_thread_id: int) -> boolDescription: Unreposts a thread with the provided original thread ID.Parameters:thread_id (int): The ID of the original thread to unrepost.Returns: bool - True if the unrepost is successful, False otherwise.delete(self, thread_id: int) -> boolDescription: Deletes a thread with the provided thread ID.Parameters:thread_id (int): The ID of the thread to delete.Returns: bool - True if the deletion is successful, False otherwise.create(self, text: str, url: str = None, image: Optional[Union[str, List]] = None, reply_to: int = None) -> dictDescription: Creates a new thread.Parameters:text (str): The text content of the thread.url (str, optional): The URL to include in the thread. Default is None.image (str or list, optional): The image or list of images to include in the thread. Default is None.reply_to (int, optional): The ID of the thread to reply to. Default is None.Returns: dict - The response JSON containing the details of the newly created thread.Customized TypesExpand1. Threads Userget_user_threads() -> List[Thread]Returns: List[Thread]Description: Get the threads of this user.get_user_followers() -> UserFollowersResponseReturns: UserFollowersResponseDescription: Get this user's followers.get_user_following() -> UserFollowingResponseReturns: UserFollowingResponseDescription: Get the users followed by this user.get_friendship_status() -> FriendshipStatusResponseReturns: FriendshipStatusResponseDescription: Get the friendship status of this user with the logged-in user.follow_user() -> FriendshipStatusResponseReturns: FriendshipStatusResponseDescription: Follow this user.unfollow_user() -> FriendshipStatusResponseReturns: FriendshipStatusResponseDescription: Unfollow this user.mute_user() -> FriendshipStatusResponseReturns: FriendshipStatusResponseDescription: Mute this user.unmute_user() -> FriendshipStatusResponseReturns: FriendshipStatusResponseDescription: Unmute this user.restrict_user() -> RestrictResponseReturns: RestrictResponseDescription: Restrict this user.unrestrict_user() -> RestrictResponseReturns: RestrictResponseDescription: Unrestrict this user.block_user() -> FriendshipStatusResponseReturns: FriendshipStatusResponseDescription: Block this user.unblock_user() -> FriendshipStatusResponseReturns: FriendshipStatusResponseDescription: Unblock this user.2. ThreadlikeReturns:boolDescription: Likes this thread. ReturnsTrueif the liking is successful,Falseotherwise.unlikeReturns:boolDescription: Unlikes this thread. ReturnsTrueif the unliking is successful,Falseotherwise.repostReturns:RepostDataDescription: Reposts this thread. Returns the data associated with the repost.unrepostReturns:boolDescription: Un-reposts this thread. ReturnsTrueif the un-reposting is successful,Falseotherwise.deleteReturns:boolDescription: Deletes this thread. ReturnsTrueif the deletion is successful,Falseotherwise.ExampleIt is very easy to work with this library everything is type hinted and the names are straight forward, also go through the above Customized Types section to use this library efficiently. Here is a small example.import threadspy
import os

USERNAME = os.environ.get("USERNAME")
PASSWORD = os.environ.get("PASSWORD")


threads_api = threadspy.ThreadsApi(USERNAME, PASSWORD)
login_status = threads_api.login()

if login_status:
    user_id = threads_api.get_user_id('zuck')    # Get the user id of zuck
    
    zuck = threads_api.get_user_profile(user_id) # Get the user profile of zuck
    
    zuck.follow_user()                           # Follow zuck (Customized type)
    
    zuck_threads = zuck.get_user_threads()       # Get the threads of zuck

    for thread in zuck_threads[:3]:              # Like the first 3 threads of zuck
        thread.like()
        print(f"Liked thread with ID: {thread.id} and Caption: {thread.posts[0].caption.text}" )
else:
    print("Login failed")⚠️ Be cautious and try the library with your Alt Account. There is always risk of getting banned.Important ConceptSettings and Threads TokenSettings is a json file that store the settings that were used to login using the provided.threads_token is the unique token that is obtained after logging in and is used for the subsequent requests.threads_api = threadspy.ThreadsApi(USERNAME, PASSWORD, settings_file="/path/to/settings", token_path="/path/to/token")Its a good idea to provide these paths, but if not provided then thesettings.jsonandthreads_token.binwill be store in the directory from where the code is run.RoadmapImplement remaining methodsPost ID from Thread IDThread LikersTimelineUser Profile RepliesImplement all the test casesInvestigate 2FA loginSeperate public and private APIOwn login flow instead of just depending on instagrapi