Skip to main content

A simple library for aiogram that allows you to easily do pagination for any Inline keyboards.

Project description

aiogram-inline-paginations

Description

A simple library for aiogram that allows you to easily do pagination for any Inline keyboards.

Install for pip:

pip install aiogram-inline-paginations

Install for poetry:

poetry add aiogram-inline-paginations

Create paginations object

from aiogram_inline_paginations.paginator import Paginator
from aiogram import types

kb = types.InlineKeyboardMarkup()
paginator = Paginator(data=kb, size=5)

Params

data: Any ready-to-use keyboard InlineKeyboardMarkup or any iterable object with InlineKeyboardButton.

size: The number of rows of buttons on one page, excluding the navigation bar.

Return

A paginator object that, when called, returns a ready-made keyboard with pagination.

Get data for registrations handler paginator

from aiogram_inline_paginations.paginator import Paginator
from aiogram import types

kb = types.InlineKeyboardMarkup()
paginator = Paginator(data=kb, size=5)


@dp.message_handler()
async def some_func(message: types.Message):
    await message.answer(
        text='Some menu',
        reply_markup=paginator()
    )

    args, kwargs = paginator.paginator_handler()
    dp.register_callback_query_handler(*args, **kwargs)

Return paginator_handler()

Data for registrations paginator.

Example

import random

from aiogram import Bot, Dispatcher, types
from aiogram.contrib.fsm_storage.memory import MemoryStorage
from aiogram.dispatcher.filters import CommandStart
from aiogram.utils.executor import Executor

from aiogram_inline_paginations.paginator import Paginator

token = 'your token'

storage = MemoryStorage()
bot = Bot(token=token)
dp = Dispatcher(bot, storage=storage)


@dp.message_handler(CommandStart(), state='*')
async def start(message: types.Message):
    await message.answer('Hello text')

    kb = types.InlineKeyboardMarkup()  # some keyboard

    '''To demonstrate, I will add more than 50 buttons to the keyboard and divide them into 5 lines per page'''
    kb.add(
        *[
            types.InlineKeyboardButton(
                text=str(random.randint(1000000, 10000000)),
                callback_data='pass'
            ) for i in range(2)
        ]
    )

    kb.add(
        *[
            types.InlineKeyboardButton(
                text=str(random.randint(1000000, 10000000)),
                callback_data='pass'
            ) for i in range(3)
        ]
    )

    kb.add(
        types.InlineKeyboardButton(
            text=str(random.randint(1000000, 10000000)),
            callback_data='pass'
        )
    )

    kb.add(
        *[
            types.InlineKeyboardButton(
                text=str(random.randint(1000000, 10000000)),
                callback_data='pass'
            ) for i in range(2)
        ]
    )

    kb.add(
        *[
            types.InlineKeyboardButton(
                text=str(random.randint(1000000, 10000000)),
                callback_data='pass'
            ) for i in range(50)
        ]
    )

    paginator = Paginator(data=kb, size=5)

    await message.answer(
        text='Some menu',
        reply_markup=paginator()
    )

    args, kwargs = paginator.paginator_handler()
    dp.register_callback_query_handler(*args, **kwargs)


if __name__ == '__main__':
    Executor(dp).start_polling()

Screenshots

First page:

img_1.png

Second page:

img_2.png

Last page:

img_3.png

The order of entries is not lost.

License MIT

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

aiogram-inline-paginations-0.1.7.tar.gz (4.8 kB view details)

Uploaded Source

Built Distribution

File details

Details for the file aiogram-inline-paginations-0.1.7.tar.gz.

File metadata

  • Download URL: aiogram-inline-paginations-0.1.7.tar.gz
  • Upload date:
  • Size: 4.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.14 CPython/3.10.3 Linux/5.4.0-122-generic

File hashes

Hashes for aiogram-inline-paginations-0.1.7.tar.gz
Algorithm Hash digest
SHA256 64aaa1d6c1ec855d694beb51bc677e160acc4140107b48f4a0453525cf851c6e
MD5 b1560eb4af26039808d6b5bde5633c44
BLAKE2b-256 1adcc9bde19c80aeb646391625f59f7110deb445252a0e53e5aa5dc0953552c1

See more details on using hashes here.

File details

Details for the file aiogram_inline_paginations-0.1.7-py3-none-any.whl.

File metadata

File hashes

Hashes for aiogram_inline_paginations-0.1.7-py3-none-any.whl
Algorithm Hash digest
SHA256 d34ea7c900ad816c497fe16b5a991a014c730cfde4c1f1f55195138098bc3c97
MD5 aa71292724e2c0e7fb37541b3085d6b2
BLAKE2b-256 f4e2462d6a3b53f4f9fceb8931296a27ff2d57a904b5448d0a0cab22f3e0e2cc

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page