Package: aiogram-inline-paginations
aiogram-inline-paginationsDescriptionA simple library for aiogram that allows you to easily do pagination for any Inline keyboards.Install for pip:pipinstallaiogram-inline-paginationsInstall for poetry:poetryaddaiogram-inline-paginationsCreate paginations objectfromaiogram_inline_paginations.paginatorimportPaginatorfromaiogramimporttypeskb=types.InlineKeyboardMarkup()paginator=Paginator(data=kb,size=5)Paramsdata: 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.ReturnA paginator object that, when called, returns a ready-made keyboard with pagination.Get data for registrations handler paginatorfromaiogram_inline_paginations.paginatorimportPaginatorfromaiogramimporttypeskb=types.InlineKeyboardMarkup()paginator=Paginator(data=kb,size=5)@dp.message_handler()asyncdefsome_func(message:types.Message):awaitmessage.answer(text='Some menu',reply_markup=paginator())Return paginator_handler()Data for registrations paginator.ExampleimportrandomfromaiogramimportBot,Dispatcher,typesfromaiogram.contrib.fsm_storage.memoryimportMemoryStoragefromaiogram.dispatcher.filtersimportCommandStartfromaiogram.utils.executorimportExecutorfromaiogram_inline_paginations.paginatorimportPaginatortoken='your token'storage=MemoryStorage()bot=Bot(token=token)dp=Dispatcher(bot,storage=storage)@dp.message_handler(CommandStart(),state='*')asyncdefstart(message:types.Message):awaitmessage.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')foriinrange(2)])kb.add(*[types.InlineKeyboardButton(text=str(random.randint(1000000,10000000)),callback_data='pass')foriinrange(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')foriinrange(2)])kb.add(*[types.InlineKeyboardButton(text=str(random.randint(1000000,10000000)),callback_data='pass')foriinrange(50)])paginator=Paginator(data=kb,size=5,dp=dp)awaitmessage.answer(text='Some menu',reply_markup=paginator())if__name__=='__main__':Executor(dp).start_polling()Check box paginations exempleimportrandomfromaiogramimportBot,Dispatcher,typesfromaiogram.contrib.fsm_storage.memoryimportMemoryStoragefromaiogram.dispatcherimportFSMContextfromaiogram.dispatcher.filtersimportCommandStart,Textfromaiogram.utils.executorimportExecutorfromaiogram_inline_paginations.paginatorimportCheckBoxPaginatortoken='your token'storage=MemoryStorage()bot=Bot(token=token)dp=Dispatcher(bot,storage=storage)@dp.message_handler(CommandStart(),state='*')asyncdefstart(message:types.Message):awaitmessage.answer('Hello text')kb=types.InlineKeyboardMarkup()# some keyboardkb.add(*[types.InlineKeyboardButton(text=str(random.randint(1000000,10000000)),callback_data=f'pass_{str(random.randint(1000000,10000000))}')foriinrange(2)])kb.add(*[types.InlineKeyboardButton(text=str(random.randint(1000000,10000000)),callback_data=f'pass_{str(random.randint(1000000,10000000))}')foriinrange(3)])kb.add(types.InlineKeyboardButton(text=str(random.randint(1000000,10000000)),callback_data=f'pass_{str(random.randint(1000000,10000000))}'))kb.add(*[types.InlineKeyboardButton(text=str(random.randint(1000000,10000000)),callback_data=f'pass_{str(random.randint(1000000,10000000))}')foriinrange(2)])kb.add(*[types.InlineKeyboardButton(text=str(random.randint(1000000,10000000)),callback_data=f'pass_{str(random.randint(1000000,10000000))}')foriinrange(50)])paginator=CheckBoxPaginator(data=kb,size=5,callback_startswith='page_',callback_startswith_button='pass_',confirm_text='Approve',dp=dp)awaitmessage.answer(text='Some menu',reply_markup=paginator())@dp.callback_query_handler(Text(startswith='Approve',endswith='confirm'))asyncdefapprove(call:types.CallbackQuery,state:FSMContext):data=awaitstate.get_data()selected=data.get('page_selected',None)awaitcall.answer(text='Your selected"\n'.join(selected))if__name__=='__main__':Executor(dp).start_polling()confirim callback:f"{confirm_text}confirm"selected data:data=awaitstate.get_data()selected=data.get(f'{startswith}selected',None)ScreenshotsFirst page:Second page:Last page:The order of entries is not lost.License MIT