Skip to main content

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 aiogram-pagination

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 object
  • keyboard (InlineKeyboardMarkup): Base keyboard to paginate
  • nav_buttons (NavigationButtons): Navigation configuration
  • page_size (int): Items per page (default: 10)
  • additional_keyboard (InlineKeyboardMarkup): Additional keyboard at the bottom (optional)

Dependencies

  • aiogram>=3.0 - Telegram Bot API framework
  • pydantic>=2.0 - Data validation and settings management

Contributing

  1. Fork the repository
  2. Create a feature branch
  3. Make your changes
  4. Add tests if applicable
  5. Submit a pull request

License

This project is licensed under the MIT License.

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

pagination_aiogram3-0.1.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pagination_aiogram3-0.1.0-py3-none-any.whl (5.7 kB view details)

Uploaded Python 3

File details

Details for the file pagination_aiogram3-0.1.0.tar.gz.

File metadata

  • Download URL: pagination_aiogram3-0.1.0.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

Hashes for pagination_aiogram3-0.1.0.tar.gz
Algorithm Hash digest
SHA256 3d522e59890604c34f5f83b828241b7985b7f252b62769d2c755e4e7554824fd
MD5 dcfd4628ca5aaeee063d400adfcfc827
BLAKE2b-256 8c060d82349bde8eed88de99d585ff687d7f760a03582d8d5219a0df6eeff633

See more details on using hashes here.

File details

Details for the file pagination_aiogram3-0.1.0-py3-none-any.whl.

File metadata

File hashes

Hashes for pagination_aiogram3-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 34330c345fbbbb5494113d44efb2b6da7b32b08906238cd15a61981379a20154
MD5 8ede65cf966416b2dcd33de77af6c9ef
BLAKE2b-256 52bd4e157a22c5d78ab01c37798e841c9c2df0e7b7f5dfa4fe1b6a7dcef1d60f

See more details on using hashes here.

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