Cette page est affichée en anglais. Une traduction française est en cours.
ScriptsJul 3, 2026·2 min de lecture

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.

Prêt pour agents

Staging sûr pour cet actif

Cet actif est d'abord staged. Le prompt copié demande à l'agent d'inspecter les fichiers staged avant d'activer scripts, config MCP ou config globale.

Stage only · 29/100Policy : staging
Surface agent
Tout agent MCP/CLI
Type
Skill
Installation
Stage only
Confiance
Confiance : Established
Point d'entrée
python-telegram-bot Overview
Commande de staging sûr
npx -y tokrepo@latest install 9c7223a1-7679-11f1-9bc6-00163e2b0d79 --target codex

Stage les fichiers d'abord; l'activation exige la revue du README et du 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

Fil de discussion

Connectez-vous pour rejoindre la discussion.
Aucun commentaire pour l'instant. Soyez le premier à partager votre avis.

Actifs similaires