Skip to main content

Python SDK for the ApiTwitter REST API — Twitter/X data access

Project description

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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

apitwitter-1.0.0.tar.gz (7.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

apitwitter-1.0.0-py3-none-any.whl (6.6 kB view details)

Uploaded Python 3

File details

Details for the file apitwitter-1.0.0.tar.gz.

File metadata

  • Download URL: apitwitter-1.0.0.tar.gz
  • Upload date:
  • Size: 7.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for apitwitter-1.0.0.tar.gz
Algorithm Hash digest
SHA256 8e326e7cdeadf44872e41eaf33fa90ac55e1b9726579f8b02934a2be5d925dc4
MD5 9b0e65d475572dfa9adb475872ad0e56
BLAKE2b-256 9158f1d1c6da0c88f735ee8afae0011172190fb07b80b8ec3c15da907e9c4119

See more details on using hashes here.

File details

Details for the file apitwitter-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: apitwitter-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.10

File hashes

Hashes for apitwitter-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3c48e220efab6237bc01fe3de0bb207503e3e2745e1dba74681d3f279e282ff5
MD5 5834a6fa59f50b3b32b5c64dfdfc630a
BLAKE2b-256 548ea00c9520f5a38c6f015658493c788f2fa916e90fe7ef841deb2eca54c5c1

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page