Skip to main content
This guide covers all operations related to Twitter users, including getting user information, following/unfollowing, blocking, muting, and managing followers.

Getting user information

There are multiple ways to retrieve user information in Twikit.

By screen name

user = await client.get_user_by_screen_name('elonmusk')
print(f'Name: {user.name}')
print(f'ID: {user.id}')
print(f'Followers: {user.followers_count}')

By user ID

user = await client.get_user_by_id('44196397')
print(f'Screen name: {user.screen_name}')

Get authenticated user info

# Get your own user information
me = await client.user()
print(f'Logged in as: {me.screen_name}')
print(f'Your user ID: {me.id}')

# Or just get your user ID
my_id = await client.user_id()

User attributes

The User object provides comprehensive information:
user = await client.get_user_by_screen_name('example_user')

# Basic information
print(user.id)                      # User ID
print(user.screen_name)             # @username
print(user.name)                    # Display name
print(user.description)             # Bio
print(user.location)                # Location string
print(user.url)                     # Profile URL
print(user.created_at)              # Account creation date

# Profile images
print(user.profile_image_url)       # Profile picture URL
print(user.profile_banner_url)      # Banner image URL

# Counts and metrics
print(user.followers_count)         # Number of followers
print(user.following_count)         # Number of following
print(user.statuses_count)          # Number of tweets
print(user.favourites_count)        # Number of likes
print(user.listed_count)            # Times listed
print(user.media_count)             # Media uploads count

# Verification status
print(user.verified)                # Legacy verified (blue check)
print(user.is_blue_verified)        # Twitter Blue subscriber

# Interaction permissions
print(user.can_dm)                  # Can you DM them
print(user.can_media_tag)           # Can you tag them in media

# Other attributes
print(user.protected)               # Is account private
print(user.possibly_sensitive)      # Potentially sensitive content
print(user.description_urls)        # URLs in bio

Following and unfollowing

Follow a user

user = await client.follow_user('44196397')
print(f'Followed {user.screen_name}')

Unfollow a user

user = await client.unfollow_user('44196397')
print(f'Unfollowed {user.screen_name}')

Getting followers and following

Get followers

user = await client.get_user_by_screen_name('example_user')

# Get followers
followers = await user.get_followers(count=20)
for follower in followers:
    print(f'@{follower.screen_name} - {follower.name}')

# Get more followers
more_followers = await followers.next()

Get following

user = await client.get_user_by_screen_name('example_user')

# Get users they're following
following = await user.get_following(count=20)
for friend in following:
    print(f'@{friend.screen_name}')

# Pagination
more_following = await following.next()

Get verified followers

user = await client.get_user_by_screen_name('example_user')
verified_followers = await user.get_verified_followers(count=20)

for follower in verified_followers:
    print(f'@{follower.screen_name} (verified: {follower.verified})')

Get followers you know

Find mutual followers:
user = await client.get_user_by_screen_name('example_user')
common_followers = await user.get_followers_you_know(count=20)

print('Followers you both know:')
for follower in common_followers:
    print(f'@{follower.screen_name}')

Using client methods directly

You can also use the client methods directly with user IDs:
user_id = '44196397'

# Get followers
followers = await client.get_user_followers(user_id, count=20)

# Get following
following = await client.get_user_following(user_id, count=20)

# Get verified followers
verified = await client.get_user_verified_followers(user_id, count=20)

# Get common followers
common = await client.get_user_followers_you_know(user_id, count=20)

Getting follower/following IDs

For faster retrieval of large follower lists, you can get just the IDs:
# Get follower IDs (up to 5000 per request)
follower_ids = await client.get_followers_ids(
    user_id='44196397',
    count=5000
)
print(f'First 5 follower IDs: {follower_ids[:5]}')

# Get following IDs
following_ids = await client.get_friends_ids(
    screen_name='elonmusk',
    count=5000
)

# Pagination for large lists
more_ids = await follower_ids.next()
Using ID methods is much faster than getting full user objects. Use this when you only need IDs or plan to fetch user details later.

Blocking users

Block a user

user = await client.block_user('123456789')
print(f'Blocked {user.screen_name}')

Unblock a user

user = await client.unblock_user('123456789')
print(f'Unblocked {user.screen_name}')

Muting users

Mute a user

Muting hides tweets from a user without unfollowing them:
user = await client.mute_user('123456789')
print(f'Muted {user.screen_name}')

Unmute a user

user = await client.unmute_user('123456789')
print(f'Unmuted {user.screen_name}')

User subscriptions

Get users that someone is subscribed to (Twitter Premium feature):
user = await client.get_user_by_screen_name('example_user')
subscriptions = await user.get_subscriptions(count=20)

for subscribed_user in subscriptions:
    print(f'Subscribed to: @{subscribed_user.screen_name}')

Practical examples

Find and follow users interested in a topic

# Search for users
results = await client.search_user('python developer', count=20)

for user in results:
    print(f'@{user.screen_name}: {user.description}')
    
    # Follow users with many followers
    if user.followers_count > 1000:
        await user.follow()
        print(f'Followed @{user.screen_name}')

# Get more results
more_users = await results.next()

Check if someone follows you back

my_id = await client.user_id()
target_user = await client.get_user_by_screen_name('example_user')

# Get their following list and check if your ID is in it
following = await target_user.get_following(count=100)
following_ids = [user.id for user in following]

if my_id in following_ids:
    print('They follow you back!')
else:
    print('They do not follow you')

Export your followers to a list

me = await client.user()
all_followers = []

followers = await me.get_followers(count=100)
while followers:
    all_followers.extend(followers)
    print(f'Fetched {len(all_followers)} followers...')
    
    # Try to get more
    try:
        followers = await followers.next()
    except:
        break

# Save to file
import json
with open('followers.json', 'w') as f:
    json.dump([
        {'screen_name': u.screen_name, 'name': u.name, 'id': u.id}
        for u in all_followers
    ], f, indent=2)

print(f'Exported {len(all_followers)} followers')

Bulk follow/unfollow operations

import asyncio

# Get a list of user IDs to follow
user_ids = ['123456', '789012', '345678']

for user_id in user_ids:
    try:
        user = await client.follow_user(user_id)
        print(f'Followed @{user.screen_name}')
        
        # Add delay to avoid rate limits
        await asyncio.sleep(2)
    except Exception as e:
        print(f'Error following {user_id}: {e}')
Be careful with bulk operations. Twitter has rate limits and may suspend accounts for aggressive following/unfollowing behavior.

Update user information

Refresh user data to get the latest information:
user = await client.get_user_by_screen_name('example_user')
print(f'Followers: {user.followers_count}')

# Wait some time...
await asyncio.sleep(3600)

# Update to get fresh data
await user.update()
print(f'Updated followers: {user.followers_count}')

Build docs developers (and LLMs) love