https://github.com/ksinn/python-telegram-bot-pagination
Python inline keyboard pagination for Telegram Bot API
https://github.com/ksinn/python-telegram-bot-pagination
bot inline-keyboard keyboard pagination paginator python telegram telegram-bot telegram-bot-api
Last synced: 3 months ago
JSON representation
Python inline keyboard pagination for Telegram Bot API
- Host: GitHub
- URL: https://github.com/ksinn/python-telegram-bot-pagination
- Owner: ksinn
- License: other
- Created: 2020-04-25T14:28:42.000Z (about 6 years ago)
- Default Branch: master
- Last Pushed: 2023-10-28T17:40:36.000Z (over 2 years ago)
- Last Synced: 2025-12-15T08:22:58.608Z (6 months ago)
- Topics: bot, inline-keyboard, keyboard, pagination, paginator, python, telegram, telegram-bot, telegram-bot-api
- Language: Python
- Homepage:
- Size: 117 KB
- Stars: 111
- Watchers: 2
- Forks: 23
- Open Issues: 6
-
Metadata Files:
- Readme: README.md
- License: LICENSE.txt
Awesome Lists containing this project
README
# python-telegram-bot-pagination
[](https://pypi.python.org/pypi/python-telegram-bot-pagination)
[](https://travis-ci.com/ksinn/python-telegram-bot-pagination)
Provide easy way for create number pagination with inline keyboard for telegram bot on python.
[Example](https://github.com/ksinn/python-telegram-bot-pagination/blob/master/examples/example.py) with [pyTelegramBotAPI](https://github.com/eternnoir/pyTelegramBotAPI)
[Example](https://github.com/ksinn/python-telegram-bot-pagination/blob/master/examples/example2.py) with [python-telegram-bot](https://github.com/python-telegram-bot/python-telegram-bot)
 
* [Installation.](#installation)
* [Usage.](#usage)
* [Button render controlling.](#button-render-controlling)
* [Adding extra button.](#adding-extra-button)
#### Installation
pip install python-telegram-bot-pagination
#### Usage
from telegram_bot_pagination import InlineKeyboardPaginator
paginator = InlineKeyboardPaginator(
page_count,
current_page=page,
data_pattern='page#{page}'
)
bot.send_message(
chat_id,
text,
reply_markup=paginator.markup,
)
Init arguments:
* page_count - integer, total 1-based pages count.
* current_page - integer, 1-based current page. Default 1
* data_pattern - string with python style formatting named argument 'page'. Used for generate callback data for button. Default '{page}'
Properties:
* markup - json object for [InlineKeyboardMarkup](https://core.telegram.org/bots/api#inlinekeyboardmarkup) TelegramAPI type
* keyboard - array of button's dist
#### Button render controlling
For edit button render, use paginator object properties:
* first_page_label
* previous_page_label
* current_page_label
* next_page_label
* last_page_label
All of them can by python style formatting string with one arg, or simple string.
For example:
class MyPaginator(InlineKeyboardPaginator):
first_page_label = '<<'
previous_page_label = '<'
current_page_label = '-{}-'
next_page_label = '>'
last_page_label = '>>'
paginator = MyPaginator(page_count)
Result:

#### Adding extra button
For adding button line before and after pagination use methods:
* add_before(*args)
* add_after(*args)
Each argument mast provide property 'text' and 'callback_data'
For example:
paginator.add_before(
InlineKeyboardButton('Like', callback_data='like#{}'.format(page)),
InlineKeyboardButton('Dislike', callback_data='dislike#{}'.format(page))
)
paginator.add_after(InlineKeyboardButton('Go back', callback_data='back'))
Result:
