Create most popular widgets for aiogram 3 in few code lines
Project description
aiogram_widgets
Create most popular widgets for aiogram 3x in a few code lines
🔗 Links
Features
- Fully customizable widgets
- Stateless
- Automatic handling
- Supports aiogram ^3.0.0b1
Roadmap
-
Checkboxes and multiselect
-
Calendar
-
Aiogram 2x support
Changelog
Version 1.2.0:
- Custom pagination keyboard support
- Aiogram 3.0.0b8 support
- README with more examples
- Live bot example with source code
- Better types naming
Installation
Pip:
pip install aiogram_widgets
Poetry:
poetry add aiogram_widgets
🤖 Bot example | Bot source code ⚙️
Usage/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,
pagination_key="test_kb_paginator",
per_page=20,
per_row=2
)
await message.answer(text="Keyboard pagination", reply_markup=paginator.as_markup())
Keyboard pagination with additional buttons (Same with text pagination)
from aiogram_widgets.pagination import KeyboardPaginator
@router.message(F.text == "/kb_additional_buttons")
async def kb_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,
pagination_key="test_kb_paginator",
additional_buttons=additional_buttons,
per_page=20,
per_row=2
)
await message.answer(
text="Keyboard pagination with additional buttons",
reply_markup=paginator.as_markup(),
)
Keyboard pagination with custom pagination buttons (Same with text pagination)
@router.message(F.text == "/kb_custom_pagination")
async def kb_custom_pagination(message: Message):
text_data = [f"I am string number {i}" for i in range(1, 1001)]
pagination_buttons = [
None, "<-", "->", None
]
paginator = TextPaginator(
data=text_data,
pagination_key="test_text_paginator",
pagination_buttons=pagination_buttons,
)
current_text_chunk, reply_markup = paginator.current_message_data
await message.answer(
text=current_text_chunk,
reply_markup=reply_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,
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 custom join
@router.message(F.text == "/text_join")
async def text_custom_join(message: Message):
text_data = [f"I am string number {i}" for i in range(1, 1001)]
paginator = TextPaginator(
data=text_data,
pagination_key="test_text_paginator",
data_joiner="\n\n",
)
current_text_chunk, reply_markup = paginator.current_message_data
await message.answer(
text=current_text_chunk,
reply_markup=reply_markup,
)
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.2.2.tar.gz
(6.0 kB
view hashes)
Built Distribution
Close
Hashes for aiogram_widgets-1.2.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | e33b9715f3e2820c5cf713c16367e8f2b858330836e5128b9e9db50d7944dd38 |
|
MD5 | 551229948423c8a79b5b809aae5a58db |
|
BLAKE2b-256 | f68a8eded0d5fe80a036b641952f0c622552a7f32e202ae01cd14e04c5027dd0 |