python-telegram-bot-pagination


Namepython-telegram-bot-pagination JSON
Version 0.0.3 PyPI version JSON
download
home_pagehttps://github.com/ksinn/python-telegram-bot-pagination
SummaryPython inline keyboard pagination for Telegram Bot API
upload_time2023-09-11 12:36:35
maintainer
docs_urlNone
authorksinn
requires_python
licenseGPL2
keywords telegram bot api pagination keyboard inline tools
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage No coveralls.
            # python-telegram-bot-pagination

[![Download Month](https://img.shields.io/pypi/v/python-telegram-bot-pagination.svg)](https://pypi.python.org/pypi/python-telegram-bot-pagination)
[![Build Status](https://travis-ci.com/ksinn/python-telegram-bot-pagination.svg?branch=master)](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)

![](https://github.com/ksinn/python-telegram-bot-pagination/raw/master/examples/media/ex1.png)  ![](https://github.com/ksinn/python-telegram-bot-pagination/raw/master/examples/media/f1.jpg)

* [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:

![](https://github.com/ksinn/python-telegram-bot-pagination/raw/master/examples/media/m2.jpg)

#### 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:

![](https://github.com/ksinn/python-telegram-bot-pagination/raw/master/examples/media/ex1.png)
            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/ksinn/python-telegram-bot-pagination",
    "name": "python-telegram-bot-pagination",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "telegram bot api pagination keyboard inline tools",
    "author": "ksinn",
    "author_email": "ksinnd@gmail.com",
    "download_url": "https://files.pythonhosted.org/packages/3d/ac/761d6a3bcb230b8445dc716be5daf8421f48df24b7668701b86d30d25490/python-telegram-bot-pagination-0.0.3.tar.gz",
    "platform": null,
    "description": "# python-telegram-bot-pagination\n\n[![Download Month](https://img.shields.io/pypi/v/python-telegram-bot-pagination.svg)](https://pypi.python.org/pypi/python-telegram-bot-pagination)\n[![Build Status](https://travis-ci.com/ksinn/python-telegram-bot-pagination.svg?branch=master)](https://travis-ci.com/ksinn/python-telegram-bot-pagination)\n\nProvide easy way for create number pagination with inline keyboard for telegram bot on python.\n\n[Example](https://github.com/ksinn/python-telegram-bot-pagination/blob/master/examples/example.py) with [pyTelegramBotAPI](https://github.com/eternnoir/pyTelegramBotAPI)\n\n[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)\n\n![](https://github.com/ksinn/python-telegram-bot-pagination/raw/master/examples/media/ex1.png)  ![](https://github.com/ksinn/python-telegram-bot-pagination/raw/master/examples/media/f1.jpg)\n\n* [Installation.](#installation)\n* [Usage.](#usage)\n* [Button render controlling.](#button-render-controlling)\n* [Adding extra button.](#adding-extra-button)\n\n#### Installation\n\n    pip install python-telegram-bot-pagination\n\n#### Usage\n        from telegram_bot_pagination import InlineKeyboardPaginator\n\n        paginator = InlineKeyboardPaginator(\n            page_count,\n            current_page=page,\n            data_pattern='page#{page}'\n        )\n\n        bot.send_message(\n            chat_id,\n            text,\n            reply_markup=paginator.markup,\n        )\n\n\nInit arguments:\n* page_count - integer, total 1-based pages count.\n* current_page - integer, 1-based current page. Default 1\n* data_pattern - string with python style formatting named argument 'page'. Used for generate callback data for button. Default '{page}'\n\nProperties:\n* markup - json object for [InlineKeyboardMarkup](https://core.telegram.org/bots/api#inlinekeyboardmarkup) TelegramAPI type\n* keyboard - array of button's dist \n\n#### Button render controlling\nFor edit button render, use paginator object properties:\n\n* first_page_label\n* previous_page_label\n* current_page_label\n* next_page_label\n* last_page_label\n\nAll of them can by python style formatting string with one arg, or simple string.\n\nFor example:\n\n    class MyPaginator(InlineKeyboardPaginator):\n        first_page_label = '<<'\n        previous_page_label = '<'\n        current_page_label = '-{}-'\n        next_page_label = '>'\n        last_page_label = '>>'\n\n    paginator = MyPaginator(page_count)\n\nResult:\n\n![](https://github.com/ksinn/python-telegram-bot-pagination/raw/master/examples/media/m2.jpg)\n\n#### Adding extra button\nFor adding button line before and after pagination use methods:\n\n* add_before(*args)\n* add_after(*args)\n\nEach argument mast provide property 'text' and 'callback_data'\n\nFor example:\n\n    paginator.add_before(\n        InlineKeyboardButton('Like', callback_data='like#{}'.format(page)),\n        InlineKeyboardButton('Dislike', callback_data='dislike#{}'.format(page))\n    )\n    paginator.add_after(InlineKeyboardButton('Go back', callback_data='back'))\n\nResult:\n\n![](https://github.com/ksinn/python-telegram-bot-pagination/raw/master/examples/media/ex1.png)",
    "bugtrack_url": null,
    "license": "GPL2",
    "summary": "Python inline keyboard pagination for Telegram Bot API",
    "version": "0.0.3",
    "project_urls": {
        "Homepage": "https://github.com/ksinn/python-telegram-bot-pagination"
    },
    "split_keywords": [
        "telegram",
        "bot",
        "api",
        "pagination",
        "keyboard",
        "inline",
        "tools"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "3dac761d6a3bcb230b8445dc716be5daf8421f48df24b7668701b86d30d25490",
                "md5": "f402f8642f2b29d630262ae29c5a1aa5",
                "sha256": "15305e9faea6b33956f016f7c064adabc0e450142a7be33286c6f8d5fbbcdd49"
            },
            "downloads": -1,
            "filename": "python-telegram-bot-pagination-0.0.3.tar.gz",
            "has_sig": false,
            "md5_digest": "f402f8642f2b29d630262ae29c5a1aa5",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 3548,
            "upload_time": "2023-09-11T12:36:35",
            "upload_time_iso_8601": "2023-09-11T12:36:35.652959Z",
            "url": "https://files.pythonhosted.org/packages/3d/ac/761d6a3bcb230b8445dc716be5daf8421f48df24b7668701b86d30d25490/python-telegram-bot-pagination-0.0.3.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-09-11 12:36:35",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "ksinn",
    "github_project": "python-telegram-bot-pagination",
    "travis_ci": true,
    "coveralls": false,
    "github_actions": false,
    "lcname": "python-telegram-bot-pagination"
}
        
Elapsed time: 0.28928s