gitmyhub

Telethon

Python ★ 12k updated 3mo ago ▣ archived

Pure Python 3 MTProto API Telegram client library, for bots too!

Telethon is a Python library for automating Telegram, send messages, download media, or build bots using Telegram's full low-level protocol instead of the limited official Bot API.

PythonasyncioMTProtopipsetup: moderatecomplexity 2/5

Telethon is a Python library that lets you write programs that interact with Telegram, the messaging app. It talks directly to Telegram using the platform's own low-level protocol (called MTProto), rather than going through the more limited official Bot API. This means you can use it both as a regular user account and as a bot, giving it access to a wider range of Telegram features than the standard bot interface allows.

The library is built around Python's async/await system, which is a way of writing code that handles multiple things at once without blocking. A basic setup involves creating a client object with your Telegram API credentials (which you obtain from Telegram's developer portal), logging in, and then making calls to read or send data. The README shows short examples: sending a text message, sending a photo, and downloading media from a received message.

Installation is a single pip command. The README is brief and points to external documentation for more detailed examples, troubleshooting, and advanced usage.

One important note from the README: version 2.0 of Telethon introduced breaking changes compared to earlier versions. Anyone using older Telethon code is advised to read the migration guide before upgrading. The README also warns that using any third-party Telegram library carries a risk of account suspension if the usage violates Telegram's terms of service, so care is needed when automating user accounts.

Where it fits