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.3.7.tar.gz (71.5 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.7-py3-none-any.whl (93.7 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: kurigram_addons-0.3.7.tar.gz
  • Upload date:
  • Size: 71.5 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.7.tar.gz
Algorithm Hash digest
SHA256 7f69d452dd709468b4df787c9573dd9f89bb77a76da558d3bf0e7c4f3846fb8f
MD5 2cf3dd886f3501ff8b017545a9676052
BLAKE2b-256 71fcd74a15c63af6a210469eee81877b7e453662babf7ec32f28629340edacd7

See more details on using hashes here.

Provenance

The following attestation bundles were made for kurigram_addons-0.3.7.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.7-py3-none-any.whl.

File metadata

File hashes

Hashes for kurigram_addons-0.3.7-py3-none-any.whl
Algorithm Hash digest
SHA256 0561ffb229523b551adbb637965cb8ca9ac14b97a1004df72cce6458bd79dc3d
MD5 349e8db363c18224e422417dc2b5f96b
BLAKE2b-256 740a8abd2dcbdef259cf9edc8c2eee62b9e6a528c67f7670b6144f364c6ac727

See more details on using hashes here.

Provenance

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