A collection of useful addons for the Kurigram library
Project description
kurigram-addons is a professional collection of utilities designed to dramatically enhance the development, maintainability, and scalability of Telegram bots built with Kurigram.
It brings powerful features such as a fully-typed Finite State Machine (FSM), deep hierarchical routing, tri-phase execution middlewares, and an extreme-performance UI framework natively into your applications.
📚 Visit the Official Documentation Portal for detailed guides and API references!
🌟 Key Features
The package is conceptually divided into two primary submodules: pyrogram_patch and pykeyboard.
1. Pyrogram Patch (Core Engine Modding)
Replaces the standard Telegram event dispatcher with a modernized engine designed for clean architecture.
- FSM Context Manager: Manage conversation states with type-aware
StatesGroupvalidation. Native support for persistentRedisStorageor rapidMemoryStorage. - Hierarchical Routers: Compose large-scale applications easily. Nest
Routertrees with individual middlewares to modularize your bot similar to FastAPI or Express. - Tri-Phase Middlewares: Absolute control over the execution stack with pre-handler (
before), post-handler (after), and wrapping (around) capabilities. - Circuit Breakers & Timeouts: Integrated fault-tolerance configurations built via Pydantic.
2. PyKeyboard (UI Foundation)
A fully declarative UI manipulation framework that obliterates traditional boilerplate.
- Smart Layout Engine: Set global
row_widthboundaries. Add a continuous stream of buttons, and letInlineKeyboardhandle the row wrapping automatically. - Pagination Engine: Built-in pagination with complex cache validations. Generate hundreds of dynamic pages efficiently, protected by LRU-hashing caching to prevent duplicate edit delays.
- KeyboardFactory: Eliminate repetitive work. Create instantaneous Star Ratings, Confirm/Deny Dialogs, and Action Menus with one-liners.
- Builder API: A modern Fluent/Chaining builder interface for creating complex UIs sequentially.
📦 Installation
pip install kurigram-addons
Requirements:
Python3.10+,kurigram>= 2.1.35 (or a compatible Pyrogram distribution),pydantic>= 2.11,redis>= 6.0.0.
🚀 Quickstarts
Stateful Interactions (Pyrogram Patch / FSM)
from pyrogram import Client, filters
from pyrogram_patch import patch
from pyrogram_patch.fsm import StatesGroup, State
from pyrogram_patch.router import Router
app = Client("my_bot")
router = Router()
class Form(StatesGroup):
name = State()
age = State()
@router.on_message(filters.command("form"))
async def start_cmd(client, message, patch_helper):
await patch_helper.fsm.set_state(Form.name)
await message.reply("Welcome! What is your name?")
@router.on_message(patch_helper.fsm.state(Form.name))
async def process_name(client, message, patch_helper):
await patch_helper.fsm.update_data(name=message.text)
await patch_helper.fsm.set_state(Form.age)
await message.reply(f"Nice to meet you, {message.text}. How old are you?")
@router.on_message(patch_helper.fsm.state(Form.age))
async def process_age(client, message, patch_helper):
data = await patch_helper.fsm.get_data()
await patch_helper.fsm.finish() # Clears context
await message.reply(
f"<b>Registration Complete!</b>\nName: {data['name']}\nAge: {message.text}"
)
async def main():
# Patch the application and attach your router network
patch_manager = await patch(app)
patch_manager.include_router(router)
await app.start()
Responsive Smart Layouts (PyKeyboard)
from pyrogram import Client, filters
from pykeyboard import InlineKeyboard, InlineButton
app = Client("my_bot")
@app.on_message(filters.command("menu"))
async def show_menu(client, message):
# Create an automated layout wrapping at 2 buttons per row
kb = InlineKeyboard(row_width=2)
kb.add(
InlineButton("Settings", "settings"),
InlineButton("History", "history"),
InlineButton("Help Center", "help") # This drops automatically to Row 2
)
# Unconditionally force 'Exit' to monopolize its own row at the bottom
kb.row(InlineButton("🚪 Exit", "exit"))
# Modern direct attachment - no raw JSON conversions needed
await message.reply("Main System Menu:", reply_markup=kb)
🤝 Contributing
We rely on developer input! To suggest new features, fix bugs, or report vulnerabilities, please raise a ticket on the Issues Tracker.
Local Setup
Using poetry is the recommended method for development:
git clone https://github.com/johnnie-610/kurigram-addons.git
cd kurigram-addons
poetry install
poetry run pytest tests/
📝 License
Distributed under the MIT License. See LICENSE for details.
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 kurigram_addons-0.4.0.tar.gz.
File metadata
- Download URL: kurigram_addons-0.4.0.tar.gz
- Upload date:
- Size: 84.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
036c7f23a60ec394a6748d047c6dff0b156f32c39bf27e2ef8f0d7887da864cc
|
|
| MD5 |
981fe6a60d6345176536ed36b492f224
|
|
| BLAKE2b-256 |
8151bf95275b6bdba998bf68063f121daf48c51fb76e6007a2f47b1f78ba5126
|
Provenance
The following attestation bundles were made for kurigram_addons-0.4.0.tar.gz:
Publisher:
deploy.yml on johnnie-610/kurigram-addons
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kurigram_addons-0.4.0.tar.gz -
Subject digest:
036c7f23a60ec394a6748d047c6dff0b156f32c39bf27e2ef8f0d7887da864cc - Sigstore transparency entry: 983724028
- Sigstore integration time:
-
Permalink:
johnnie-610/kurigram-addons@dc5f47658b59cf8afd1b31d451bf87980c59aa12 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/johnnie-610
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deploy.yml@dc5f47658b59cf8afd1b31d451bf87980c59aa12 -
Trigger Event:
push
-
Statement type:
File details
Details for the file kurigram_addons-0.4.0-py3-none-any.whl.
File metadata
- Download URL: kurigram_addons-0.4.0-py3-none-any.whl
- Upload date:
- Size: 111.8 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6233a5af3ce212814e24fdc8c18c24a832931fd7c79d8d31e0ad52264656a261
|
|
| MD5 |
a846b541807bc2b31bebc3e2896c8b8d
|
|
| BLAKE2b-256 |
db50e9a18bad5384324286f4bd5e2665a668018f413339c858d3b4ef1d492726
|
Provenance
The following attestation bundles were made for kurigram_addons-0.4.0-py3-none-any.whl:
Publisher:
deploy.yml on johnnie-610/kurigram-addons
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
kurigram_addons-0.4.0-py3-none-any.whl -
Subject digest:
6233a5af3ce212814e24fdc8c18c24a832931fd7c79d8d31e0ad52264656a261 - Sigstore transparency entry: 983724045
- Sigstore integration time:
-
Permalink:
johnnie-610/kurigram-addons@dc5f47658b59cf8afd1b31d451bf87980c59aa12 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/johnnie-610
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
deploy.yml@dc5f47658b59cf8afd1b31d451bf87980c59aa12 -
Trigger Event:
push
-
Statement type: