A comprehensive pagination system for aiogram inline keyboards with type safety and easy configuration
Project description
Aiogram Inline Pagination
A comprehensive pagination system for aiogram inline keyboards with type safety and easy configuration.
Features
- Pagination System: Navigate through large sets of data with back/next buttons
- Type Safety: Full type annotations for better code quality and IDE support
- Easy Configuration: Simple setup with customizable navigation buttons
- Flexible: Support for additional keyboards and custom page sizes
- Automatic Handler Registration: Built-in callback query handlers for navigation
Installation
pip install pagination-aiogram3
Quick Start
from aiogram import Bot, Dispatcher
from aiogram.types import Message, InlineKeyboardButton, InlineKeyboardMarkup
from aiogram_pagination import Paginator, NavigationButtons
import asyncio
bot = Bot(token="YOUR_BOT_TOKEN_HERE")
dp = Dispatcher()
def get_test_keyboard() -> InlineKeyboardMarkup:
inline_keyboard = []
for i in range(500):
inline_keyboard.append([
InlineKeyboardButton(text=str(i), callback_data=f"kb__{i}"),
InlineKeyboardButton(text=str(i + 1), callback_data=f"kb__{i + 1}")
])
return InlineKeyboardMarkup(inline_keyboard=inline_keyboard)
# Additional keyboard at the bottom
add_kb = InlineKeyboardMarkup(inline_keyboard=[
[InlineKeyboardButton(text="Назад", callback_data="back")]
])
# Russian paginator
ru_test_paginator = Paginator(
dp=dp,
keyboard=get_test_keyboard(),
page_size=30,
nav_buttons=NavigationButtons(
callback_prefix="call",
back="Назад",
next="Дальше"
),
additional_keyboard=add_kb
)
# English paginator
en_test_paginator = Paginator(
dp=dp,
keyboard=get_test_keyboard(),
page_size=30,
nav_buttons=NavigationButtons(
callback_prefix="en_call"
),
additional_keyboard=add_kb
)
async def menu_handler(message: Message, bot: Bot):
if message.from_user.language_code == "ru":
kb = ru_test_paginator
else:
kb = en_test_paginator
await message.answer(
text='Choose an option:',
reply_markup=kb()
)
async def main() -> None:
dp.message.register(menu_handler)
await dp.start_polling(bot)
if __name__ == "__main__":
asyncio.run(main())
Configuration
NavigationButtons
Configure the navigation buttons with the following parameters:
callback_prefix(str): Unique prefix for callback data (required)separator(str): Separator for callback data (default: ":")back(str): Text for back button (default: "Back")next(str): Text for next button (default: "Next")
Paginator
Configure the paginator with:
dp(Dispatcher): Aiogram dispatcher objectkeyboard(InlineKeyboardMarkup): Base keyboard to paginatenav_buttons(NavigationButtons): Navigation configurationpage_size(int): Items per page (default: 10)additional_keyboard(InlineKeyboardMarkup): Additional keyboard at the bottom (optional)
Dependencies
aiogram>=3.0- Telegram Bot API frameworkpydantic>=2.0- Data validation and settings management
Contributing
- Fork the repository
- Create a feature branch
- Make your changes
- Add tests if applicable
- Submit a pull request
License
This project is licensed under the MIT License.
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 pagination_aiogram3-0.1.1.tar.gz.
File metadata
- Download URL: pagination_aiogram3-0.1.1.tar.gz
- Upload date:
- Size: 5.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a7a230c7beaa7f0ba4036e303ab32eb00137c45d551ae25bd06cc5fc55e607c
|
|
| MD5 |
45b0f8eba841060bc2ec35bc7707389f
|
|
| BLAKE2b-256 |
99a1c6c663b7d91366528354cc41a941ea798dd12a948dbc6ceb5dd830d29093
|
File details
Details for the file pagination_aiogram3-0.1.1-py3-none-any.whl.
File metadata
- Download URL: pagination_aiogram3-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.7 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
3ca7ec4ac448dc25c970ed9da4b225acf2a7421d38ed17724abdd54f7271cbc5
|
|
| MD5 |
6191c843c86b25c84d69a5d0728f9a15
|
|
| BLAKE2b-256 |
5df64db5657c2f1a24053c66261b394778c025be7a48d3c00a9de954bbafcf8a
|