No project description provided
Project description
aiogram_widgets
Create most popular widgets for aiogram 3 in few code lines
Installation
Pip:
pip install aiogram_widgets
Poetry:
poetry add aiogram_widgets
Examples
Simple keyboard pagination
from aiogram_widgets.pagination import KeyboardPaginator
@router.message(F.text == "/keyboard_pagination")
async def keyboard_pagination(message: Message):
buttons = [
InlineKeyboardButton(text=f"Button {i}", callback_data=f"button_{i}")
for i in range(1, 1001)
]
paginator = KeyboardPaginator(
data=buttons,
router=router,
pagination_key="test_kb_paginator",
per_page=20,
row_witdh=2
)
await message.answer(text="Keyboard pagination", reply_markup=paginator.as_markup())
Keyboard pagination with additional buttons
from aiogram_widgets.pagination import KeyboardPaginator
@router.message(F.text == "/keyboard_pagination_with_additional_buttons")
async def keyboard_pagination_with_additional_buttons(message: Message):
buttons = [
InlineKeyboardButton(text=f"Button {i}", callback_data=f"button_{i}")
for i in range(1, 1001)
]
additional_buttons = [
InlineKeyboardButton(text="Go back 🔙", callback_data="go_back")
]
paginator = KeyboardPaginator(
data=buttons,
router=router,
pagination_key="test_kb_paginator",
additional_buttons=additional_buttons,
per_page=20,
row_witdh=2
)
await message.answer(
text="Keyboard pagination with additional buttons",
reply_markup=paginator.as_markup(),
)
Simple text pagination
from aiogram_widgets.pagination import TextPaginator
@router.message(F.text == "/text_pagination")
async def text_pagination(message: Message):
text_data = [
f"I am string number {i}"
for i in range(1, 1001)
]
paginator = TextPaginator(
data=text_data,
router=router,
pagination_key="test_text_paginator",
)
current_text_chunk, reply_markup = paginator.current_message_data
await message.answer(
text=current_text_chunk,
reply_markup=reply_markup,
)
Text pagination with additional buttons
@router.message(F.text == "/text_pagination_with_additional_buttons")
async def text_pagination_with_additional_buttons(message: Message):
text_data = [f"I am string number {i}" for i in range(1, 1001)]
additional_buttons = [
InlineKeyboardButton(text="Go back 🔙", callback_data="go_back")
]
paginator = TextPaginator(
data=text_data,
router=router,
pagination_key="test_text_paginator",
additional_buttons=additional_buttons,
)
current_text_chunk, reply_markup = paginator.current_message_data
await message.answer(
text=current_text_chunk,
reply_markup=reply_markup,
)
Text pagination with custom join
@router.message(F.text == "/text_pagination_with_custom_join")
async def text_pagination_with_custom_join(message: Message):
text_data = [f"I am string number {i}" for i in range(1, 1001)]
paginator = TextPaginator(
data=text_data,
router=router,
pagination_key="test_text_paginator",
additional_buttons=additional_buttons,
data_joiner="\n\n",
)
current_text_chunk, reply_markup = paginator.current_message_data
await message.answer(
text=current_text_chunk,
reply_markup=reply_markup,
)
🔗 Links
Feedback
I would be very pleased for a star ⭐️
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_widgets-1.1.0.tar.gz
(5.2 kB
view hashes)
Built Distribution
Close
Hashes for aiogram_widgets-1.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e667c276bf621c0110d21be989d33aaf4400253abccb6d1882fbdcfe34fabd6a |
|
MD5 | d0baa40b22112b037d856072368f1d36 |
|
BLAKE2b-256 | f7f5dd028a5224dd50c6b393a36a2f0dc84c6af3eaf08dc0606ab60fd0202912 |