Skip to main content
Twikit provides a GuestClient that allows you to access Twitter’s public data without logging in. This is useful for read-only operations and when you don’t have Twitter credentials.

Overview

The GuestClient is a special client that operates without authentication. It can access public tweets, user profiles, and other public information, but cannot perform actions that require authentication.

Key differences from Client

GuestClient can only perform read-only operations on public data. For full functionality including posting tweets, following users, and accessing private content, use the regular Client with authentication.

Getting started

Initialize GuestClient

from twikit.guest import GuestClient

client = GuestClient(language='en-US')

Activate the client

Before making any requests, you must activate the guest client to obtain a guest token:
await client.activate()
print('Guest client activated')
You must call activate() before using any other methods. Forgetting this step will result in authentication errors.

Complete example

import asyncio
from twikit.guest import GuestClient

async def main():
    client = GuestClient(language='en-US')
    
    # Activate the guest client
    await client.activate()
    
    # Now you can use the client
    tweet = await client.get_tweet_by_id('1234567890')
    print(f'Tweet: {tweet.text}')
    print(f'Author: @{tweet.user.screen_name}')

asyncio.run(main())

What you can do

GuestClient supports several read-only operations:

Get user information

# Get user by screen name
user = await client.get_user_by_screen_name('elonmusk')
print(f'Name: {user.name}')
print(f'Followers: {user.followers_count}')
print(f'Bio: {user.description}')

# Get user by ID
user = await client.get_user_by_id('44196397')
print(f'Screen name: @{user.screen_name}')

Get tweets

# Get a specific tweet
tweet = await client.get_tweet_by_id('1234567890')
print(f'Tweet text: {tweet.text}')
print(f'Likes: {tweet.favorite_count}')
print(f'Retweets: {tweet.retweet_count}')

# Access tweet media
if tweet.media:
    for media in tweet.media:
        print(f'Media type: {media.type}')
        print(f'URL: {media.media_url}')

Get user tweets

user = await client.get_user_by_screen_name('elonmusk')

# Get recent tweets
tweets = await client.get_user_tweets(
    user_id=user.id,
    tweet_type='Tweets',
    count=20
)

for tweet in tweets:
    print(f'@{tweet.user.screen_name}: {tweet.text}')
GuestClient only supports tweet_type='Tweets'. Other types like ‘Replies’, ‘Media’, and ‘Likes’ require authentication.

Get highlighted tweets

user = await client.get_user_by_screen_name('example_user')

# Get user's highlighted tweets
highlights = await client.get_user_highlights_tweets(
    user_id=user.id,
    count=20
)

for tweet in highlights:
    print(f'{tweet.text}')

# Pagination works too
more_highlights = await highlights.next()

What you cannot do

GuestClient has several limitations compared to the authenticated Client:

Cannot perform write operations

# ❌ These will NOT work with GuestClient:

# Cannot create tweets
await client.create_tweet('Hello')  # Error!

# Cannot follow users
await client.follow_user('123')  # Error!

# Cannot like or retweet
await client.favorite_tweet('123')  # Error!
await client.retweet('123')  # Error!

# Cannot send DMs
await client.send_dm('123', 'Hello')  # Error!

Cannot access private content

# ❌ Cannot access protected accounts
user = await client.get_user_by_screen_name('private_account')
tweets = await client.get_user_tweets(user.id)  # May fail or return empty

# ❌ Cannot access your own timeline
await client.get_timeline()  # Error!

# ❌ Cannot access bookmarks
await client.get_bookmarks()  # Error!

Limited search capabilities

# ❌ Search is not available in GuestClient
await client.search_tweet('python')  # Error!
await client.search_user('developer')  # Error!
# ❌ Trends require authentication
await client.get_trends('trending')  # Error!

Use cases

GuestClient is perfect for these scenarios:

1. Public data monitoring

Monitor public accounts without authentication:
import asyncio
from twikit.guest import GuestClient

async def monitor_account(screen_name):
    client = GuestClient()
    await client.activate()
    
    user = await client.get_user_by_screen_name(screen_name)
    tweets = await client.get_user_tweets(user.id, 'Tweets', count=10)
    
    print(f'Latest tweets from @{screen_name}:')
    for tweet in tweets:
        print(f'  {tweet.text}')

asyncio.run(monitor_account('nasa'))

2. Tweet embedding

Fetch public tweets to display on your website:
async def get_tweet_data(tweet_id):
    client = GuestClient()
    await client.activate()
    
    tweet = await client.get_tweet_by_id(tweet_id)
    
    return {
        'text': tweet.text,
        'author': tweet.user.screen_name,
        'author_name': tweet.user.name,
        'created_at': tweet.created_at,
        'likes': tweet.favorite_count,
        'retweets': tweet.retweet_count,
        'media': [media.media_url for media in tweet.media] if tweet.media else []
    }

tweet_data = await get_tweet_data('1234567890')

3. Analytics and research

Analyze public Twitter data without authentication:
import asyncio
from twikit.guest import GuestClient

async def analyze_user_activity(screen_name):
    client = GuestClient()
    await client.activate()
    
    user = await client.get_user_by_screen_name(screen_name)
    tweets = await client.get_user_tweets(user.id, 'Tweets', count=100)
    
    total_likes = sum(tweet.favorite_count for tweet in tweets)
    total_retweets = sum(tweet.retweet_count for tweet in tweets)
    avg_likes = total_likes / len(tweets)
    avg_retweets = total_retweets / len(tweets)
    
    print(f'Analysis for @{screen_name}:')
    print(f'  Average likes: {avg_likes:.1f}')
    print(f'  Average retweets: {avg_retweets:.1f}')
    print(f'  Total engagement: {total_likes + total_retweets}')

asyncio.run(analyze_user_activity('elonmusk'))

4. Media archiving

Download media from public accounts:
import os
from twikit.guest import GuestClient

async def archive_user_media(screen_name, count=50):
    client = GuestClient()
    await client.activate()
    
    user = await client.get_user_by_screen_name(screen_name)
    tweets = await client.get_user_tweets(user.id, 'Tweets', count=count)
    
    os.makedirs(f'archive_{screen_name}', exist_ok=True)
    
    media_count = 0
    for tweet in tweets:
        if tweet.media:
            for i, media in enumerate(tweet.media):
                if media.type == 'photo':
                    filename = f'archive_{screen_name}/{tweet.id}_{i}.jpg'
                    await media.download(filename)
                    media_count += 1
                    print(f'Downloaded: {filename}')
    
    print(f'Total media archived: {media_count}')

await archive_user_media('nasa', count=20)

GuestClient vs Client

Here’s a comparison to help you choose:
from twikit.guest import GuestClient

client = GuestClient()
await client.activate()

# ✅ Read public data
# ❌ Cannot post or interact
# ✅ No credentials needed
# ❌ Limited functionality

Configuration options

GuestClient supports the same configuration options as Client:
client = GuestClient(
    language='en-US',                    # Language for API requests
    proxy='http://proxy.example.com',    # Proxy server URL
)

Best practices

1

Always activate before use

Call activate() immediately after creating the GuestClient and before any other operations.
2

Cache guest tokens

Guest tokens are valid for a period of time. Consider caching them to reduce activation calls.
3

Handle rate limits

Even though GuestClient doesn’t require authentication, it’s still subject to Twitter’s rate limits.
4

Use for read-only tasks

GuestClient is perfect for monitoring, analytics, and data collection from public accounts.
5

Switch to Client when needed

If you need to perform actions or access private content, use the authenticated Client instead.

Example: Complete guest application

import asyncio
from twikit.guest import GuestClient

class TwitterMonitor:
    def __init__(self):
        self.client = GuestClient(language='en-US')
        self.initialized = False
    
    async def initialize(self):
        """Initialize and activate the guest client"""
        if not self.initialized:
            await self.client.activate()
            self.initialized = True
            print('Twitter monitor initialized')
    
    async def get_user_stats(self, screen_name):
        """Get statistics for a user"""
        await self.initialize()
        
        user = await self.client.get_user_by_screen_name(screen_name)
        
        return {
            'screen_name': user.screen_name,
            'name': user.name,
            'followers': user.followers_count,
            'following': user.following_count,
            'tweets': user.statuses_count,
            'verified': user.verified,
            'description': user.description
        }
    
    async def get_recent_tweets(self, screen_name, count=10):
        """Get recent tweets from a user"""
        await self.initialize()
        
        user = await self.client.get_user_by_screen_name(screen_name)
        tweets = await self.client.get_user_tweets(user.id, 'Tweets', count)
        
        return [
            {
                'id': tweet.id,
                'text': tweet.text,
                'created_at': tweet.created_at,
                'likes': tweet.favorite_count,
                'retweets': tweet.retweet_count
            }
            for tweet in tweets
        ]

# Usage
async def main():
    monitor = TwitterMonitor()
    
    # Get user stats
    stats = await monitor.get_user_stats('elonmusk')
    print(f"User: {stats['name']} (@{stats['screen_name']})")
    print(f"Followers: {stats['followers']:,}")
    
    # Get recent tweets
    tweets = await monitor.get_recent_tweets('elonmusk', count=5)
    print(f"\nRecent tweets:")
    for tweet in tweets:
        print(f"  {tweet['text'][:60]}...")
        print(f"  Likes: {tweet['likes']}, Retweets: {tweet['retweets']}")

asyncio.run(main())

When to use Client instead

You should use the authenticated Client instead of GuestClient when you need to:
  • Post tweets, replies, or quote tweets
  • Follow, unfollow, block, or mute users
  • Like, retweet, or bookmark tweets
  • Send or receive direct messages
  • Search for tweets or users
  • Access trends and personalized content
  • View protected accounts you follow
  • Access your timeline, notifications, or bookmarks
  • Perform any action that requires user authentication
For all these operations, use the regular Client with authentication as described in the Getting Started guide.

Build docs developers (and LLMs) love