gitmyhub

pyTelegramBotAPI

Python ★ 8.8k updated 4d ago

Python Telegram bot api.

A Python library for building Telegram bots, register message handlers, respond to commands, send files and polls, and choose between synchronous or async coding styles.

Pythonsetup: easycomplexity 2/5

pyTelegramBotAPI is a Python library for building Telegram bots. Telegram provides an official Bot API that lets you create automated accounts that can send and receive messages, respond to commands, send files, create polls, handle payments, and do many other things within Telegram chats. This library wraps that API so that Python developers can write bot logic without having to handle the underlying HTTP calls directly.

The library supports both regular (synchronous) and asynchronous programming styles. In the synchronous style, your code runs one step at a time in order. In the asynchronous style, your code can handle multiple incoming messages at once without waiting for each one to finish, which is better for bots that expect a lot of traffic. Both modes expose the same features.

To use the library, you create a bot account through Telegram's BotFather tool and receive an API token. You then write Python code that registers message handlers: functions that run automatically when certain types of messages arrive. A simple echo bot, which the README walks through step by step, takes about 10 lines of code. Handlers can filter by command, message content, or any custom condition you define.

The library is installed via pip, the standard Python package installer, and works with Python 3.10 through 3.14. It is kept up to date with Telegram's Bot API as Telegram releases new features. The README includes a thorough table of contents covering topics like inline mode, webhooks, middleware, proxy support, and how to send large text messages in chunks.

The project has official documentation hosted on Read the Docs, available in both English and Russian. It is described as production-ready but still actively developed. The full README is longer than what was shown.

Where it fits