gunkonchi / xscrape
git clone https://github.com/gunkonchi/xscrape.git
Async Python client for collecting public data from X (Twitter) - search, profiles, threads, replies, and media. Built-in account rotation, adaptive rate limiting, and export to JSON/CSV/SQLite.
β
stars, 24h
β
stars, 7 days
+643
stars, 30 days Β· #455
643
β
total
151
forks Β· 0 open issues
Star history starts 2026-10-20; the chart appears after the second daily snapshot.
LanguagePython
LicenseMIT
Created2026-09-26 (24d ago)
Last pushtoday
Watchers18
OwnerUser
GitHub topics
Links
- GitHub: github.com/gunkonchi/xscrape
- Releases Β· Issues Β· Hacker News mentions
README excerpt
# xscrape > Asynchronous Python client for collecting public data from X (Twitter). **xscrape** is a lightweight library for asynchronously collecting public data from X (Twitter): posts, profiles, threads, replies, and media. It supports account rotation, a built-in rate limiter, and export to JSON / CSV / SQLite. --- ## Table of Contents - Features - Installation - Quick Start - How It Works - Configuration - CLI - Examples - Docker - Testing - Project Layout - Roadmap - Contributing - Disclaimer - License --- ## Features - π **Post search** β by keywords, hashtags, and operators (`from:`, `since:`, `until:`) - π€ **User profiles** β metadata, followers, activity counters - π§΅ **Threads and replies** β reconstruction of conversation chains - πΌ **Media** β extraction of image and video links - π **Account rotation** β session pool with automatic failover - β± **Rate limiting** β adaptive control of request frequency - πΎ **Storage backends** β JSON, CSV, SQLite out of the box - π§© **Plugins** β custom handlers and exporters - π₯ **CLI** β ready-to-use command line interface - π³ **Docker-ready** β single command deployment - π **Structured logging** β JSON logs with request tracing --- ## π¦ Installation ### From source [code] ### Requirements - Python 3.10+ - `aiohttp`, `pydantic`, `tenacity`, `orjson` ### Optional [code] --- ## Quick Start [code] Run `xscrape --help` for the full command reference. ## How It Works `xscrape` talks to public GraphQL endpoints of X using session cookies. The pipeline looks like this: [code] 1. **Client** β public interface (`search`, `user`, `thread`, `replies`). 2. **AuthPool** β session pool; picks a free account, handles 429/401. 3. **Fetcher** β low-level HTTP requests with retries and exponential backoff. 4. **Parser** β normalizes raw responses into typed models (`Tweet`, `User`). 5. **RateLimiter** β per-account token bucket plus a global cap. 6. **Storage** β serialization of results into the chosen format. See docs/ARCHITECTURE.md for details. --- ## Configuration All options are read from environment variables (see `.env.example`): | Variable | Description | Default | |---|---|---| | `XSCRAPE_COOKIES` | Cookie string (`auth_token`, `ct0`) | β | | `XSCRAPE_POOL` | Path to JSON with account pool | `None` | | `XSCRAPE_CONCURRENCY` | Max parallel requests | `4` | | `XSCRAPE_TIMEOUT` | Request timeout (seconds) | `20` | | `XSCRAPE_RETRIES` | Number of retries on error | `3` | | `XSCRAPE_USER_AGENT` | Custom User-Agent | built-in | | `XSCRAPE_PROXY` | Proxy (`http://user:pass@host:port`) | `None` | | `XSCRAPE_LOG_LEVEL` | Logging level | `INFO` | | `XSCRAPE_LOG_FORMAT` | `text` or `json` | `text` | Full reference: docs/CONFIGURATION.md. --- ## Examples The `examples/` directory contains ready-to-run scripts: - `search_tweets.py` β search with pagination and filters - `user_timeline.py` β collect a user's timeline - `export_to_csv.py` β dump results to CSV - `export_to_sqlite.py` β persist results into SQLite