Skip to main content

Overview

The Client class provides authenticated access to the Twitter API. All methods are asynchronous and must be executed using await.

Initialization

from twikit import Client

client = Client(
    language='en-US',
    proxy='http://proxy.example.com:8080',  # optional
    captcha_solver=capsolver,  # optional
    user_agent='custom user agent'  # optional
)
language
str
default:"en-US"
The language code to use in API requests (e.g., ‘en-US’, ‘ja-JP’).
proxy
str | None
default:"None"
The proxy server URL to use for requests (e.g., ‘http://0.0.0.0:8080’).
captcha_solver
Capsolver | None
default:"None"
A Capsolver instance for automatic CAPTCHA solving. See the Capsolver documentation.
user_agent
str | None
default:"None"
Custom user agent string. If not provided, a default user agent will be used.

Authentication

login

Logs into a Twitter account using the specified credentials.
await client.login(
    auth_info_1='example_user',
    auth_info_2='[email protected]',
    password='your_password'
)
auth_info_1
str
required
The first piece of authentication information: username, email address, or phone number.
auth_info_2
str | None
default:"None"
The second piece of authentication information (optional but recommended). Can be username, email, or phone number.
password
str
required
The account password.
totp_secret
str | None
default:"None"
The TOTP secret key for two-factor authentication (2FA).
cookies_file
str | None
default:"None"
File path for storing/loading cookies. If the file exists, cookies are loaded from it, potentially bypassing login.
enable_ui_metrics
bool
default:"True"
If True, executes obfuscated ui_metrics function to reduce account suspension risk.
return
dict
Response data from the login flow.

logout

Logs out of the currently logged-in account.
await client.logout()
return
Response
HTTP response from the logout request.

unlock

Unlocks the account using the provided CAPTCHA solver.
await client.unlock()
Requires a captcha_solver to be configured during client initialization.

get_cookies

Retrieves the current session cookies.
cookies = client.get_cookies()
return
dict
Dictionary containing session cookies.

save_cookies

Saves cookies to a file in JSON format.
client.save_cookies('cookies.json')
path
str
required
File path where cookies will be saved.

load_cookies

Loads cookies from a file.
client.load_cookies('cookies.json')
path
str
required
Path to the file containing saved cookies.

set_cookies

Sets cookies from a dictionary.
client.set_cookies(cookies_dict, clear_cookies=False)
cookies
dict
required
Dictionary of cookies to set.
clear_cookies
bool
default:"False"
If True, clears existing cookies before setting new ones.

User Operations

user_id

Retrieves the user ID of the authenticated account.
user_id = await client.user_id()
return
str
The user ID of the authenticated account.

user

Retrieves detailed information about the authenticated user.
user = await client.user()
return
User
User object with detailed information about the authenticated user.

get_user_by_screen_name

Fetches a user by their screen name (username).
user = await client.get_user_by_screen_name('elonmusk')
print(user.name)
print(user.followers_count)
screen_name
str
required
The screen name (username) of the Twitter user.
return
User
User object representing the Twitter user.

get_user_by_id

Fetches a user by their user ID.
user = await client.get_user_by_id('44196397')
user_id
str
required
The ID of the Twitter user.
return
User
User object representing the Twitter user.

follow_user

Follows a user.
user = await client.follow_user('123456789')
user_id
str
required
The ID of the user to follow.
return
User
The followed user.

unfollow_user

Unfollows a user.
user = await client.unfollow_user('123456789')
user_id
str
required
The ID of the user to unfollow.
return
User
The unfollowed user.

block_user

Blocks a user.
user = await client.block_user('123456789')
user_id
str
required
The ID of the user to block.
return
User
The blocked user.

unblock_user

Unblocks a user.
user = await client.unblock_user('123456789')
user_id
str
required
The ID of the user to unblock.
return
User
The unblocked user.

mute_user

Mutes a user.
user = await client.mute_user('123456789')
user_id
str
required
The ID of the user to mute.
return
User
The muted user.

unmute_user

Unmutes a user.
user = await client.unmute_user('123456789')
user_id
str
required
The ID of the user to unmute.
return
User
The unmuted user.

get_user_tweets

Fetches tweets from a specific user’s timeline.
tweets = await client.get_user_tweets(
    user_id='44196397',
    tweet_type='Tweets',
    count=20
)

for tweet in tweets:
    print(tweet.text)

# Get more tweets
more_tweets = await tweets.next()
user_id
str
required
The ID of the Twitter user whose tweets to retrieve.
tweet_type
'Tweets' | 'Replies' | 'Media' | 'Likes'
required
The type of tweets to retrieve.
count
int
default:"40"
The number of tweets to retrieve.
cursor
str | None
default:"None"
Cursor for pagination.
return
Result[Tweet]
A Result object containing a list of Tweet objects with pagination support.

get_user_highlights_tweets

Retrieves highlighted tweets from a user’s timeline.
tweets = await client.get_user_highlights_tweets('123456789', count=20)
user_id
str
required
The user ID.
count
int
default:"20"
The number of tweets to retrieve.
cursor
str | None
default:"None"
Cursor for pagination.
return
Result[Tweet]
Result object containing highlighted tweets.

get_user_followers

Retrieves a list of followers for a given user.
followers = await client.get_user_followers('123456789', count=20)

for follower in followers:
    print(follower.screen_name)

more_followers = await followers.next()
user_id
str
required
The ID of the user for whom to retrieve followers.
count
int
default:"20"
The number of followers to retrieve.
cursor
str | None
default:"None"
Cursor for pagination.
return
Result[User]
Result object containing User objects representing followers.

get_user_verified_followers

Retrieves a list of verified followers for a given user.
verified_followers = await client.get_user_verified_followers('123456789', count=20)
user_id
str
required
The ID of the user.
count
int
default:"20"
The number of verified followers to retrieve.
cursor
str | None
default:"None"
Cursor for pagination.
return
Result[User]
Result object containing verified followers.

get_user_followers_you_know

Retrieves a list of common followers (followers you both follow).
common_followers = await client.get_user_followers_you_know('123456789', count=20)
user_id
str
required
The ID of the user.
count
int
default:"20"
The number of common followers to retrieve.
cursor
str | None
default:"None"
Cursor for pagination.
return
Result[User]
Result object containing common followers.

get_user_following

Retrieves a list of users whom the given user is following.
following = await client.get_user_following('123456789', count=20)
user_id
str
required
The ID of the user.
count
int
default:"20"
The number of following users to retrieve.
cursor
str | None
default:"None"
Cursor for pagination.
return
Result[User]
Result object containing User objects representing followed users.

get_user_subscriptions

Retrieves a list of users to which the specified user is subscribed.
subscriptions = await client.get_user_subscriptions('123456789', count=20)
user_id
str
required
The ID of the user.
count
int
default:"20"
The number of subscriptions to retrieve.
cursor
str | None
default:"None"
Cursor for pagination.
return
Result[User]
Result object containing subscribed users.

get_latest_followers

Retrieves the latest followers (max count: 200).
followers = await client.get_latest_followers(
    user_id='123456789',
    count=200
)
user_id
str | None
default:"None"
The ID of the user.
screen_name
str | None
default:"None"
The screen name of the user.
count
int
default:"200"
The maximum number of followers to retrieve (max 200).
cursor
str | None
default:"None"
Cursor for pagination.
return
Result[User]
Result object containing latest followers.

get_latest_friends

Retrieves the latest friends/following users (max count: 200).
friends = await client.get_latest_friends(
    user_id='123456789',
    count=200
)
user_id
str | None
default:"None"
The ID of the user.
screen_name
str | None
default:"None"
The screen name of the user.
count
int
default:"200"
The maximum number of friends to retrieve (max 200).
cursor
str | None
default:"None"
Cursor for pagination.
return
Result[User]
Result object containing latest friends.

get_followers_ids

Fetches the IDs of the followers of a specified user.
follower_ids = await client.get_followers_ids(
    user_id='123456789',
    count=5000
)
user_id
str | None
default:"None"
The ID of the user.
screen_name
str | None
default:"None"
The screen name of the user.
count
int
default:"5000"
The maximum number of IDs to retrieve.
cursor
str | None
default:"None"
Cursor for pagination.
return
Result[int]
Result object containing follower IDs.

get_friends_ids

Fetches the IDs of the friends (following users) of a specified user.
friend_ids = await client.get_friends_ids(
    user_id='123456789',
    count=5000
)
user_id
str | None
default:"None"
The ID of the user.
screen_name
str | None
default:"None"
The screen name of the user.
count
int
default:"5000"
The maximum number of IDs to retrieve.
cursor
str | None
default:"None"
Cursor for pagination.
return
Result[int]
Result object containing friend IDs.

Tweet Operations

create_tweet

Creates a new tweet with text, media, and/or poll.
await client.create_tweet('Hello, Twitter!')
text
str
default:"''"
The text content of the tweet.
media_ids
list[str] | None
default:"None"
A list of media IDs to attach. Media IDs are obtained via upload_media().
poll_uri
str | None
default:"None"
The URI of a Twitter poll card. Poll URIs are obtained via create_poll().
reply_to
str | None
default:"None"
The ID of the tweet to which this tweet is a reply.
conversation_control
'followers' | 'verified' | 'mentioned' | None
default:"None"
Limits who can reply:
  • 'followers': Only followers can reply
  • 'verified': Only verified accounts can reply
  • 'mentioned': Only mentioned accounts can reply
attachment_url
str | None
default:"None"
URL of the tweet to quote.
community_id
str | None
default:"None"
ID of the community to post in.
share_with_followers
bool
default:"False"
If True, shares community tweet with followers.
is_note_tweet
bool
default:"False"
If True, allows tweets longer than 280 characters (Twitter Premium only).
richtext_options
list[dict] | None
default:"None"
Options for text formatting (Twitter Premium only).
edit_tweet_id
str | None
default:"None"
ID of the tweet to edit (Twitter Premium only).
return
Tweet
The created Tweet object.

delete_tweet

Deletes a tweet.
await client.delete_tweet('1234567890')
tweet_id
str
required
ID of the tweet to delete.
return
Response
HTTP response from the API.

get_tweet_by_id

Fetches a tweet by its ID.
tweet = await client.get_tweet_by_id('1234567890')
print(tweet.text)
print(tweet.user.name)

# Access replies
for reply in tweet.replies:
    print(reply.text)
tweet_id
str
required
The ID of the tweet.
cursor
str | None
default:"None"
Cursor for pagination.
return
Tweet
Tweet object with replies, reply_to, and related_tweets populated.

get_tweets_by_ids

Retrieves multiple tweets by their IDs.
tweet_ids = ['1111111111', '1111111112', '111111113']
tweets = await client.get_tweets_by_ids(tweet_ids)

for tweet in tweets:
    print(tweet.text)
ids
list[str]
required
A list of tweet IDs to retrieve.
return
list[Tweet]
List of Tweet objects.

search_tweet

Searches for tweets based on a query.
tweets = await client.search_tweet(
    query='python programming',
    product='Latest',
    count=20
)

for tweet in tweets:
    print(f"{tweet.user.name}: {tweet.text}")

more_tweets = await tweets.next()
query
str
required
The search query.
product
'Top' | 'Latest' | 'Media'
required
The type of tweets to retrieve:
  • 'Top': Most relevant tweets
  • 'Latest': Most recent tweets
  • 'Media': Tweets with media
count
int
default:"20"
Number of tweets to retrieve (1-20).
cursor
str | None
default:"None"
Token to retrieve more tweets.
return
Result[Tweet]
Result object containing search results with pagination.

get_scheduled_tweets

Retrieves scheduled tweets.
scheduled = await client.get_scheduled_tweets()

for tweet in scheduled:
    print(f"Scheduled for: {tweet.scheduled_at}")
    print(f"Text: {tweet.text}")
return
list[ScheduledTweet]
List of ScheduledTweet objects.

create_scheduled_tweet

Schedules a tweet for posting at a specified time.
import time

scheduled_time = int(time.time()) + 3600  # One hour from now

media_ids = [await client.upload_media('image.png')]

tweet_id = await client.create_scheduled_tweet(
    scheduled_at=scheduled_time,
    text='This will post in an hour!',
    media_ids=media_ids
)
scheduled_at
int
required
Unix timestamp when the tweet should be posted.
text
str
default:"''"
The text content of the tweet.
media_ids
list[str] | None
default:"None"
List of media IDs to attach.
return
str
The ID of the scheduled tweet.

delete_scheduled_tweet

Deletes a scheduled tweet.
await client.delete_scheduled_tweet('1234567890')
tweet_id
str
required
The ID of the scheduled tweet to delete.
return
Response
HTTP response from the API.

get_similar_tweets

Retrieves tweets similar to a specified tweet (Twitter Premium only).
similar = await client.get_similar_tweets('1234567890')

for tweet in similar:
    print(tweet.text)
tweet_id
str
required
The ID of the tweet.
return
list[Tweet]
List of similar tweets.

favorite_tweet

Likes a tweet.
await client.favorite_tweet('1234567890')
tweet_id
str
required
The ID of the tweet to like.
return
Response
HTTP response from the API.

unfavorite_tweet

Unlikes a tweet.
await client.unfavorite_tweet('1234567890')
tweet_id
str
required
The ID of the tweet to unlike.
return
Response
HTTP response from the API.

retweet

Retweets a tweet.
await client.retweet('1234567890')
tweet_id
str
required
The ID of the tweet to retweet.
return
Response
HTTP response from the API.

delete_retweet

Removes a retweet.
await client.delete_retweet('1234567890')
tweet_id
str
required
The ID of the retweeted tweet.
return
Response
HTTP response from the API.

get_retweeters

Retrieves users who retweeted a specific tweet.
retweeters = await client.get_retweeters('1234567890', count=40)

for user in retweeters:
    print(user.name)

more_retweeters = await retweeters.next()
tweet_id
str
required
The ID of the tweet.
count
int
default:"40"
The maximum number of users to retrieve.
cursor
str | None
default:"None"
Cursor for pagination.
return
Result[User]
Result object containing users who retweeted.

get_favoriters

Retrieves users who liked a specific tweet.
favoriters = await client.get_favoriters('1234567890', count=40)

for user in favoriters:
    print(user.name)
tweet_id
str
required
The ID of the tweet.
count
int
default:"40"
The maximum number of users to retrieve.
cursor
str | None
default:"None"
Cursor for pagination.
return
Result[User]
Result object containing users who liked the tweet.

get_community_note

Fetches a community note by ID.
note = await client.get_community_note('1234567890')
print(note.text)
note_id
str
required
The ID of the community note.
return
CommunityNote
CommunityNote object.

Timeline Operations

get_timeline

Retrieves the “For You” timeline.
tweets = await client.get_timeline(count=20)

for tweet in tweets:
    print(tweet.text)

more_tweets = await tweets.next()
count
int
default:"20"
The number of tweets to retrieve.
seen_tweet_ids
list[str] | None
default:"None"
List of tweet IDs that have been seen.
cursor
str | None
default:"None"
Cursor for pagination.
return
Result[Tweet]
Result object containing timeline tweets.

get_latest_timeline

Retrieves the “Following” timeline.
tweets = await client.get_latest_timeline(count=20)

for tweet in tweets:
    print(f"{tweet.user.name}: {tweet.text}")
count
int
default:"20"
The number of tweets to retrieve.
seen_tweet_ids
list[str] | None
default:"None"
List of tweet IDs that have been seen.
cursor
str | None
default:"None"
Cursor for pagination.
return
Result[Tweet]
Result object containing timeline tweets.

Media Operations

upload_media

Uploads media to Twitter.
media_id = await client.upload_media('photo.jpg')
source
str | bytes
required
File path or bytes of the media content.
wait_for_completion
bool
default:"False"
Whether to wait for media processing to complete.
status_check_interval
float | None
default:"None"
Interval in seconds to check upload status.
media_type
str | None
default:"None"
MIME type of the media. Auto-detected if not specified.
media_category
str | None
default:"None"
Media category (e.g., ‘tweet_gif’, ‘dm_gif’).
is_long_video
bool
default:"False"
If True, allows videos longer than 2:20 (Twitter Premium only).
return
str
The media ID of the uploaded media.
For GIF uploads with wait_for_completion=True, you must specify media_category as either ‘dm_gif’ or ‘tweet_gif’.

check_media_status

Checks the processing status of uploaded media.
status = await client.check_media_status('media_id_here')
print(status['processing_info']['state'])
media_id
str
required
The media ID of the uploaded media.
is_long_video
bool
default:"False"
Whether this is a long video upload.
return
dict
Dictionary containing media processing status information.

create_media_metadata

Adds metadata (alt text and content warnings) to uploaded media.
media_id = await client.upload_media('image.jpg')

await client.create_media_metadata(
    media_id,
    alt_text='A beautiful sunset over the ocean',
    sensitive_warning=['other']
)

await client.create_tweet('Check this out!', media_ids=[media_id])
media_id
str
required
The media ID for which to create metadata.
alt_text
str | None
default:"None"
Alternative text description for the media.
sensitive_warning
list['adult_content' | 'graphic_violence' | 'other'] | None
default:"None"
List of sensitive content warnings.
return
Response
HTTP response from the API.

Poll Operations

create_poll

Creates a poll and returns its card URI.
choices = ['Python', 'JavaScript', 'Rust', 'Go']
duration_minutes = 1440  # 24 hours

poll_uri = await client.create_poll(choices, duration_minutes)
await client.create_tweet('What is your favorite language?', poll_uri=poll_uri)
choices
list[str]
required
List of poll choices (maximum 4).
duration_minutes
int
required
Poll duration in minutes.
return
str
The URI of the created poll card.

vote

Votes on a poll.
tweet = await client.get_tweet_by_id('1234567890')

if tweet.poll:
    updated_poll = await client.vote(
        selected_choice='Option A',
        card_uri=tweet.poll.card_uri,
        tweet_id=tweet.id,
        card_name=tweet.poll.name
    )
    print(f"Total votes: {updated_poll.total_votes}")
selected_choice
str
required
The label of the selected choice.
card_uri
str
required
The URI of the poll card.
tweet_id
str
required
The ID of the tweet containing the poll.
card_name
str
required
The name of the poll card.
return
Poll
Updated Poll object after voting.

Bookmark Operations

bookmark_tweet

Adds a tweet to bookmarks.
# Bookmark to default folder
await client.bookmark_tweet('1234567890')

# Bookmark to specific folder
await client.bookmark_tweet('1234567890', folder_id='folder_id')
tweet_id
str
required
The ID of the tweet to bookmark.
folder_id
str | None
default:"None"
The ID of the folder to add the bookmark to.
return
Response
HTTP response from the API.

delete_bookmark

Removes a tweet from bookmarks.
await client.delete_bookmark('1234567890')
tweet_id
str
required
The ID of the tweet to remove from bookmarks.
return
Response
HTTP response from the API.

get_bookmarks

Retrieves bookmarked tweets.
bookmarks = await client.get_bookmarks(count=20)

for tweet in bookmarks:
    print(tweet.text)

more_bookmarks = await bookmarks.next()
count
int
default:"20"
The number of bookmarks to retrieve.
cursor
str | None
default:"None"
Cursor for pagination.
folder_id
str | None
default:"None"
Folder ID to retrieve bookmarks from.
return
Result[Tweet]
Result object containing bookmarked tweets.

delete_all_bookmarks

Deletes all bookmarks.
await client.delete_all_bookmarks()
return
Response
HTTP response from the API.
This action cannot be undone. All bookmarks will be permanently deleted.

get_bookmark_folders

Retrieves bookmark folders.
folders = await client.get_bookmark_folders()

for folder in folders:
    print(f"{folder.name}: {folder.id}")

more_folders = await folders.next()
cursor
str | None
default:"None"
Cursor for pagination.
return
Result[BookmarkFolder]
Result object containing bookmark folders.

create_bookmark_folder

Creates a new bookmark folder.
folder = await client.create_bookmark_folder('My Important Tweets')
print(f"Created folder: {folder.id}")
name
str
required
Name of the folder.
return
BookmarkFolder
The created bookmark folder.

edit_bookmark_folder

Edits a bookmark folder’s name.
folder = await client.edit_bookmark_folder('folder_id', 'New Name')
folder_id
str
required
ID of the folder to edit.
name
str
required
New name for the folder.
return
BookmarkFolder
The updated bookmark folder.

delete_bookmark_folder

Deletes a bookmark folder.
await client.delete_bookmark_folder('folder_id')
folder_id
str
required
ID of the folder to delete.
return
Response
HTTP response from the API.

Direct Message Operations

send_dm

Sends a direct message to a user.
message = await client.send_dm(
    user_id='123456789',
    text='Hello!'
)
print(f"Message sent: {message.id}")
user_id
str
required
The ID of the user to send the message to.
text
str
required
The text content of the message.
media_id
str | None
default:"None"
Media ID to include in the message. Obtained via upload_media().
reply_to
str | None
default:"None"
Message ID to reply to.
return
Message
Message object containing information about the sent message.

delete_dm

Deletes a direct message.
await client.delete_dm('message_id')
message_id
str
required
The ID of the message to delete.
return
Response
HTTP response from the API.

get_dm_history

Retrieves DM conversation history with a user.
messages = await client.get_dm_history('123456789')

for message in messages:
    print(f"{message.sender_id}: {message.text}")

more_messages = await messages.next()
user_id
str
required
The ID of the user.
max_id
str | None
default:"None"
If specified, retrieves messages older than this message ID.
return
Result[Message]
Result object containing messages.

add_reaction_to_message

Adds an emoji reaction to a message.
conversation_id = f'123456789-{await client.user_id()}'

await client.add_reaction_to_message(
    message_id='message_id',
    conversation_id=conversation_id,
    emoji='❤️'
)
message_id
str
required
The ID of the message.
conversation_id
str
required
The ID of the conversation. Format: partner_id-your_id or group ID.
emoji
str
required
The emoji to add as a reaction.
return
Response
HTTP response from the API.

remove_reaction_from_message

Removes an emoji reaction from a message.
conversation_id = f'123456789-{await client.user_id()}'

await client.remove_reaction_from_message(
    message_id='message_id',
    conversation_id=conversation_id,
    emoji='❤️'
)
message_id
str
required
The ID of the message.
conversation_id
str
required
The ID of the conversation.
emoji
str
required
The emoji reaction to remove.
return
Response
HTTP response from the API.

Group Message Operations

send_dm_to_group

Sends a message to a group.
media_id = await client.upload_media('image.png')

message = await client.send_dm_to_group(
    group_id='group_id',
    text='Hello everyone!',
    media_id=media_id
)
group_id
str
required
The ID of the group.
text
str
required
The text content of the message.
media_id
str | None
default:"None"
Media ID to include.
reply_to
str | None
default:"None"
Message ID to reply to.
return
GroupMessage
GroupMessage object containing information about the sent message.

get_group_dm_history

Retrieves DM history from a group.
messages = await client.get_group_dm_history('group_id')

for message in messages:
    print(f"{message.sender_id}: {message.text}")
group_id
str
required
The ID of the group.
max_id
str | None
default:"None"
If specified, retrieves messages older than this message ID.
return
Result[GroupMessage]
Result object containing group messages.

get_group

Retrieves information about a group.
group = await client.get_group('group_id')
print(f"Group name: {group.name}")
print(f"Members: {len(group.participants)}")
group_id
str
required
The ID of the group.
return
Group
Group object containing group information.

add_members_to_group

Adds members to a group.
await client.add_members_to_group(
    group_id='group_id',
    user_ids=['user_id_1', 'user_id_2']
)
group_id
str
required
ID of the group.
user_ids
list[str]
required
List of user IDs to add.
return
Response
HTTP response from the API.

change_group_name

Changes a group’s name.
await client.change_group_name('group_id', 'New Group Name')
group_id
str
required
ID of the group.
name
str
required
New name for the group.
return
Response
HTTP response from the API.

List Operations

create_list

Creates a new list.
list = await client.create_list(
    name='Tech News',
    description='Accounts posting about technology',
    is_private=True
)
name
str
required
The name of the list.
description
str
default:"''"
The description of the list.
is_private
bool
default:"False"
Whether the list is private (True) or public (False).
return
List
The created List object.

get_list

Retrieves a list by ID.
list = await client.get_list('list_id')
print(list.name)
print(list.member_count)
list_id
str
required
The ID of the list.
return
List
List object.

get_lists

Retrieves user’s lists.
lists = await client.get_lists(count=100)

for list in lists:
    print(f"{list.name}: {list.member_count} members")

more_lists = await lists.next()
count
int
default:"100"
The number of lists to retrieve.
cursor
str | None
default:"None"
Cursor for pagination.
return
Result[List]
Result object containing lists.

edit_list

Edits list information.
updated_list = await client.edit_list(
    list_id='list_id',
    name='New Name',
    description='New description',
    is_private=True
)
list_id
str
required
The ID of the list to edit.
name
str | None
default:"None"
New name for the list.
description
str | None
default:"None"
New description for the list.
is_private
bool | None
default:"None"
Whether the list should be private.
return
List
The updated List object.

add_list_member

Adds a user to a list.
await client.add_list_member('list_id', 'user_id')
list_id
str
required
The ID of the list.
user_id
str
required
The ID of the user to add.
return
List
The updated List object.

remove_list_member

Removes a user from a list.
await client.remove_list_member('list_id', 'user_id')
list_id
str
required
The ID of the list.
user_id
str
required
The ID of the user to remove.
return
List
The updated List object.

get_list_tweets

Retrieves tweets from a list.
tweets = await client.get_list_tweets('list_id', count=20)

for tweet in tweets:
    print(tweet.text)

more_tweets = await tweets.next()
list_id
str
required
The ID of the list.
count
int
default:"20"
The number of tweets to retrieve.
cursor
str | None
default:"None"
Cursor for pagination.
return
Result[Tweet]
Result object containing tweets from the list.

get_list_members

Retrieves members of a list.
members = await client.get_list_members('list_id', count=20)

for member in members:
    print(member.name)

more_members = await members.next()
list_id
str
required
The ID of the list.
count
int
default:"20"
Number of members to retrieve.
cursor
str | None
default:"None"
Cursor for pagination.
return
Result[User]
Result object containing list members.

get_list_subscribers

Retrieves subscribers of a list.
subscribers = await client.get_list_subscribers('list_id', count=20)
list_id
str
required
The ID of the list.
count
int
default:"20"
Number of subscribers to retrieve.
cursor
str | None
default:"None"
Cursor for pagination.
return
Result[User]
Result object containing list subscribers.

search_list

Searches for lists based on a query.
lists = await client.search_list('python', count=20)

for list in lists:
    print(f"{list.name}: {list.description}")

more_lists = await lists.next()
query
str
required
The search query.
count
int
default:"20"
The number of lists to retrieve.
cursor
str | None
default:"None"
Cursor for pagination.
return
Result[List]
Result object containing search results.

edit_list_banner

Edits the banner image of a list.
media_id = await client.upload_media('banner.png')
await client.edit_list_banner('list_id', media_id)
list_id
str
required
The ID of the list.
media_id
str
required
The ID of the media to use as banner.
return
Response
HTTP response from the API.

delete_list_banner

Deletes a list’s banner.
await client.delete_list_banner('list_id')
list_id
str
required
The ID of the list.
return
Response
HTTP response from the API.

Community Operations

search_community

Searches for communities.
communities = await client.search_community('python')

for community in communities:
    print(f"{community.name}: {community.member_count} members")

more_communities = await communities.next()
query
str
required
The search query.
cursor
str | None
default:"None"
Cursor for pagination.
return
Result[Community]
Result object containing communities.

get_community

Retrieves a community by ID.
community = await client.get_community('community_id')
print(community.name)
print(community.description)
community_id
str
required
The ID of the community.
return
Community
Community object.

join_community

Joins a community.
community = await client.join_community('community_id')
community_id
str
required
The ID of the community to join.
return
Community
The joined community.

leave_community

Leaves a community.
community = await client.leave_community('community_id')
community_id
str
required
The ID of the community to leave.
return
Community
The left community.

request_to_join_community

Requests to join a private community.
community = await client.request_to_join_community(
    'community_id',
    answer='I am interested in this topic'
)
community_id
str
required
The ID of the community.
answer
str | None
default:"None"
Answer to the join request question.
return
Community
The requested community.

get_community_tweets

Retrieves tweets from a community.
tweets = await client.get_community_tweets(
    community_id='community_id',
    tweet_type='Latest',
    count=40
)

for tweet in tweets:
    print(tweet.text)
community_id
str
required
The ID of the community.
tweet_type
'Top' | 'Latest' | 'Media'
required
The type of tweets to retrieve.
count
int
default:"40"
The number of tweets to retrieve.
cursor
str | None
default:"None"
Cursor for pagination.
return
Result[Tweet]
Result object containing community tweets.

get_communities_timeline

Retrieves tweets from communities timeline.
tweets = await client.get_communities_timeline(count=20)

for tweet in tweets:
    print(f"{tweet.community.name}: {tweet.text}")
count
int
default:"20"
The number of tweets to retrieve.
cursor
str | None
default:"None"
Cursor for pagination.
return
Result[Tweet]
Result object containing tweets from communities.

get_community_members

Retrieves members of a community.
members = await client.get_community_members('community_id', count=20)

for member in members:
    print(member.name)
community_id
str
required
The ID of the community.
count
int
default:"20"
The number of members to retrieve.
cursor
str | None
default:"None"
Cursor for pagination.
return
Result[CommunityMember]
Result object containing community members.

get_community_moderators

Retrieves moderators of a community.
moderators = await client.get_community_moderators('community_id', count=20)
community_id
str
required
The ID of the community.
count
int
default:"20"
The number of moderators to retrieve.
cursor
str | None
default:"None"
Cursor for pagination.
return
Result[CommunityMember]
Result object containing community moderators.

search_community_tweet

Searches for tweets in a community.
tweets = await client.search_community_tweet(
    community_id='community_id',
    query='python',
    count=20
)
community_id
str
required
The ID of the community.
query
str
required
The search query.
count
int
default:"20"
The number of tweets to retrieve.
cursor
str | None
default:"None"
Cursor for pagination.
return
Result[Tweet]
Result object containing search results.

Notification Operations

get_notifications

Retrieves notifications.
notifications = await client.get_notifications('All', count=40)

for notification in notifications:
    print(notification.text)

more_notifications = await notifications.next()
type
'All' | 'Verified' | 'Mentions'
required
Type of notifications to retrieve:
  • 'All': All notifications
  • 'Verified': Notifications from verified users
  • 'Mentions': Mention notifications
count
int
default:"40"
Number of notifications to retrieve.
cursor
str | None
default:"None"
Cursor for pagination.
return
Result[Notification]
Result object containing notifications.

Trend Operations

Retrieves trending topics.
trends = await client.get_trends('trending', count=20)

for trend in trends:
    print(f"{trend.name}: {trend.tweet_count} tweets")
category
'trending' | 'for-you' | 'news' | 'sports' | 'entertainment'
required
The category of trends to retrieve.
count
int
default:"20"
The number of trends to retrieve.
retry
bool
default:"True"
If True, continuously retries if no trends are fetched.
additional_request_params
dict | None
default:"None"
Additional parameters for the API request.
return
list[Trend]
List of Trend objects.

get_available_locations

Retrieves locations where trends can be retrieved.
locations = await client.get_available_locations()

for location in locations:
    print(f"{location.name} (WOEID: {location.woeid})")
return
list[Location]
List of available locations.
Retrieves the top 50 trending topics for a specific location.
trends = await client.get_place_trends(woeid=1)

for trend in trends['trends']:
    print(trend.name)
woeid
int
required
Where On Earth ID. Can be obtained from get_available_locations().
return
PlaceTrends
Dictionary containing place trends information.

Geolocation Operations

reverse_geocode

Searches for places near a latitude and longitude.
places = await client.reverse_geocode(
    lat=37.7749,
    long=-122.4194,
    granularity='city'
)

for place in places:
    print(place.full_name)
lat
float
required
The latitude to search around.
long
float
required
The longitude to search around.
accuracy
str | float | None
default:"None"
A hint on the region size.
granularity
str | None
default:"None"
Minimal granularity: ‘neighborhood’, ‘city’, ‘admin’, or ‘country’.
max_results
int | None
default:"None"
Maximum number of results.
return
list[Place]
List of Place objects.

search_geo

Searches for places that can be attached to tweets.
places = await client.search_geo(
    query='San Francisco',
    granularity='city'
)
lat
float | None
default:"None"
The latitude to search around.
long
float | None
default:"None"
The longitude to search around.
query
str | None
default:"None"
Free-form text to match (e.g., location name).
ip
str | None
default:"None"
IP address for geolocation.
granularity
str | None
default:"None"
Minimal granularity: ‘neighborhood’, ‘city’, ‘admin’, or ‘country’.
max_results
int | None
default:"None"
Maximum number of results.
return
list[Place]
List of Place objects.

get_place

Retrieves a place by ID.
place = await client.get_place('place_id')
print(place.full_name)
id
str
required
The ID of the place.
return
Place
Place object.

Streaming API

get_streaming_session

Returns a session for interacting with the streaming API.
from twikit.streaming import Topic

topics = {
    Topic.tweet_engagement('1234567890'),
    Topic.dm_update(f'{user_id}-{await client.user_id()}'),
    Topic.dm_typing(f'{user_id}-{await client.user_id()}')
}

session = await client.get_streaming_session(topics)

async for topic, payload in session:
    if payload.dm_update:
        print(f'New DM from {payload.dm_update.user_id}')
    
    if payload.dm_typing:
        print(f'{payload.dm_typing.user_id} is typing...')
    
    if payload.tweet_engagement:
        print(f'Likes: {payload.tweet_engagement.like_count}')
        print(f'Retweets: {payload.tweet_engagement.retweet_count}')
topics
set[str]
required
Set of topics to stream. Use Topic class to generate topic strings.
auto_reconnect
bool
default:"True"
Whether to automatically reconnect when disconnected.
return
StreamingSession
A streaming session instance.
Topics can be added or removed using session.update_subscriptions(subscribe_topics, unsubscribe_topics).

Search Operations

search_user

Searches for users.
users = await client.search_user('elon', count=20)

for user in users:
    print(f"{user.name} (@{user.screen_name})")

more_users = await users.next()
query
str
required
The search query.
count
int
default:"20"
The number of users to retrieve.
cursor
str | None
default:"None"
Cursor for pagination.
return
Result[User]
Result object containing search results.

Delegation

set_delegate_account

Sets the account to act as (for delegated accounts).
# Act as another account
client.set_delegate_account('user_id')

# Clear delegation
client.set_delegate_account(None)
user_id
str | None
required
The user ID of the account to act as. Set to None to clear.
This allows authenticated users with delegation permissions to perform actions on behalf of other accounts.

Build docs developers (and LLMs) love