Tweepy is a popular, easy-to-use Python library for accessing the X API (formerly Twitter API). It provides a Pythonic way to interact with both v1.1 and v2 of the API, handling authentication, requests, and response parsing. The current version is 4.16.0, and it generally releases new versions frequently, often tied to changes or additions in the X API.
pip install tweepyVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to use `tweepy.Client` for accessing the Twitter API v2. It fetches the user ID for a specified username and then retrieves their latest tweets. For public data access, a Bearer Token (Developer Portal > Projects & Apps > your_app > Keys and tokens) is typically sufficient. For user-specific actions (like posting tweets), more complex OAuth 2.0 PKCE or OAuth 1.0a authentication is required.
Upgrade your Python environment to version 3.9 or newer. Alternatively, pin Tweepy to a version prior to 4.15.0 if Python upgrade is not feasible (e.g., `pip install 'tweepy<4.15.0'`).
Migrate to Twitter API v2 streaming endpoints using `tweepy.StreamingClient`. The API v2 offers a more robust and flexible streaming experience.
For new development, prioritize `tweepy.Client` and the Twitter API v2. Use `tweepy.API` only when specifically interacting with legacy v1.1 features not yet available in v2 or when specific OAuth 1.0a features are required. Always ensure your authentication method matches the client being used.
Consult the official Tweepy documentation (e.g., the 'Authentication' section) for detailed OAuth 2.0 PKCE or OAuth 1.0a setup instructions when user-context actions are needed. A Bearer Token alone is insufficient for these operations.
Implement robust error handling around API calls, specifically catching `tweepy.TweepyException`. Integrate a retry logic with exponential backoff, potentially using a library like `tenacity`, to gracefully handle rate limit exhaustion.
No dependency data recorded yet.