--- id: twscrape version: "0.20.0" license: MIT license_treatment: permissive maintenance: active --- # twscrape — Twitter GraphQL and Search API implementation with SNScrape data models License: permissive · Maintenance: active · Downloads: 132.5K/mo ## 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 above — 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 pip install twscrape uv add twscrape poetry add twscrape ## Installing 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_current - Install friction: low - Maintenance: active - Downloads: 132.5K/month (top 15,000 on PyPI) - Known vulnerabilities: none known ## Tags twitter scraping library, x.com api client async, twitter search graphql, account pool rotation, snscrape compatible models, twitter data extraction, x api wrapper python, web-scraping, async-api, twitter-x [View on SkillFed](https://skillfed.io/packages/twscrape) · [View on PyPI](https://pypi.org/project/twscrape/)