Skip to main content
We provide official SDKs so you can skip raw HTTP calls and start building in seconds.

Installation

pip install apitwitter

Quick Start

from apitwitter import ApiTwitter

client = ApiTwitter("tda_your_api_key")

# Get user profile
user = client.get_user("elonmusk")
print(user["data"]["name"])        # Elon Musk
print(user["data"]["followers"])   # 236446942

Read Endpoints (GET — Server Pool)

These endpoints use our server-side account pool. You only need your API key — no cookies or proxy required.

Get User by Username

user = client.get_user("elonmusk")

Get User by ID

user = client.get_user_by_id("44196397")

Batch User Lookup

users = client.get_users_by_ids(["44196397", "1234567890"])

Get Followers

result = client.get_followers("elonmusk", count=20)

for follower in result["followers"]:
    print(f"@{follower['userName']}{follower['name']}")

# Pagination
next_page = client.get_followers("elonmusk", count=20, cursor=result["next_cursor"])

Get Following

result = client.get_following("elonmusk", count=20)

Get User Tweets

tweets = client.get_user_tweets("elonmusk")

for tweet in tweets["tweets"]:
    print(tweet["text"][:120])
    print(f"  Likes: {tweet.get('likes', 0)}  Retweets: {tweet.get('retweets', 0)}")

Search Tweets

results = client.search("python programming", count=10)

for tweet in results["tweets"]:
    print(f"@{tweet['author']['userName']}: {tweet['text'][:100]}")

Get Tweets by ID

tweets = client.get_tweets(["1234567890", "0987654321"])

User Replies

replies = client.get_user_replies("elonmusk")

User Media

media = client.get_user_media("elonmusk", cookie, proxy)

User Likes

likes = client.get_user_likes("elonmusk", cookie, proxy)

Mutual Followers

mutual = client.get_mutual_followers("elonmusk")

Write Endpoints (POST — Your Credentials)

Write operations require your own Twitter cookies and a proxy.
Python — Setup
COOKIE = "ct0=YOUR_CT0;auth_token=YOUR_AUTH_TOKEN"
PROXY = "http://user:pass@host:port"
JavaScript — Setup
const cookie = "ct0=YOUR_CT0;auth_token=YOUR_AUTH_TOKEN";
const proxy = "http://user:pass@host:port";

Create Tweet

result = client.create_tweet("Hello from Python SDK!", COOKIE, PROXY)
print(result)  # tweet ID

Like / Unlike

client.like("1234567890", COOKIE, PROXY)
client.unlike("1234567890", COOKIE, PROXY)

Follow / Unfollow

client.follow("44196397", COOKIE, PROXY)
client.unfollow("44196397", COOKIE, PROXY)

Retweet / Undo Retweet

client.retweet("1234567890", COOKIE, PROXY)
client.undo_retweet("1234567890", COOKIE, PROXY)

Send Direct Message

client.send_dm("44196397", "Hey! Sent via SDK", COOKIE, PROXY)

Bookmarks

# List bookmarks
bookmarks = client.get_bookmarks(COOKIE, PROXY)

# Add bookmark
client.add_bookmark("1234567890", COOKIE, PROXY)

# Remove bookmark
client.remove_bookmark("1234567890", COOKIE, PROXY)

Timelines

# "For You" timeline
for_you = client.get_for_you_timeline(COOKIE, PROXY)

# "Latest" timeline
latest = client.get_latest_timeline(COOKIE, PROXY)

Lists

# Get owned lists
my_lists = client.get_owned_lists(COOKIE, PROXY)

# Create a list
client.create_list("My List", "Description", COOKIE, PROXY)

# Get list tweets
tweets = client.get_list_tweets("list_id", COOKIE, PROXY)

# Add/remove members
client.add_list_member("list_id", "user_id", COOKIE, PROXY)
client.remove_list_member("list_id", "user_id", COOKIE, PROXY)

Communities

# Explore communities
communities = client.explore_communities(COOKIE, PROXY)

# Get community tweets
tweets = client.get_community_tweets("community_id", COOKIE, PROXY)

# Join / Leave
client.join_community("community_id", COOKIE, PROXY)
client.leave_community("community_id", COOKIE, PROXY)

Topics

topic = client.get_topic("topic_id", COOKIE, PROXY)
client.follow_topic("topic_id", COOKIE, PROXY)
client.unfollow_topic("topic_id", COOKIE, PROXY)

Error Handling

Both SDKs throw typed exceptions for common API errors.
from apitwitter.exceptions import (
    ApiTwitterError,
    AuthenticationError,
    InsufficientCreditsError,
    RateLimitError,
    NotFoundError,
    ValidationError,
)

try:
    user = client.get_user("someone")
except AuthenticationError:
    print("Invalid API key")
except InsufficientCreditsError:
    print("Top up your balance")
except RateLimitError as e:
    print(f"Rate limited — retry in {e.retry_after}s")
except NotFoundError:
    print("User not found")
except ApiTwitterError as e:
    print(f"API error {e.status_code}: {e.message}")
ExceptionHTTP CodeWhen
AuthenticationError401Invalid or missing API key
InsufficientCreditsError402Not enough credits
RateLimitError429Too many requests (has retry_after / retryAfter)
NotFoundError404Resource not found
ValidationError400Invalid request parameters

Pagination Pattern

Most list endpoints support cursor-based pagination.
all_followers = []
cursor = None

while True:
    result = client.get_followers("username", count=200, cursor=cursor)
    all_followers.extend(result["followers"])

    cursor = result.get("next_cursor")
    if not cursor:
        break

print(f"Collected {len(all_followers)} followers")

Python SDK

PyPI: pip install apitwitter

JavaScript SDK

npm: npm install @apitwitter/sdk

PyPI

pypi.org/project/apitwitter

npm

npmjs.com/package/@apitwitter/sdk
Both SDKs are open-source and accept contributions. Found a bug or missing a feature? Open an issue on GitHub.