Skip to main content

A collection of useful addons for the Kurigram library

Project description

kurigram-addons

Advanced enterprise-grade toolset for the Kurigram / Pyrogram ecosystem.

PyPI License


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 StatesGroup validation. Native support for persistent RedisStorage or rapid MemoryStorage.
  • Hierarchical Routers: Compose large-scale applications easily. Nest Router trees 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_width boundaries. Add a continuous stream of buttons, and let InlineKeyboard handle 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: Python 3.10+. Requires kurigram >= 2.1.35 (or a compatible Pyrogram distribution), pydantic >= 2.11, and 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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kurigram_addons-0.3.6.tar.gz (69.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kurigram_addons-0.3.6-py3-none-any.whl (92.3 kB view details)

Uploaded Python 3

File details

Details for the file kurigram_addons-0.3.6.tar.gz.

File metadata

  • Download URL: kurigram_addons-0.3.6.tar.gz
  • Upload date:
  • Size: 69.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for kurigram_addons-0.3.6.tar.gz
Algorithm Hash digest
SHA256 682c71479165fdc2b789fb6cf7bb596041a31fce85033d2434aae46356da4f2b
MD5 6b9a313879aa145e69b64209155cc389
BLAKE2b-256 22970aaf20d51d73b841abf8a0af4b5c6bd09015444cc1ac9db5b2f55e0d6cbc

See more details on using hashes here.

Provenance

The following attestation bundles were made for kurigram_addons-0.3.6.tar.gz:

Publisher: deploy.yml on johnnie-610/kurigram-addons

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file kurigram_addons-0.3.6-py3-none-any.whl.

File metadata

File hashes

Hashes for kurigram_addons-0.3.6-py3-none-any.whl
Algorithm Hash digest
SHA256 ce0f278081fd6825d15ce562a49c174e5b45cecae7708fc0cba351ec5ff8b2c2
MD5 2e4d44b6b59d4ac8329c2b69a9459f0b
BLAKE2b-256 d7364bf556b51a1b860ed1fba4a96f4b897eafe9d3f6d9353c82536661b4c3be

See more details on using hashes here.

Provenance

The following attestation bundles were made for kurigram_addons-0.3.6-py3-none-any.whl:

Publisher: deploy.yml on johnnie-610/kurigram-addons

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page