Skip to main content

A collection of useful addons for the Kurigram library

Project description

kurigram-addons Logo

kurigram-addons

Advanced toolset for the Kurigram / Pyrogram ecosystem.

PyPI PyPI Downloads License Python

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+,
  • 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


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.4.0.tar.gz (84.3 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.4.0-py3-none-any.whl (111.8 kB view details)

Uploaded Python 3

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

Hashes for kurigram_addons-0.4.0.tar.gz
Algorithm Hash digest
SHA256 036c7f23a60ec394a6748d047c6dff0b156f32c39bf27e2ef8f0d7887da864cc
MD5 981fe6a60d6345176536ed36b492f224
BLAKE2b-256 8151bf95275b6bdba998bf68063f121daf48c51fb76e6007a2f47b1f78ba5126

See more details on using hashes here.

Provenance

The following attestation bundles were made for kurigram_addons-0.4.0.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.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

Hashes for kurigram_addons-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6233a5af3ce212814e24fdc8c18c24a832931fd7c79d8d31e0ad52264656a261
MD5 a846b541807bc2b31bebc3e2896c8b8d
BLAKE2b-256 db50e9a18bad5384324286f4bd5e2665a668018f413339c858d3b4ef1d492726

See more details on using hashes here.

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

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