GoyGram — one Python runtime for both Telegram Bot API and MTProto, with a Rust core and OpSec-first sessions
GoyGram is a Telegram framework for Python. It runs both of Telegram's protocols — Bot API and MTProto — in a single asyncio runtime, and moves crypto and TL serialization into a compiled Rust extension. The dual-transport problem aiogram and python-telegram-bot are Bot API only. telethon and pyrogram are MTProto only. GoyGram runs both in one process, one loop, one dispatcher — the transport is…
GoyGram is a Python framework for Telegram that supports both the Bot API and MTProto protocols within a single asyncio runtime. It incorporates cryptographic functions and TL serialization into a compiled Rust extension. This innovative approach differentiates GoyGram from other popular libraries like aiogram and python-telegram-bot, which focus exclusively on the Bot API, and telethon and pyrogram, which are limited to MTProto.
The framework operates within a single process, utilizing one loop and one dispatcher. It intelligently selects the appropriate transport for each operation, ensuring seamless communication between the two protocols. The Rust core, employing AES-256-IGE and AES-256-GCM, operates with high performance - as demonstrated by benchmarks on a virtual private server running Python 3.11.
Cold import takes just 87 milliseconds, while RSS after import is a modest 12 MB, in stark contrast to other libraries that can consume 152 MB or more.
Performance is further enhanced by GoyGram's AES-256-IGE encryption, which achieves an impressive 113 MB per second, more than ten times faster than the default implementation in telethon. The framework also employs zero-overhead dynamic dispatch, resolving methods from the TL schema at load time, and reading raw fields lazily, thereby minimizing memory usage.
One of GoyGram's standout features is its commitment to operational security (OpSec). Sessions are stored securely in an AES-256-GCM vault, keyed to the machine's ID. Upon logout, keys are securely erased from memory, and login is restricted to terminal-only methods, such as QR codes, phone numbers, or two-factor authentication - ensuring that no tokens ever leave the device. The framework also supports multi-session capabilities, filters, finite-state machine state machines, transport routing, and an event pipeline.
For those interested in exploring GoyGram, the project is hosted on GitHub (https://github.com/GoyGram/GoyGram) and the documentation can be found at (https://goygram.github.io). Licensed under AGPL-3.0, GoyGram offers a robust and secure solution for developers looking to leverage Telegram's capabilities in their Python applications.
Written by urgent.news from Dev.to's reporting — not their text. Machine-written — may contain errors; check the original before relying on it.