CLI and library for X/Twitter GraphQL API (cookie auth, no API key required)
Project description
bird 🐦
A Python CLI and library for X/Twitter's GraphQL API using cookie-based authentication — no API key required.
Disclaimer: This uses X/Twitter's undocumented internal GraphQL API. X can change endpoints or rotate query IDs at any time. Expect occasional breakage.
Installation
pip install -e .
Requires Python 3.10+.
Quick start
1. Configure credentials
python -m bird.cli configure
You'll be prompted for two cookies from your active X/Twitter session:
- Open x.com and log in
- Open DevTools → Application → Cookies →
https://x.com - Copy the values of
auth_tokenandct0
Credentials are saved to ~/.config/bird/credentials.json and used automatically by all commands.
2. Run commands
python -m bird.cli whoami
python -m bird.cli search "from:username" -n 10
python -m bird.cli tweet "Hello from Python"
Commands
| Command | Description |
|---|---|
configure |
Save credentials interactively |
whoami |
Show the authenticated account |
check |
Show where credentials are loaded from |
tweet "<text>" |
Post a new tweet |
reply <id-or-url> "<text>" |
Reply to a tweet |
read <id-or-url> |
Fetch a tweet |
thread <id-or-url> |
Show the full conversation thread |
replies <id-or-url> |
List replies to a tweet |
search "<query>" |
Search for tweets |
mentions |
Find tweets mentioning you |
user-tweets @handle |
Get tweets from a user's timeline |
home |
Your "For You" timeline |
home --following |
Your "Following" timeline |
bookmarks |
List your bookmarks |
unbookmark <id-or-url> |
Remove a bookmark |
likes |
List your liked tweets |
following |
Users you follow |
followers |
Users that follow you |
lists |
Your owned lists |
list-timeline <id-or-url> |
Tweets from a list |
news |
News and trending topics from Explore |
about @handle |
"About this account" info |
query-ids |
Inspect or refresh GraphQL query ID cache |
Common options
--json Output raw JSON
-n / --count N Number of results (default varies per command)
--cursor STRING Resume pagination from a cursor
--max-pages N Limit number of pages fetched
--timeout MS Request timeout in milliseconds
Auth options (override saved credentials)
--auth-token TOKEN
--ct0 TOKEN
# Or via environment variables
AUTH_TOKEN=... CT0=... python -m bird.cli whoami
Examples
# Search and output JSON
python -m bird.cli search "python asyncio" -n 20 --json
# Get someone's recent tweets
python -m bird.cli user-tweets @gvanrossum -n 50
# Fetch a full thread
python -m bird.cli thread https://x.com/user/status/1234567890123456789
# List bookmarks from a specific folder
python -m bird.cli bookmarks --folder-id 1234567890123456789 -n 50
# Fetch AI-curated news
python -m bird.cli news --ai-only -n 10
# Paginate following list
python -m bird.cli following -n 200 --json
Library usage
from bird import TwitterClient
client = TwitterClient(auth_token="...", ct0="...")
# Search
tweets, next_cursor = client.search("from:gvanrossum", count=20)
for tweet in tweets:
print(f"@{tweet.author.username}: {tweet.text}")
# Post
tweet_id = client.tweet("Hello from Python!")
# Reply
client.reply("Thanks!", reply_to_tweet_id=tweet_id)
# Bookmarks
tweets, cursor = client.get_bookmarks(count=50)
# Engagement
client.like(tweet_id)
client.retweet(tweet_id)
client.bookmark(tweet_id)
# News
items = client.get_news(count=10, ai_only=True)
Context manager
with TwitterClient(auth_token="...", ct0="...") as client:
user = client.get_current_user()
print(user.username)
Project structure
src/bird/
client.py TwitterClient — all API methods
cli.py Click CLI entry point
_config.py Credential storage (~/.config/bird/credentials.json)
_constants.py API URLs, bearer token, fallback query IDs
_features.py GraphQL feature-flag payloads
_models.py Dataclasses: Tweet, User, TwitterList, NewsItem, …
_utils.py Response parsing utilities
_query_ids.py Runtime query ID cache (scraped from x.com bundles)
tests/
test_utils.py Unit tests (no network required)
Development
pip install -e ".[dev]"
pytest tests/
ruff check src/ tests/
Credential resolution order
--auth-token/--ct0CLI flagsAUTH_TOKEN/CT0environment variables~/.config/bird/credentials.json(written bybird configure)
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file birdapi-0.0.3.tar.gz.
File metadata
- Download URL: birdapi-0.0.3.tar.gz
- Upload date:
- Size: 42.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6a911b0307c4e478b1634b57760c0f30a672b12215cb9f762c699b7cb8c4579a
|
|
| MD5 |
336b0184b0b8d2703ca81e4b4d4865d4
|
|
| BLAKE2b-256 |
1d64ae11d0ed67ca65f7730d7295de1b15c25e695f11fa0c78faa934b4f21e89
|
Provenance
The following attestation bundles were made for birdapi-0.0.3.tar.gz:
Publisher:
workflow.yml on dvermaas/birdapi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
birdapi-0.0.3.tar.gz -
Subject digest:
6a911b0307c4e478b1634b57760c0f30a672b12215cb9f762c699b7cb8c4579a - Sigstore transparency entry: 1781707201
- Sigstore integration time:
-
Permalink:
dvermaas/birdapi@1fad944550758f2bb16a39e8aad0111ee6863e12 -
Branch / Tag:
refs/tags/v0.0.3 - Owner: https://github.com/dvermaas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@1fad944550758f2bb16a39e8aad0111ee6863e12 -
Trigger Event:
push
-
Statement type:
File details
Details for the file birdapi-0.0.3-py3-none-any.whl.
File metadata
- Download URL: birdapi-0.0.3-py3-none-any.whl
- Upload date:
- Size: 40.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6f6bf68b18424c9316e333825e9bc5cb98c0b40f43254a925616a1297331bbef
|
|
| MD5 |
5ecc1c02e9a114bd005d054633dba1a5
|
|
| BLAKE2b-256 |
ebd428a3ad488723302656bcd601f6974f0770910e405b5611ea9fd8c5b2c9fb
|
Provenance
The following attestation bundles were made for birdapi-0.0.3-py3-none-any.whl:
Publisher:
workflow.yml on dvermaas/birdapi
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
birdapi-0.0.3-py3-none-any.whl -
Subject digest:
6f6bf68b18424c9316e333825e9bc5cb98c0b40f43254a925616a1297331bbef - Sigstore transparency entry: 1781707375
- Sigstore integration time:
-
Permalink:
dvermaas/birdapi@1fad944550758f2bb16a39e8aad0111ee6863e12 -
Branch / Tag:
refs/tags/v0.0.3 - Owner: https://github.com/dvermaas
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
workflow.yml@1fad944550758f2bb16a39e8aad0111ee6863e12 -
Trigger Event:
push
-
Statement type: