The Python framework for production Telegram bots.
Project description
Kudexgram
Kudexgram is a Python framework for production Telegram bots.
It is currently pre-alpha. The goal is not to be one more Bot API wrapper, but a FastAPI-like toolkit for building Telegram products: typed routing, async runtime, stateful conversations, testing utilities, Mini App helpers, AI streaming, payments, and production observability.
Vision
Telegram bots are becoming real applications: they need reliable state, clean developer experience, testable flows, Mini Apps, payments, AI responses, tracing, and deployment patterns. Kudexgram aims to make that feel boringly good.
Manifesto
Kudexgram makes Telegram bots feel small when they are small, and stay maintainable when they grow.
Write handlers as product logic. Return replies directly. Test conversations like conversations. Scale into explicit context, state, middleware, plugins, and production runtimes only when you need them.
from kudexgram import Bot, Context
bot = Bot.from_env()
@bot.command("start")
async def start(ctx: Context) -> str:
return "Hey. Kudexgram is alive."
@bot.text()
async def echo(message: str) -> str:
return f"You said: {message}"
bot.run_polling()
Middleware stays explicit when a bot grows:
@bot.use
async def log_chat(ctx: Context, next) -> bool:
print(ctx.chat_id)
return await next()
CLI
Kudexgram uses the short command name kdx.
kdx --help
kdx new mybot
cd mybot
python -m pip install -e ".[dev]"
copy .env.example .env
python bot.py
kdx dev
Install for development
python -m venv .venv
.venv\Scripts\activate
pip install -e ".[dev]"
pytest
If you use uv, the intended workflow is:
uv sync --extra dev
uv run pytest
uv run kdx --help
MVP Goals
- Thin
Botfacade over an application/runtime architecture. - Async Telegram Bot API client with a typed core and codegen-ready boundaries.
- Telegram API retries for rate limits, temporary HTTP failures, and network timeouts.
Botdecorators for small bots, plusRouterfor modular projects.- Router decorators for commands and text messages with compiled handler resolution.
- Context API with explicit
ctx: Contextinjection andctx.reply(...)sugar. - Middleware pipeline with
bot.use(...). - Clear handler signature errors for unsupported parameters.
- Runtime boundary for polling, webhook, replay, and tests.
- Minimal production-shaped state engine for conversations.
- Testing DSL for conversation-style tests with
bot.scenario(). - CLI entrypoint
kdxfor full project scaffolding and local development.
Testing DSL
Kudexgram tests can read like a Telegram chat:
scenario = bot.scenario(chat_id=42, user_id=7, first_name="Ada")
await scenario.send_message("/start")
scenario.assert_handled()
scenario.assert_last_reply("Hey Ada. Kudexgram is alive.")
scenario.assert_api_called("sendMessage")
Client Reliability
TelegramClient has a small production-minded retry policy:
- Telegram
429errors useparameters.retry_after. - Temporary HTTP
5xxresponses retry with exponential backoff. - Network timeouts and network errors retry before raising
TelegramNetworkError. - Non-retryable Telegram errors raise clear
TelegramAPIErrorsubclasses.
client = TelegramClient("token", retry_attempts=3, retry_backoff=0.5)
See ARCHITECTURE.md for the current v0.1 architecture direction.
Why not just aiogram or python-telegram-bot?
Those projects are excellent. Kudexgram is exploring a sharper product angle:
- Testing-first bot flows with replayable updates.
- Production-first runtime: rate limits, retries, tracing, queues, deploy recipes.
- AI-native helpers for streaming, tools, memory, and rich replies.
- Mini-App-ready backend helpers for Telegram Web Apps.
- Codegen-ready Telegram Bot API types so new Bot API releases can be adopted fast.
Status
The repository is being bootstrapped. APIs may change freely until 0.1.0.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file kudexgram-0.0.1.tar.gz.
File metadata
- Download URL: kudexgram-0.0.1.tar.gz
- Upload date:
- Size: 19.5 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d2a2048e346a8c7e56c72e5f76d9d2992f707011c5ba823e04e2945ef5f6b63f
|
|
| MD5 |
408d0adaf86bc612983cd07eb2fbefba
|
|
| BLAKE2b-256 |
3fb621f6468021f0592aa6acad111fa21da129b8eb044f3127510cf4570d6e1c
|
File details
Details for the file kudexgram-0.0.1-py3-none-any.whl.
File metadata
- Download URL: kudexgram-0.0.1-py3-none-any.whl
- Upload date:
- Size: 17.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.14.2
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3b4b6b3a41e099a4cc4513cb7b388227a39324e40e5283b0e70bb200b88651b7
|
|
| MD5 |
a418a383e6017423aa8122888ba89cc7
|
|
| BLAKE2b-256 |
34abfc34a0eec35b0b59945403f6bf526d21cb83efa4242034d9ff8cb7bf95f2
|