A collection of useful addons for the Kurigram library
Project description
This library is a collection of popular Addons and patches for pyrogram/Kurigram. Currently, Pykeyboard and Pyrogram-patch have been added. You're welcome to add more.
📘 Documentation is available at johnnie-610.github.io/kurigram-addons, featuring learnings, tutorials, and API references for PyKeyboard and Pyrogram Patch.
Installation
The easiest way to install the library is via PyPI:
using pip
pip install kurigram-addons
using poetry
poetry add kurigram-addons
install from source (development)
pip install git+https://github.com/johnnie-610/kurigram-addons.git
Usage
PyKeyboard (click to expand)
🎉This is pykeyboard for Kurigram 🎉
No need to change your code, just install the library and you're good to go.
Pykeyboard
- Pykeyboard
- What's new?
- Documentation
What's new?
- Minor changes due to update in Kurigram.
Documentation
Inline Keyboard
from pykeyboard import InlineKeyboard
Parameters:
- row_width (integer, default 3)
Inline Keyboard add buttons
Code
from pykeyboard import InlineKeyboard, InlineButton
keyboard = InlineKeyboard(row_width=3)
keyboard.add(
InlineButton('1', 'inline_keyboard:1'),
InlineButton('2', 'inline_keyboard:2'),
InlineButton('3', 'inline_keyboard:3'),
InlineButton('4', 'inline_keyboard:4'),
InlineButton('5', 'inline_keyboard:5'),
InlineButton('6', 'inline_keyboard:6'),
InlineButton('7', 'inline_keyboard:7')
)
Result
Inline Keyboard row buttons
Code
from pykeyboard import InlineKeyboard, InlineButton
keyboard = InlineKeyboard()
keyboard.row(InlineButton('1', 'inline_keyboard:1'))
keyboard.row(
InlineButton('2', 'inline_keyboard:2'),
InlineButton('3', 'inline_keyboard:3')
)
keyboard.row(InlineButton('4', 'inline_keyboard:4'))
keyboard.row(
InlineButton('5', 'inline_keyboard:5'),
InlineButton('6', 'inline_keyboard:6')
)
Result
Pagination inline keyboard
from pykeyboard import InlineKeyboard
Parameters:
- count_pages (integer)
- current_page (integer)
- callback_pattern (string) - use of the
{number}pattern is required
Pagination 3 pages
Code
from pykeyboard import InlineKeyboard
keyboard = InlineKeyboard()
keyboard.paginate(3, 3, 'pagination_keyboard:{number}')
Result
Pagination 5 pages
Code
from pykeyboard import InlineKeyboard
keyboard = InlineKeyboard()
keyboard.paginate(5, 3, 'pagination_keyboard:{number}')
Result
Pagination 9 pages
Code
from pykeyboard import InlineKeyboard
keyboard = InlineKeyboard()
keyboard.paginate(9, 5, 'pagination_keyboard:{number}')
Result
Pagination 100 pages
Code
from pykeyboard import InlineKeyboard
keyboard = InlineKeyboard()
keyboard.paginate(100, 100, 'pagination_keyboard:{number}')
Result
Pagination 150 pages and buttons
Code
from pykeyboard import InlineKeyboard, InlineButton
keyboard = InlineKeyboard()
keyboard.paginate(150, 123, 'pagination_keyboard:{number}')
keyboard.row(
InlineButton('Back', 'pagination_keyboard:back'),
InlineButton('Close', 'pagination_keyboard:close')
)
Result
Languages inline keyboard
from pykeyboard import InlineKeyboard
Parameters:
- callback_pattern (string) - use of the
{locale}pattern is required - locales (string | list) - list of language codes
- be_BY - Belarusian
- de_DE - German
- zh_CN - Chinese
- en_US - English
- fr_FR - French
- id_ID - Indonesian
- it_IT - Italian
- ko_KR - Korean
- tr_TR - Turkish
- ru_RU - Russian
- es_ES - Spanish
- uk_UA - Ukrainian
- uz_UZ - Uzbek
- row_width (integer, default 2)
Code
from pykeyboard import InlineKeyboard
keyboard = InlineKeyboard(row_width=3)
keyboard.languages(
'languages:{locale}', ['en_US', 'ru_RU', 'id_ID'], 2
)
Result
Reply Keyboard
from pykeyboard import ReplyKeyboard
Parameters:
- resize_keyboard (bool, optional)
- one_time_keyboard (bool, optional)
- selective (bool, optional)
- row_width (integer, default 3)
Reply Keyboard add buttons
Code
from pykeyboard import ReplyKeyboard, ReplyButton
keyboard = ReplyKeyboard(row_width=3)
keyboard.add(
ReplyButton('Reply button 1'),
ReplyButton('Reply button 2'),
ReplyButton('Reply button 3'),
ReplyButton('Reply button 4'),
ReplyButton('Reply button 5')
)
Result
Reply Keyboard row buttons
Code
from pykeyboard import ReplyKeyboard, ReplyButton
keyboard = ReplyKeyboard()
keyboard.row(ReplyButton('Reply button 1'))
keyboard.row(
ReplyButton('Reply button 2'),
ReplyButton('Reply button 3')
)
keyboard.row(ReplyButton('Reply button 4'))
keyboard.row(ReplyButton('Reply button 5'))
Result
Pyrogram Patch (click to expand)
pyrogram_patch
pyrogram_patch is a powerful extension for Pyrogram that enhances it with advanced features for building robust Telegram bots. It provides middleware support, Finite State Machine (FSM) capabilities, and thread-safe data management, making it easier to develop complex bot interactions.
✨ Features
- Middleware System: Intercept and process updates with a powerful middleware pipeline
- Finite State Machine (FSM): Manage complex conversation flows with ease
- Router Support: Organize your handlers into modular components
- Thread-Safe: Built with thread safety for high-load applications
- Flexible Storage: Multiple storage backends with Redis and MongoDB support
- Type Safety: Full type hints for better development experience
- Easy Integration: Works seamlessly with existing Pyrogram code
🚀 Quick Start
Basic Usage
from pyrogram import Client, filters
from pyrogram_patch import patch, Router
from pyrogram_patch.fsm import StatesGroup, State, StateFilter
# Initialize the client and router
app = Client("my_bot")
router = Router()
# Apply the patch
patch_manager = patch(app)
# Define states
class Registration(StatesGroup):
waiting_for_name = State()
waiting_for_age = State()
# Command handler with router
@router.on_message(filters.command("start") & filters.private)
async def start(client, message, state):
await state.set_state(Registration.waiting_for_name)
await message.reply("Welcome! Please enter your name:")
# State handler with router
@router.on_message(StateFilter(Registration.waiting_for_name) & filters.private)
async def process_name(client, message, state):
await state.update_data(name=message.text)
await state.set_state(Registration.waiting_for_age)
await message.reply(f"Nice to meet you, {message.text}! How old are you?")
# Include router in the application
app.include_router(router)
# Run the bot
if __name__ == "__main__":
app.run()
🔌 Middleware System
Easily add middleware to process updates before they reach your handlers:
from pyrogram_patch.middlewares import BaseMiddleware
class AuthMiddleware(BaseMiddleware):
def __init__(self, allowed_users: list):
self.allowed_users = allowed_users
async def __call__(self, update, client, patch_helper):
if update.from_user.id not in self.allowed_users:
await update.reply("Access denied!")
return None # Stop processing
return await self.next(update, client, patch_helper)
# Register middleware
middleware_manager = MiddlewareManager()
middleware_manager.register(MessageHandler, AuthMiddleware([12345678]))
💾 Storage Options
Built-in Storage Backends
from pyrogram_patch.fsm.storages import MemoryStorage, RedisStorage, MongoStorage
# In-memory storage (not persistent across restarts)
storage = MemoryStorage()
# Redis storage (persistent)
redis_storage = RedisStorage(
host="localhost",
port=6379,
db=0,
ttl=86400 # 24 hours
)
# MongoDB storage (persistent with document support)
mongo_storage = MongoStorage(
host="mongodb://localhost:27017/",
db_name="bot_states",
collection_name="user_states"
)
Custom Storage
Implement your own storage by extending the BaseStorage class:
from typing import Optional, Dict, Any
from datetime import datetime, timedelta
from pyrogram_patch.fsm.base_storage import BaseStorage
from pyrogram_patch.fsm.states import StateData
class CustomStorage(BaseStorage):
def __init__(self, connection_string: str):
self.connection = self._connect(connection_string)
async def get_state(self, key: str) -> Optional[StateData]:
data = await self.connection.get(f"state:{key}")
return StateData(**data) if data else None
async def set_state(self, key: str, state_data: StateData) -> None:
await self.connection.set(
f"state:{key}",
state_data.dict(),
ex=state_data.ttl or 86400 # Default 24h TTL
)
async def delete_state(self, key: str) -> None:
await self.connection.delete(f"state:{key}")
async def _cleanup(self) -> None:
"""Optional: Clean up expired states"""
pass
📚 Documentation
For complete documentation, including advanced usage and API reference, visit:
💬 Community
Join our community for support and discussions:
🤝 Contributing
Contributions are welcome! Please open an issue or submit a pull request.
📄 License
This project is licensed under the MIT License - see the LICENSE file for details.
🥳 Have fun with pyrogram_patch! 🎉
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.3.1.tar.gz.
File metadata
- Download URL: kurigram_addons-0.3.1.tar.gz
- Upload date:
- Size: 72.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
292d3e6cfacf8da3d23a513bf88623f7a343aa72296afb2a900f90598d5e8561
|
|
| MD5 |
59897b0e2c04b26275d41cde72838b8d
|
|
| BLAKE2b-256 |
42cf163d86f28d795c24f2b76ae0f692427c30334607f09efc6e9b9fdda52c24
|
Provenance
The following attestation bundles were made for kurigram_addons-0.3.1.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.3.1.tar.gz -
Subject digest:
292d3e6cfacf8da3d23a513bf88623f7a343aa72296afb2a900f90598d5e8561 - Sigstore transparency entry: 962522325
- Sigstore integration time:
-
Permalink:
johnnie-610/kurigram-addons@08c3522a95b5d12431c4235ce3ca923cd5927b5a -
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@08c3522a95b5d12431c4235ce3ca923cd5927b5a -
Trigger Event:
push
-
Statement type:
File details
Details for the file kurigram_addons-0.3.1-py3-none-any.whl.
File metadata
- Download URL: kurigram_addons-0.3.1-py3-none-any.whl
- Upload date:
- Size: 93.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 |
3bcbe8ff8464b0197e71054233bf88998a85220de35f0fd5f9d99dff48c3661b
|
|
| MD5 |
520a695ad0a6827bb7cb1e5d5c206471
|
|
| BLAKE2b-256 |
2928e8ed72cd168caa62e69b16a234b8eec2c718f51d7a18bfc9845aa93f8751
|
Provenance
The following attestation bundles were made for kurigram_addons-0.3.1-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.3.1-py3-none-any.whl -
Subject digest:
3bcbe8ff8464b0197e71054233bf88998a85220de35f0fd5f9d99dff48c3661b - Sigstore transparency entry: 962522334
- Sigstore integration time:
-
Permalink:
johnnie-610/kurigram-addons@08c3522a95b5d12431c4235ce3ca923cd5927b5a -
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@08c3522a95b5d12431c4235ce3ca923cd5927b5a -
Trigger Event:
push
-
Statement type: