Twitter/X API wrapper with no API key required.
Project description
twitscrape
A Python library for interacting with Twitter/X — no API key required.
Uses cookie-based authentication and browser-level HTTP fingerprinting (curl_cffi) to bypass connection issues that affect standard httpx clients.
Features
- No API key required
- Cookie-based auth — paste cookies from your browser, no login flow needed
- Supports 4 cookie input formats
- Async API built on
twikitinternals
Install
pip install twitscraper
Getting your cookies
- Open x.com and log in
- Open DevTools → Application → Cookies →
https://x.com - Copy
auth_tokenandct0(minimum required)
Or use a browser extension like EditThisCookie or Cookie-Editor to export all cookies at once.
Quick start
From a dict
import asyncio
from twitscrape import create_client
async def main():
client = await create_client({
"auth_token": "your_auth_token",
"ct0": "your_ct0",
"twid": "u%3D123456789",
})
me = await client.user()
print(me.screen_name)
asyncio.run(main())
From a JSON file
from twitscrape import create_client_from_file
client = await create_client_from_file("cookies.json")
cookies.json:
{
"auth_token": "...",
"ct0": "...",
"twid": "u%3D123456789"
}
From a raw cookie string (Network tab)
from twitscrape import create_client_from_string
raw = "auth_token=abc123; ct0=xyz789; twid=u%3D123456789"
client = await create_client_from_string(raw)
From a browser extension export
from twitscrape import create_client_from_browser_export
# Paste the JSON array copied from EditThisCookie / Cookie-Editor
raw_json = '[{"name": "auth_token", "value": "...", "domain": ".x.com"}, ...]'
client = await create_client_from_browser_export(raw_json)
Examples
Search tweets
tweets = await client.search_tweet("python", "Latest")
for tweet in tweets:
print(tweet.user.screen_name, tweet.text)
Create a tweet
tweet = await client.create_tweet("Hello from twitscrape!")
Upload media
media_id = await client.upload_media("image.jpg")
await client.create_tweet("Tweet with image", media_ids=[media_id])
Send a DM
await client.send_dm("123456789", "Hello!")
Get trends
trends = await client.get_trends("trending")
for t in trends:
print(t.name)
Download tweet media
tweet = await client.get_tweet_by_id("tweet_id")
for i, media in enumerate(tweet.media):
if media.type == "photo":
await media.download(f"photo_{i}.jpg")
elif media.type == "video":
await media.streams[-1].download(f"video_{i}.mp4")
Listen for new tweets
import asyncio
from twitscrape import Tweet
async def on_new_tweet(tweet: Tweet):
print(f"New tweet: {tweet.text}")
USER_ID = "44196397"
before = (await client.get_user_tweets(USER_ID, "Tweets", count=1))[0]
while True:
await asyncio.sleep(60)
latest = (await client.get_user_tweets(USER_ID, "Tweets", count=1))[0]
if latest.id != before.id:
await on_new_tweet(latest)
before = latest
Rate limits
See ratelimits.md for per-endpoint limits (reset every 15 minutes).
License
MIT
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file twitscraper-1.0.2.tar.gz.
File metadata
- Download URL: twitscraper-1.0.2.tar.gz
- Upload date:
- Size: 47.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4de1ee2040153b1fd61dd57141c0292b4db733e18b4c3c3fbd9ef4dae163a7cc
|
|
| MD5 |
93f9f60f21bc9023abb07095651c55d4
|
|
| BLAKE2b-256 |
2ab53b7bd96b7c6cf90fe6e3b4b2a1bdacf5d50d0e564614af62776f2a6eb673
|
File details
Details for the file twitscraper-1.0.2-py3-none-any.whl.
File metadata
- Download URL: twitscraper-1.0.2-py3-none-any.whl
- Upload date:
- Size: 54.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
1718559571dcd3dbdb59ebd91b0722648c05547ea04b43acb870edc01e581401
|
|
| MD5 |
f989712a7686cab69e4a12f15c3c1176
|
|
| BLAKE2b-256 |
10326bfe80be2bd8632814bea167e9df48f22394f1584e127cbe82388c41faeb
|