Registry / search / twscrape

twscrape

JSON →
library0.18.1pypypi✓ verified 85d ago

twscrape is an asynchronous Python library for scraping Twitter data using the GraphQL and Search API, with SNScrape-like data models. Current version is 0.18.1, requiring Python >=3.10. It is actively maintained with regular releases.

pip install twscrape
INSTALL
IMPORT
SIG · TWSCRAPE
T
twscrape
searchpythonv0.18.1
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

API
from twscrape import API
Main API class for interacting with Twitter.
Gather
from twscrape import Gather
Legacy import still works but prefer API.

Initialize the API and fetch user data by login. Note that login is required for most endpoints.

import asyncio from twscrape import API from twscrape.models import User, Tweet async def main(): api = API() # Add accounts (if needed) # await api.pool.add_account("username", "password", "email", "email_password") # await api.pool.login_all() user = await api.user_by_login("BarackObama") print(user) asyncio.run(main())
Debug
Known issues
breakingAs of version 0.18.0, the library replaced `Gather` with `API` as the main entry point. Old code using `from twscrape import Gather` will break. Use `from twscrape import API` and instantiate `API()` instead.
fix
Replace `Gather` with `API` and use the new async methods.
affects: >=0.18.0
breakingThe `add_account` method signature changed. It now expects `(username, password, email, email_password)` instead of `(username, password, email)`. Failing to provide the email password may cause login failures.
fix
Update all calls to `add_account` to include a fourth argument for the email password.
affects: >=0.14.0
gotchaAPI methods are asynchronous and must be awaited. Common error: calling `api.user_by_login(...)` without `await` silently returns a coroutine object, not the result.
fix
Always use `await` when calling API methods (e.g., `user = await api.user_by_login("...")`).
affects: all
Errors
Common errors & fixes
TypeError: object NoneType can't be used in 'await' expression
Forgetting `await` on an async method returns a coroutine, but when used incorrectly it may evaluate to None.
fix
Ensure all API calls are prefixed with `await`.
twscrape.exceptions.UnauthorizedException: 401 Unauthorized
No authenticated account added or login failed. The library requires at least one valid Twitter account to make requests.
fix
Use `api.pool.add_account(username, password, email, email_password)` and then `api.pool.login_all()` before making requests.
ImportError: cannot import name 'Gather' from 'twscrape'
Since version 0.18.0, `Gather` is removed. Old code still imports it.
fix
Change import to `from twscrape import API` and adapt code accordingly.
Upgrade
Version history
0.18.1latest on PyPI · released May 23, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
51 hits · last 30 days
node
46
OpenAI (training)
1
Resources

No resource links recorded.