TgFlow
Pure Python MTProto 2.0 Telegram Framework
Engineered for speed, intuitive routing typography, full Telegram Layer 225 schema, 24 raw namespaces, and zero comment clutter.
Highlights
- Pure MTProto 2.0 Engine: Built from scratch adhering strictly to official Telegram MTProto specifications.
- Complete Official Schema (Layer 225): Exactly 1,573 TL types and 783 RPC methods compiled into type-safe Python classes with exact 4-byte aligned serialization.
- 24 Raw Namespaces: Direct low-level access via
tgflow.raw.functions.<namespace>andtgflow.raw.types.<namespace>(messages,channels,phone,payments,stories,aicompose,smsjobs, etc.). - MTProto Core & E2E Secret Chats: Native implementations of
core.telegram.org/schema/mtproto(45 types, 9 functions) andcore.telegram.org/schema/end-to-end(90 constructors). - Obfuscated2 TCP Framing: Live-verified transport connection to Telegram DC2 with 64-byte random payload handshakes.
- Advanced Routing Typography: Replaces cumbersome filter syntax with concise, direct decorators:
@bot.command("start")@bot.callback("confirm")@bot.message(When.photo)@bot.inline()
- Expressive When Condition Engine: Intuitive condition combinators via
When(orF):When.photo | When.video,When.private & ~When.bot. - Comprehensive Telegram Client API: Over 110 client methods covering media sending, polls, chat management, forum topics, stories, stars, collectibles, reactions, and VoIP/group calls.
- Rich Telegram Formatting: Full support for expandable blockquotes, spoilers, custom emoji, clickable links, and copy-text buttons.
- Interactive Documentation: Sphinx documentation featuring a dynamic animated scroll rail and TOC scrollspy.
- Zero Comments In Core Code: Self-explanatory, line-by-line clean idiomatic Python.
Installation
pip install pytgflow
Quickstart
import asyncio
from tgflow import TgFlow, When, CommandContext
from tgflow.types import Message, InlineKeyboardMarkup, InlineKeyboardButton
bot = TgFlow(
session="my_bot",
bot_token="YOUR_BOT_TOKEN_HERE",
)
# 1. Zero-argument command decorator (inferred from function name)
@bot.command
async def ping(client: TgFlow, message: Message):
await message.reply("pong!")
# 2. Typed parameterized command with automatic argument injection
@bot.command("ban <user_id:int> [reason:str]")
async def ban_user(client: TgFlow, message: Message, user_id: int, reason: str = "Spam"):
await client.ban_chat_member(message.chat.id, user_id)
await message.reply(f"Banned user {user_id}. Reason: {reason}")
# 3. CommandContext (ctx) shortcut
@bot.command("start", when=When.private)
async def handle_start(ctx: CommandContext):
keyboard = InlineKeyboardMarkup([
[InlineKeyboardButton(text="GitHub", url="https://github.com/VeezNetworks/TgFlow")],
[InlineKeyboardButton(text="Verify", callback_data="verify_user")]
])
await ctx.reply(
"<b>Welcome to TgFlow!</b>\n\nExperience clean, modern MTProto 2.0 in Python.",
parse_mode="html",
reply_markup=keyboard,
)
@bot.callback("verify_user")
async def handle_callback(client: TgFlow, query):
await query.answer("Account verified!", show_alert=True)
@bot.command("quote")
async def handle_quote(client: TgFlow, message: Message):
await message.reply_quote(
text="Native MTProto quote reply.",
quote=message.text,
)
@bot.command("secret")
async def handle_secret(client: TgFlow, message: Message):
await message.reply_ephemeral(
text="This message will self-destruct in 10 seconds.",
ttl_seconds=10,
)
asyncio.run(bot.run())
Comprehensive Architecture
| Domain | Module | Highlights |
|---|---|---|
| Client & Methods | tgflow.client |
110+ methods: send media, stories, stars, gifts, forum topics, group calls |
| Raw Namespaces | tgflow.raw |
24 namespaces: messages, channels, phone, payments, stories, aicompose, etc. |
| Typography & Routing | tgflow.filters |
Direct decorators @bot.command, @bot.callback, When & F engine |
| Rich Types | tgflow.types |
Message, User, Chat, Photo, Poll, InlineKeyboardMarkup, ChatMember |
| MTProto Transport | tgflow.transport |
Obfuscated2 framing, intermediate protocol (0xeeeeeeee) |
| Crypto & Handshake | tgflow.crypto |
AES-256 IGE, Pollard's rho PQ factorization, DH key exchange |
| Binary TL Schema | tgflow.tl |
TLReader/TLWriter, 2,356 constructors, 4-byte aligned serialization |
| Sessions | tgflow.session |
Portable string sessions with CRC32 integrity verification |
Documentation
Interactive documentation is built using Sphinx with the Furo UI and custom animated scroll tracking:
sphinx-build -b html docs docs/_build/html
Preview locally:
python -m http.server 8000 --directory docs/_build/html
Changelog
See CHANGELOG.md for full release notes and version history.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Metadata
Release files for pytgflow 1.8.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | |
|---|---|---|---|---|
| pytgflow-1.8.0.tar.gz | 599.2 kB | Without provenance | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| pytgflow-1.8.0-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 957.1 kB
Release files / pytgflow-1.8.0.tar.gz
| Download URL | pytgflow-1.8.0.tar.gz |
|---|---|
| Size | 599.2 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
4827207b3a9cb8a512f0964a461730446f476f7a0b883db312b24317657aa16f
|
|
BLAKE2b-256 checksum How to use checksums |
a32b37b51723816ab925e96614cab7755074d43dba0783929d92940f3897fcbd
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|
Release files / pytgflow-1.8.0-py3-none-any.whl
| Download URL | pytgflow-1.8.0-py3-none-any.whl |
|---|---|
| Size | 357.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
0deea9e224bfbb99666ac59741c0b20aed0cb8a5d3c5285b991c80c27b0c9fc0
|
|
BLAKE2b-256 checksum How to use checksums |
724b92f8883ee22552b2aa14df47e465973cd703ff763476858e6fbd52d75c5f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.6
|
Security for pytgflow 1.8.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.