A Twitter / X API scraper for Python — no API key required.
A maintained fork of d60/twikit, fixed for the 2026 breakages that make the upstream release unusable.
Drop-in replacement — the package still imports as
twikit, so existing code (from twikit import Client) keeps working unchanged.
pip install twiforkWith optional browser-TLS impersonation (gets past some 403 walls):
pip install "twifork[impersonate]"Or grab the latest straight from git:
pip install git+https://github.com/PawiX25/twifork.gitThe upstream PyPI release (twikit==2.3.3) is broken in several ways as of 2026. twifork fixes them — each item links to the upstream issue it resolves:
- ClientTransaction /
Couldn't get KEY_BYTE indices— updatedondemand.s.jsparsing for the new X webpack bundle, so GraphQL requests work again. (#408, #409, #304) - Intermittent / sticky
404onSearchTimelineandfriends/list— thex-client-transaction-idanimation key was missing X'sframe_timerounding step, so on someClientsessions every strict request 404'd until the client was recreated. Restored, so the semi-random 404s are gone. (#357, #397) KeyErroron missing optional fields inUser.__init__andClient.request— defensive.get()parsing. (#417)- Empty user
name/screen_name(e.g. in search results) — X movedname,screen_name,created_at, avatar, location, and more out oflegacyinto new sub-objects; these are now read with a legacy fallback. get_tweet_by_idKeyError: 'itemContent'— handles both the legacy and the new trailing-cursor shapes. (#332, #363)KeyError: 'entries'/IndexErroronget_user_tweetsfor accounts with no visible tweets — empty / cursor-less timelines return an empty result instead of crashing. (#361, #216)get_trendsdeprecated / returns nothing — rebuilt on top ofGenericTimelineById; also addsget_explore_page(). (#389)RecursionErroron rate-limit — the 429 recovery path no longer recurses.GuestClient.activate()404 — the guest client now sends aUser-Agentheader and parses user fields defensively. (#402, #385)get_latest_friends404 — routed through the GraphQLFollowingendpoint after the v1.1 endpoint was retired. (#397)'Client' object has no attribute '_ui_metrix'— fixed the captcha unlock path. (#333)get_bookmark_folders().next()infinite loop — fixed malformed pagination variables. (#334, #335)get_latest_timeline/get_list_tweetsdropping conversation entries — home- and list-conversation entries are now unpacked. (#336, #337, #340)Media.source_urlfor the full-resolution image (#376), andTweet.quoted_status_idfor the quoted tweet id (#222).
Issues that stem from X-side restrictions (account suspension, Cloudflare/IP blocks, captcha, automation limits) aren't fixable in the library and are out of scope.
Some X endpoints reject the default httpx TLS fingerprint with a 403 (HTML) response even when the request is valid. Installing the optional curl_cffi backend and passing impersonate= routes requests through a real browser TLS fingerprint, which avoids those 403s:
client = Client('en-US', impersonate='chrome124')Define a client and log in.
import asyncio
from twikit import Client
client = Client('en-US')
async def main():
await client.login(
auth_info_1='example_user',
auth_info_2='email@example.com',
password='password0000',
cookies_file='cookies.json'
)
asyncio.run(main())Post a tweet with media attached.
media_ids = [
await client.upload_media('media1.jpg'),
await client.upload_media('media2.jpg'),
]
await client.create_tweet(text='Example Tweet', media_ids=media_ids)Search the latest tweets for a keyword.
tweets = await client.search_tweet('python', 'Latest')
for tweet in tweets:
print(tweet.user.name, tweet.text, tweet.created_at)A few more common calls.
await client.get_user_tweets('123456', 'Tweets') # a user's tweets
await client.send_dm('123456789', 'Hello') # send a DM
await client.get_trends('trending') # trending topicsMore examples (upstream, still apply): https://github.com/d60/twikit/tree/main/examples
- No API key — works by scraping the web client.
- Free & open source (MIT).
- Drop-in
twikitreplacement — same import, your code doesn't change. - Tweets, search, timelines, trends, users, DMs, media, bookmarks, and more.
Full API reference (upstream — the package surface is the same): https://twikit.readthedocs.io/en/latest/twikit.html
Found a bug or have a fix? Open an issue or PR on twifork issues.
If twifork saved you a headache, consider leaving a ⭐.
twifork is a fork of d60/twikit by @d60 — all upstream credit goes to the original authors. Licensed under the MIT License.
twifork is an independent, unofficial project. It is not affiliated with, endorsed by, or sponsored by X Corp. "X" and "Twitter" are trademarks of X Corp. Use it in accordance with applicable terms and laws.