Skip to main content

twitterapi-io (Python)

Official Python SDK + CLI for twitterapi.io — Twitter/X data API. Search tweets, fetch user profiles, followers, replies, retweeters, trends. One API key, no OAuth, no Twitter Developer Account.

PyPI version Python 3.9+ MIT License

Install

pip install twitterapi-io

Get an API key

Sign up at twitterapi.io — free tier available.

Quick start (sync)

from twitterapi_io import TwitterApiClient

client = TwitterApiClient(api_key="your_api_key")  # or env TWITTERAPI_TOKEN

user = client.get_user_info(user_name="elonmusk")
print(user["data"]["name"], user["data"]["followers"])

tweets = client.search_tweets(query="from:elonmusk has:images", query_type="Latest")
for t in tweets["tweets"]:
    print(t["text"])

Async variant

import asyncio
from twitterapi_io import AsyncTwitterApiClient

async def main():
    async with AsyncTwitterApiClient(api_key="your_api_key") as client:
        user = await client.get_user_info(user_name="elonmusk")
        print(user)

asyncio.run(main())

CLI

export TWITTERAPI_TOKEN=your_api_key

twitterapi user-info elonmusk
twitterapi search "from:elonmusk has:images" Latest
twitterapi trends 1 10        # 1 = Worldwide

twitterapi help

Output is JSON to stdout — pipe to jq:

twitterapi user-info elonmusk | jq '.data.followers'

API reference

12 read endpoints (v0.1.0):

Method Endpoint
search_tweets(query, query_type, cursor) Advanced search
get_user_info(user_name) Basic profile
get_user_about(user_name) Extended profile
get_user_followers(user_name, cursor, page_size) Followers
get_user_followings(user_name, cursor, page_size) Followings
get_user_last_tweets(user_name OR user_id, cursor, include_replies) Recent tweets
get_user_mentions(user_name, since_time, until_time, cursor) Mentions
get_tweets_by_ids(tweet_ids) Batch fetch (≤100)
get_tweet_replies(tweet_id, cursor, query_type) Replies
get_tweet_quotes(tweet_id, since_time, until_time, cursor) Quote-tweets
get_tweet_retweeters(tweet_id, cursor) Retweeters
get_trends(woeid, count) Trending topics

Low-level escape hatch

For any endpoint not yet wrapped above:

result = client.get("/twitter/some/new/endpoint", {"foo": "bar"})

Full REST API: twitterapi.io/docs.

Error handling

from twitterapi_io import TwitterApiClient, TwitterApiError

try:
    client.get_user_info(user_name="nonexistent_user_xyz")
except TwitterApiError as e:
    print(f"API {e.status}: {e}")

Automatic retry on 429 / 5xx (3 attempts, exponential backoff).

Coming from tweepy

If your code uses tweepy's v2 Client for reading data, the compat module gives you a tweepy-style interface on top of twitterapi.io. In most scripts you change two lines:

# before
# import tweepy
# client = tweepy.Client(bearer_token=X_BEARER_TOKEN)

from twitterapi_io.compat import TweepyClient
client = TweepyClient(bearer_token="YOUR_TWITTERAPI_IO_KEY")  # your twitterapi.io API key

resp = client.get_users_tweets(id="44196397", exclude=["replies"], expansions=["author_id"])
for tweet in resp.data:
    print(tweet.id, tweet.created_at, tweet.text, tweet.public_metrics["like_count"])

next_token = resp.meta.get("next_token")   # absent on the last page

Results come back as Response(data, includes, errors, meta) with Tweet / User objects: the same shape as tweepy. Each object also keeps the full twitterapi.io record in .data.

Supported methods and how many API calls each makes

Every API call is billed at the normal twitterapi.io prices.

Method API calls
get_user(username=...) / get_user(id=...) 1
get_users(ids=[...]) (up to 100) 1
get_users(usernames=[...]) (up to 100) 1 per username
get_tweet(id) 1
get_tweets(ids) (up to 100) 1 per 50 ids
get_users_tweets(id, pagination_token=, exclude=) 1 per page
search_recent_tweets(query, start_time=, end_time=, next_token=, sort_order=) 1 per page
get_users_followers(id, max_results=, pagination_token=) / get_users_following(...) 1 per page, +1 the first time for each user id (the id is looked up once and cached in the client)
get_users_mentions(id, start_time=, end_time=, pagination_token=) 1 per page, +1 the first time for each user id
expansions=["author_id"] 0 extra (authors are already in the response)

Good to know

  • bearer_token is your twitterapi.io API key. X credentials (consumer_key, access_token, …) are not used, and passing them raises TypeError.
  • Read-only: write methods such as create_tweet, like and follow_user raise NotImplementedError.
  • tweet_fields, user_fields and expansions are accepted. All fields are always returned; expansions=["author_id"] fills includes["users"].
  • max_results is accepted. Timeline and search pages have a fixed size (about 20). For followers and following, it sets the page size (20 to 200).
  • search_recent_tweets is not limited to the last 7 days. start_time / end_time accept a datetime (naive means UTC) or an ISO-8601 string. sort_order="relevancy" returns top results; the default returns the latest.
  • public_metrics["impression_count"] is the view count. verified is the blue-check status.
  • wait_on_rate_limit=True retries on HTTP 429 (up to 3 times, at most 60 seconds in total). return_type=dict returns the raw JSON.
  • Exceptions use tweepy's names and hierarchy (TweepyException → HTTPException → Unauthorized, TooManyRequests, …, plus PaymentRequired for 402). They are this package's own classes, so import them from here: from twitterapi_io.compat import errors, then except errors.TooManyRequests:. except tweepy.TooManyRequests will not catch them.

MCP server (alternative for AI agents)

If building Claude.ai / Claude Code / Cursor integrations, use the hosted MCP:

URL: https://mcp.twitterapi.io/mcp

Or stdio: @twitterapi_io/mcp-server

License

MIT

Metadata

Release files for twitterapi-io 0.2.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 twitterapi-io 0.2.0
File Size Uploaded Provenance Actions
twitterapi_io-0.2.0.tar.gz 21.6 kB Without provenance Details for twitterapi_io-0.2.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for twitterapi-io 0.2.0
File Interpreter ABI Platform Actions
twitterapi_io-0.2.0-py3-none-any.whl Python 3 none any Details for twitterapi_io-0.2.0-py3-none-any.whl

Total release size: 40.5 kB

Release files / twitterapi_io-0.2.0.tar.gz

Download URL twitterapi_io-0.2.0.tar.gz
Size 21.6 kB
Tags Source
SHA-256 checksum
How to use checksums
3c232a6141d7f2a8b52aa0b81249de2047790b05bf73462e87e27894cfe3a037
BLAKE2b-256 checksum
How to use checksums
152ae471f2d37283a9db59dab8f0a62828a8ce55d68597567fd8439a87858435
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release files / twitterapi_io-0.2.0-py3-none-any.whl

Download URL twitterapi_io-0.2.0-py3-none-any.whl
Size 18.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
ebf7c0414c04235236f1468ac4ea3980ae2348f8eaa2645f5a048bef87076561
BLAKE2b-256 checksum
How to use checksums
87bcb45c44461f466bb0ac4f33f133aeb29dc69677060f7a67ad06723a6590b1
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Security for twitterapi-io 0.2.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files No provenance

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