skillfed

twscrape

Twitter GraphQL and Search API implementation with SNScrape data models

twscrape v0.20.0 132.5K downloads/30d#11,550 on PyPI2,679
Permissive license MIT Active released

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 twscrape

uv

uv add twscrape

poetry

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

Development Status :: 4 - BetaLicense :: OSI Approved :: MIT LicenseProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.11Programming Language :: Python :: 3.12Programming Language :: Python :: 3.13Programming Language :: Python :: 3.14

Tags

twitter scraping libraryx.com api client asynctwitter search graphqlaccount pool rotationsnscrape compatible modelstwitter data extractionx api wrapper python
web-scrapingasync-apitwitter-x

More WWW/HTTP packages