Skip to main content

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

Project description

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).

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: @kaitoinfra/twitterapi-io-mcp-server

License

MIT

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

twitterapi_io-0.1.0.tar.gz (8.9 kB view details)

Uploaded Source

Built Distribution

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

twitterapi_io-0.1.0-py3-none-any.whl (9.1 kB view details)

Uploaded Python 3

File details

Details for the file twitterapi_io-0.1.0.tar.gz.

File metadata

  • Download URL: twitterapi_io-0.1.0.tar.gz
  • Upload date:
  • Size: 8.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for twitterapi_io-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3b3a7149622eef15e113fdf2ebf1213f6d66e11bfdf79342957cf40bc0879a1b
MD5 0174bd56db6de33253fc5834b382713b
BLAKE2b-256 080f735a64be93aa462d567c0c9bcebc44202bae2e54cecf9cc459da93ea9051

See more details on using hashes here.

File details

Details for the file twitterapi_io-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: twitterapi_io-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for twitterapi_io-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 ea0b85aff257bb0b4373d3740aa488dbaa6a0af191291ac5604a34af647538b1
MD5 4103155935558dde8723d77b5d14e50a
BLAKE2b-256 af1fe09145ea2a815b1a694e5eaa791c5186bfd2de35478454865dde7f88a18a

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