$ show d60/twikit
Twikit is an asynchronous Python library that provides a comprehensive, unofficial client for the Twitter (X) API. It allows users to perform a wide range of Twitter operationsβsuch as posting tweets, searching for tweets and users, managing bookmarks and lists, sending direct messages, uploading media, and streaming real-time eventsβwithout requiring an official API key. The library achieves this by reverse-engineering Twitter's internal GraphQL and REST v1.1 endpoints, handling authentication via login flows or guest tokens, and implementing sophisticated anti-bot evasion techniques like client-side transaction ID generation (X-Client-Transaction-Id) and UI metrics obfuscation. The architecture separates concerns into GraphQL (gql) and REST (v11) client modules, with data models for tweets, users, communities, and more. It includes optional CAPTCHA solving and cookie persistence for session reuse. The codebase is well-structured, actively maintained, and demonstrates deep reverse-engineering skill, particularly in the `x_client_transaction` module that mimics Twitter's client-side telemetry.
The LLM identified 1 files worth highlighting for reuse:
This module implements the generation of X-Client-Transaction-Id headers, a critical anti-bot mechanism used by Twitter. It fetches the Twitter homepage, extracts a verification key from meta tags, parses SVG loading animations to derive a dynamic key using cubic bezier curves and color interpolation, and combines it with request parameters to produce a unique transaction ID per request. The module is self-contained (only depends on httpx, beautifulsoup4, and standard libraries) and demonstrates a high degree of reverse-engineering skill. It can be extracted and reused in any project that needs to replicate Twitter's client-side telemetry for API access.