Skip to main content

ApiTwitter Python SDK

Official Python SDK for the ApiTwitter REST API — access Twitter/X data without the official developer portal.

Installation

pip install apitwitter

Quick Start

from apitwitter import ApiTwitter

client = ApiTwitter("your-api-key")

# Get user profile (uses server pool — no cookies needed)
user = client.get_user("elonmusk")
print(user["name"], user["followers"])

# Search tweets
results = client.search("python programming", count=10)
for tweet in results["tweets"]:
    print(tweet["text"])

# Get user tweets
tweets = client.get_user_tweets("elonmusk")
for tweet in tweets["tweets"]:
    print(tweet["text"])

Read Operations (Server Pool)

These endpoints use the server-side pool — no cookies or proxy needed:

client = ApiTwitter("your-api-key")

# Users
user = client.get_user("username")
user = client.get_user_by_id("12345")
users = client.get_users_batch(["id1", "id2", "id3"])
followers = client.get_followers("username", count=100)
following = client.get_following("username", count=100)

# Tweets
tweets = client.get_user_tweets("username")
tweets = client.get_tweets(["tweet_id_1", "tweet_id_2"])

# Search
results = client.search("query", product="Top", count=20)
# product options: "Top", "Latest", "People", "Photos", "Videos"

Write Operations (Own Credentials)

Write endpoints require your own Twitter cookies and proxy:

COOKIE = "ct0=...;auth_token=..."
PROXY = "http://user:pass@host:port"

# Post a tweet
client.create_tweet("Hello from ApiTwitter SDK!", COOKIE, PROXY)

# Like / unlike
client.like("tweet_id", COOKIE, PROXY)
client.unlike("tweet_id", COOKIE, PROXY)

# Retweet
client.retweet("tweet_id", COOKIE, PROXY)

# Follow / unfollow
client.follow("user_id", COOKIE, PROXY)
client.unfollow("user_id", COOKIE, PROXY)

# Send DM
client.send_dm("user_id", "Hello!", COOKIE, PROXY)

# Bookmarks
client.add_bookmark("tweet_id", COOKIE, PROXY)
bookmarks = client.get_bookmarks(COOKIE, PROXY)

# Timeline
timeline = client.get_timeline_for_you(COOKIE, PROXY, count=20)
latest = client.get_timeline_latest(COOKIE, PROXY, count=20)

Pagination

# First page
result = client.get_followers("username", count=100)
followers = result["followers"]

# Next page
if result.get("next_cursor"):
    result = client.get_followers("username", count=100, cursor=result["next_cursor"])
    followers.extend(result["followers"])

Error Handling

from apitwitter import ApiTwitter
from apitwitter.exceptions import (
    AuthenticationError,
    InsufficientCreditsError,
    RateLimitError,
    NotFoundError,
)

client = ApiTwitter("your-api-key")

try:
    user = client.get_user("username")
except AuthenticationError:
    print("Invalid API key")
except InsufficientCreditsError:
    print("Top up your balance")
except RateLimitError as e:
    print(f"Rate limited, retry after {e.retry_after}s")
except NotFoundError:
    print("User not found")

Lists, Communities, Topics

COOKIE = "ct0=...;auth_token=..."
PROXY = "http://user:pass@host:port"

# Lists
client.create_list("My List", COOKIE, PROXY, description="A list")
client.get_list_tweets("list_id", COOKIE, PROXY)
client.add_list_member("list_id", "user_id", COOKIE, PROXY)

# Communities
communities = client.explore_communities(COOKIE, PROXY)
client.join_community("community_id", COOKIE, PROXY)

# Topics
client.follow_topic("topic_id", COOKIE, PROXY)

Configuration

client = ApiTwitter(
    api_key="your-api-key",
    base_url="https://api.apitwitter.com",  # default
    timeout=30.0,                            # request timeout in seconds
)

Links

Metadata

Release files for apitwitter 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for apitwitter 1.0.0
File Size Uploaded
apitwitter-1.0.0.tar.gz 7.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for apitwitter 1.0.0
File Interpreter ABI Platform
apitwitter-1.0.0-py3-none-any.whl Python 3 none any Details

Total release size: 14.4 kB

Release files / apitwitter-1.0.0.tar.gz

Download URL apitwitter-1.0.0.tar.gz
Size 7.8 kB
Tags Source
SHA-256 checksum
How to use checksums
8e326e7cdeadf44872e41eaf33fa90ac55e1b9726579f8b02934a2be5d925dc4
BLAKE2b-256 checksum
How to use checksums
9158f1d1c6da0c88f735ee8afae0011172190fb07b80b8ec3c15da907e9c4119
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.10

Release files / apitwitter-1.0.0-py3-none-any.whl

Download URL apitwitter-1.0.0-py3-none-any.whl
Size 6.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3c48e220efab6237bc01fe3de0bb207503e3e2745e1dba74681d3f279e282ff5
BLAKE2b-256 checksum
How to use checksums
548ea00c9520f5a38c6f015658493c788f2fa916e90fe7ef841deb2eca54c5c1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.12.10

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page