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

python-telegram-bot — Python Wrapper for the Telegram Bot API

Build Telegram bots in Python with python-telegram-bot, a feature-rich async wrapper for the official Bot API with conversation handlers and job queues.

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 · 29/100Política: staging
Superficie agent
Cualquier agent MCP/CLI
Tipo
Skill
Instalación
Stage only
Confianza
Confianza: Established
Entrada
python-telegram-bot Overview
Comando de staging seguro
npx -y tokrepo@latest install 9c7223a1-7679-11f1-9bc6-00163e2b0d79 --target codex

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

Introduction

python-telegram-bot provides a pure Python, async interface to the Telegram Bot API. It abstracts away HTTP requests and webhook management so you can focus on bot logic with conversation flows, inline queries, and scheduled jobs.

What python-telegram-bot Does

  • Wraps every method in the Telegram Bot API with typed Python objects
  • Provides ConversationHandler for multi-step user dialogues
  • Includes a JobQueue for scheduling recurring or delayed tasks
  • Supports webhooks and long-polling out of the box
  • Handles rate limiting, retries, and connection pooling automatically

Architecture Overview

The library centers on the Application class, which manages an Updater (fetches updates via polling or webhook), a Dispatcher (routes updates to registered handlers), and a JobQueue (backed by APScheduler). Handlers are matched by type and filters, then executed as async coroutines. Persistence backends can store conversation state across restarts.

Self-Hosting & Configuration

  • Install via pip: pip install python-telegram-bot[all] for optional deps
  • Obtain a bot token from @BotFather on Telegram
  • Set webhooks with application.run_webhook(url=...) behind a reverse proxy
  • Use PicklePersistence or DictPersistence for state across restarts
  • Deploy as a systemd service, Docker container, or serverless function

Key Features

  • Full async/await support built on top of httpx
  • Rich filter system for routing messages by text, regex, media type, or custom logic
  • Built-in rate limiting that respects Telegram's per-chat and global limits
  • Arbitrary callback data for inline keyboards without string parsing
  • Extensive type hints and IDE autocompletion support

Comparison with Similar Tools

  • Aiogram — also async, lighter weight, but less built-in conversation management
  • Telethon — MTProto client for user accounts, not limited to the Bot API
  • pyTelegramBotAPI (telebot) — simpler synchronous API, less suitable for complex bots
  • node-telegram-bot-api — JavaScript equivalent, callback-based

FAQ

Q: Does it support Telegram Bot API payments? A: Yes, it wraps all payment-related methods including invoices, shipping queries, and pre-checkout handling.

Q: Can I run multiple bots in one process? A: Yes, create multiple Application instances each with their own token and run them concurrently.

Q: What Python versions are supported? A: Version 21.x requires Python 3.9 or later.

Q: How do I handle media groups? A: Use MediaGroupHandler or collect updates sharing the same media_group_id with a short timeout.

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