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 toolkit for building production Telegram bots with Kurigram. It provides a Client subclass, declarative FSM conversations, a menu system, dependency injection, rate limiting, and a powerful keyboard framework.

📚 Official Documentation →

✨ What's New in v0.4.0

  • KurigramClient — drop-in Client subclass that replaces patch(). Middleware, FSM, and routing built in.
  • Conversation handler — class-based multi-step flows with state descriptors.
  • Menu system — declarative menus with auto back-button and edit-in-place navigation.
  • Depends() — FastAPI-style dependency injection for handlers.
  • RateLimit — per-user / per-chat token-bucket rate limiter.
  • parse_command — typed /command arg1 arg2 argument parsing.
  • Router shortcuts@router.on_callback("data"), @router.on_command("cmd").
  • InlineKeyboard.button() — keyboard-router integration.

See the full CHANGELOG for details.

📦 Installation

pip install kurigram-addons

Requirements: Python 3.10+, kurigram >= 2.1.35 (or compatible Pyrogram fork), pydantic >= 2.11.

🚀 Quick Start

from kurigram_addons import KurigramClient, Router, MemoryStorage, InlineKeyboard

router = Router()

@router.on_command("start")
async def start(client, message):
    kb = InlineKeyboard(row_width=2)
    kb.button("👤 Profile", callback="profile")
    kb.button("⚙️ Settings", callback="settings")
    await message.reply("Welcome!", reply_markup=kb)

@router.on_callback("profile")
async def show_profile(client, query):
    await query.answer("Opening profile...")

app = KurigramClient(
    "my_bot",
    bot_token="YOUR_TOKEN",
    storage=MemoryStorage(),
    auto_flood_wait=True,
)
app.include_router(router)
app.run()

🧩 Features

KurigramClient

Replaces the old patch() pattern. Everything is configured at construction:

app = KurigramClient(
    "my_bot",
    bot_token="...",
    storage=MemoryStorage(),      # FSM storage
    auto_flood_wait=True,         # Auto-retry FloodWait
    max_flood_wait=60,            # Max seconds to wait
)
app.include_router(router)
app.include_conversation(Registration)
app.include_menus(main_menu, settings_menu)

Conversation Handler

Declarative multi-step FSM flows:

from kurigram_addons import Conversation, ConversationState

class Registration(Conversation):
    name = ConversationState(initial=True)
    age = ConversationState()

    @name.on_enter
    async def ask_name(self, ctx):
        await ctx.message.reply("What's your name?")

    @name.on_message
    async def save_name(self, ctx):
        await ctx.helper.update_data(name=ctx.message.text)
        await self.goto(ctx, self.age)

    @age.on_enter
    async def ask_age(self, ctx):
        await ctx.message.reply("How old are you?")

    @age.on_message
    async def save_age(self, ctx):
        await ctx.helper.update_data(age=int(ctx.message.text))
        await self.finish(ctx)

Menu System

Declarative menus with auto back-button:

from kurigram_addons import Menu

main_menu = Menu("main", text="Main Menu")
main_menu.button("👤 Profile", goto="profile")
main_menu.button("⚙️ Settings", goto="settings")

profile_menu = Menu("profile", text="Profile", parent=main_menu)
profile_menu.button("✏️ Edit Name", callback=edit_name_handler)

app.include_menus(main_menu, profile_menu)

Dependency Injection

from kurigram_addons import Depends

async def get_user(client, update):
    return await db.fetch_user(update.from_user.id)

@router.on_command("profile")
async def profile(client, message, user=Depends(get_user)):
    await message.reply(f"Hello, {user.name}!")

Rate Limiting

from kurigram_addons import RateLimit

@router.on_command("generate")
@RateLimit(per_user=3, window=60, message="Slow down! {remaining}s left.")
async def generate(client, message):
    await message.reply("Generating...")

Command Parser

from kurigram_addons import parse_command

@router.on_command("ban")
async def ban(client, message):
    args = parse_command(message.text, user_id=int, reason=str)
    # /ban 12345 spamming → {"user_id": 12345, "reason": "spamming"}

🏗️ Legacy Support

Old imports still work but emit deprecation warnings:

# ⚠️ Deprecated (still works, warns)
from pykeyboard import InlineKeyboard
from pyrogram_patch import patch

# ✅ Recommended
from kurigram_addons import InlineKeyboard, KurigramClient

🤝 Contributing

Raise tickets on the Issues Tracker.

git clone https://github.com/johnnie-610/kurigram-addons.git
cd kurigram-addons
poetry install
poetry run pytest tests/

📝 License

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.1.tar.gz (85.4 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.1-py3-none-any.whl (114.2 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: kurigram_addons-0.4.1.tar.gz
  • Upload date:
  • Size: 85.4 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.1.tar.gz
Algorithm Hash digest
SHA256 db90799b51c2c830d525147c6a18b70bd51ba8242e3ba4b1930676e502186dc3
MD5 54d05a9ebe256da6ecf6e2995a281368
BLAKE2b-256 e53f590a6b431421bb6a96d9136045344ef680d727f179d957731e5af92017a9

See more details on using hashes here.

Provenance

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

File metadata

File hashes

Hashes for kurigram_addons-0.4.1-py3-none-any.whl
Algorithm Hash digest
SHA256 d33ecf683d3d3a10d030065813402d7433854b57444767c14a5552bdc0b03043
MD5 b67051454027755a45e17a38f8e57025
BLAKE2b-256 6263372766fcef146d7c7220bf96cdcd51ceac0c65f0c949d97c0a83e4586366

See more details on using hashes here.

Provenance

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