twscrape
Twitter GraphQL and Search API implementation with SNScrape data models
What it is and what it does
twscrape is an async Python library that wraps X/Twitter's GraphQL and Search APIs by rotating through a pool of your own authorized accounts. It stores session cookies in SQLite, automatically switches accounts when rate-limited, and returns either parsed Tweet/User/Trend objects (compatible with SNScrape's data model) or raw API responses. The library includes both a Python API for concurrent scraping and a CLI for one-off queries.
You add accounts via browser cookies (the most stable method), and twscrape handles session persistence, per-account proxies, and the mechanics of keeping your scraper running across rate limits. It supports search with product filters (Latest, Top, Media), tweet threads and replies, user timelines, followers, lists, communities, and trends. The async/await design lets you run multiple concurrent scrapers efficiently.
Use it for:
- Bulk collection of tweets matching a search query or from specific users for research or analysis.
- Monitoring trending topics or specific accounts over time with automatic account rotation to avoid rate limits.
- Building a dataset of user metadata, follower networks, or community membership for social network analysis.
- Extracting tweet threads and conversation context programmatically for NLP or sentiment analysis pipelines.
- Running scheduled scraping jobs via CLI that output JSON Lines for downstream processing or storage.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
twscrape is an async Python library and CLI for querying X/Twitter's Search and GraphQL endpoints using your own account pool, with automatic session management, rate-limit rotation, and SNScrape-compatible data models.
Yes, if you need to scrape X/Twitter data at scale and can manage authorized account credentials responsibly. The library is actively maintained, has low install friction, uses a permissive MIT license, and offers both programmatic and CLI interfaces. Main considerations: you must provide your own account cookies (no API key), and X's Terms of Service discourage multi-account use—deploy with awareness of platform policy and your own risk tolerance.
Install
twscrape on PyPI
pip
pip install twscrapeuv
uv add twscrapepoetry
poetry add twscrapeInstalling twscrape
Before you install
Low install friction: pure Python wheel with 7 runtime dependencies (aiosqlite, beautifulsoup4, fake-useragent, httpx, loguru, py-machineid, pyotp). Actively maintained—last commit 2026-08-07, released 0.20.0 seven days ago, 2679 GitHub stars.
License in practice
MIT license (permissive): you can use, modify, and distribute twscrape freely in commercial and private projects with minimal restrictions, provided you retain the license notice.
Quickstart
pip install twscrape
import asyncio
from twscrape import API
async def main():
api = API()
await api.pool.add_account_cookies("my_account", "auth_token=xxx; ct0=yyy")
user = await api.user_by_login("xdevelopers")
print(user.id, user.username, user.followersCount)
asyncio.run(main())
Requires Python 3.10 or later. Needs authorized X/Twitter account credentials (auth_token and ct0 cookies from x.com).
Verify before relying
- Whether the optional curl-cffi backend (TWS_HTTP_BACKEND=curl) is necessary for avoiding detection or if httpx alone is sufficient for most use cases.
- Rate-limit behavior and account rotation strategy when multiple accounts are exhausted simultaneously.
- Whether X/Twitter's Terms of Service enforcement against multi-account scraping poses practical risk to users of this library.
Package facts
| License | MIT (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 7 — aiosqlite, beautifulsoup4, fake-useragent, httpx, loguru, py-machineid, pyotp |
| Maintenance | actively maintained — 7 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 132,475/month — #11,550 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: twscrape-0.20.0-py3-none-any.whl
Keywords: api, scrape, scrapper, snscrape, twitter
Tags
More WWW/HTTP packages
urllib3 is an HTTP client library that provides…
permissive · top 100 on PyPI
requestsRequests is a Python HTTP library that…
permissive · top 100 on PyPI
h11h11 is a pure-Python HTTP/1.1 protocol…
permissive · top 100 on PyPI
httpxHTTPX is a fully featured HTTP client library…
permissive · top 100 on PyPI
httpcoreA minimal low-level HTTP client library that…
permissive · top 100 on PyPI
aiohttpaiohttp is an async HTTP client and server…
permissive · top 100 on PyPI
ScweetScrape tweets, profiles, followers, and user…
permissive · top 15,000 on PyPI
tweepyTweepy is a Python library that provides access…
permissive · top 5,000 on PyPI
twikitTwikit is a Twitter scraper library that lets…
permissive · top 15,000 on PyPI
twythonTwython is a Python wrapper for the Twitter API…
permissive · top 15,000 on PyPI
python-graphql-clientSends GraphQL queries, mutations, and…
permissive · top 15,000 on PyPI
snscrapeScrapes user profiles, posts, hashtags, and…
copyleft · top 15,000 on PyPI
xclienttransactionGenerates X-Client-Transaction-ID headers for…
permissive · top 15,000 on PyPI
python-twitterA Python wrapper that provides programmatic…
permissive · top 15,000 on PyPI
graphqlclientA lightweight GraphQL client that sends queries…
permissive · top 15,000 on PyPI
crowdin-api-clientA lightweight Python client library for the…
permissive · top 15,000 on PyPI