Esta página se muestra en inglés. Una traducción al español está en curso.
ScriptsJul 15, 2026·3 min de lectura

Tweepy — Python Client for the Twitter/X API

An easy-to-use Python library for accessing the Twitter (X) API, supporting both v1.1 and v2 endpoints for tweets, users, streams, and media uploads.

Listo para agents

Staging seguro para este activo

Este activo primero queda en staging. El prompt copiado pide inspeccionar los archivos staged antes de activar scripts, config MCP o config global.

Stage only · 17/100Política: staging
Superficie agent
Cualquier agent MCP/CLI
Tipo
CLI Tool
Instalación
Stage only
Confianza
Confianza: Established
Entrada
Tweepy Overview
Comando de staging seguro
npx -y tokrepo@latest install 1bd02f3b-808e-11f1-9bc6-00163e2b0d79 --target codex

Primero deja archivos en staging; la activación requiere revisar el README y el plan staged.

Introduction

Tweepy is a Python library that simplifies interaction with the Twitter (now X) API. It wraps both the v1.1 REST API and the newer v2 API, handling OAuth authentication, pagination, rate limiting, and streaming so developers can focus on building applications rather than managing HTTP requests.

What Tweepy Does

  • Provides a high-level Client class for Twitter API v2 endpoints (tweets, users, spaces, lists)
  • Supports the legacy API v1.1 via the API class for media uploads and direct messages
  • Handles OAuth 1.0a and OAuth 2.0 (Bearer Token, PKCE) authentication flows
  • Offers real-time filtered and sampled stream classes for processing tweets as they arrive
  • Manages automatic pagination through cursors and paginators

Architecture Overview

Tweepy is organized around two main client classes: Client for API v2 and API for v1.1. Authentication is handled by separate handler classes (OAuthHandler, OAuth2BearerHandler) that manage token exchange and request signing. The streaming module uses long-lived HTTP connections to receive tweets in real-time, dispatching events to user-defined callbacks. Pagination is abstracted via Paginator, which yields pages or items lazily.

Self-Hosting & Configuration

  • Requires Python 3.7 or newer
  • Install with pip install tweepy
  • Create a Twitter Developer account and generate API keys and tokens
  • Set the appropriate access level (Essential, Elevated, Academic) for your use case
  • Store credentials in environment variables or a secrets manager, never in code

Key Features

  • Dual API support: v2 Client for modern endpoints, v1.1 API for legacy features
  • Built-in rate limit handling with configurable wait behavior
  • StreamingClient for real-time tweet filtering by keywords, users, or rules
  • Automatic response model parsing into Python objects
  • Async support via tweepy.asynchronous for non-blocking operations

Comparison with Similar Tools

  • python-twitter — Older alternative that only supports API v1.1; Tweepy covers both v1.1 and v2
  • twarc — Focused on Twitter data archiving and research; Tweepy is more general-purpose
  • snscrape — Scrapes Twitter without API keys but breaks when the site changes; Tweepy uses the official API
  • TwitterAPI — Thin wrapper with less abstraction; Tweepy provides more convenience methods and models

FAQ

Q: Does Tweepy work with the X (Twitter) API v2? A: Yes. The tweepy.Client class is specifically designed for API v2 endpoints.

Q: How does Tweepy handle rate limits? A: By default, Tweepy waits automatically when a rate limit is hit. You can disable this with wait_on_rate_limit=False.

Q: Can I stream tweets in real time? A: Yes. Use StreamingClient with filtered stream rules to receive matching tweets as they are posted.

Q: What license does Tweepy use? A: MIT License.

Sources

Discusión

Inicia sesión para unirte a la discusión.
Aún no hay comentarios. Sé el primero en compartir tus ideas.

Activos relacionados