Skip to main content

Pyromenu Build Status

Pyromenu is an easy-to-extend object-oriented library for building keyboard menus for telegram bots on the Pyrogram

Base usage case

from pyrogram import Client, Filters, ReplyKeyboardRemove
from pyromenu import KButton, KRow, KMenu


app = Client("app")
# it's menu declaration style
menu = KMenu(
  KRow(
    KButton("English"), KButton("Russian"), KButton("Portugues")
  ),
  KRow(
    KButton("exit")
  )
)


@app.on_message(Filters.command("start"))
def send_keyboard(clt, msg):
  msg.reply("Hi / Привет / Oi", reply_markup=menu.keyboard)

# use KButton update_filter property for creating Filter for Handler's
@app.on_message(KButon("exit").update_filter)
def remove_keyboard(clt, msg):
  msg.reply("Bye / Пока / Adeus", reply_markup=ReplyKeyboardRemove)

ABC's

Pyromenu define 3 abstract classes: Button, Row, Menu

  • Button
    • __hash__
    • __eq__
    • keyboard_button(properrty) - return KeyboardButton
    • update_filter(property) - return Filter
  • Row
    • keyboard_row(property) - return list of KeyboardButton's
    • buttons(property) - return list of Button's
  • Menu
    • keyboard(property) - return ReplyKeyboardButton
    • one_time_keyboard(property) - same as keyboard, but with one_time_keyboard flag on
    • filter(property) - return composite Filter of all button
    • matched_button - take message and return first matched button

Built-in's

Pyromenu provides simple built-in implementations of each abstract classes: KButton, KRow, KMenu

Usage

Pyromenu has a distinctive menu declaration style inspired by the principles of Elegant Objects.

from pyrogram import Client
from pyromenu import KButton, KRow, KMenu


app = Client("app")
menu = KMenu(
  KRow(
    KButton("English"), KButton("Russian"), KButton("Portugues")
  ),
  KRow(
    KButton("exit")
  )
)

Sending

app.send_message(chat_id, text, reply_markup=menu.keyboard)
# or
# send one time keyboard
app.send_message(chat_id, text, reply_markup=menu.one_time_keyboard)

Handling

@app.on_message(KButton("exit").update_filter)
def exit(clt, msg):
    msg.reply("Bye / Пока / Adeus" reply_markup=ReplyKeyboardRemove)
# or
# if you have more complex menu
@app.on_message(menu.filter)
def handle_menu(clt, msg):
    matched_button = menu.matched_button(msg)
    if matched_button == KButton("exit"):
        msg.reply("Bye / Пока / Adeus" reply_markup=ReplyKeyboardRemove)
    ...

Expanding

All built-in classes have minimal dependency on others. All you need to do is implement abstract class. For example if you need to create button, which send location request you can create that:

from pyrogram import KeyboardButton, Filters
from pyromenu.abc import Button


class LocationButton(Button):
    def __init__(self, text):
        self._text = text

    def __hash__(self):
        return hash(self._text)

    def __eq__(self, other_button):
        return hash(self) == hash(other_button)

    @property
    def keyboard_button(self):
        return KeyboardButton(self._text, request_location=True)

    @property
    def update_filter(self):
        return Filters.create(
            name=f"{self._text}ButtonFilter",
            func=lambda flt, msg: flt.btn_txt == msg.text,
            btn_txt=self._text,
        )

or that:

from pyrogram import KeyboardButton
from pyromenu import KButton

class LocationButton(KButton):
    @property
    def keyboard_button(self):
        btn = super().keyboard_button
        btn.request_location = True
        return btn

and it's will be works well with any built-in classes

Installing

pip3 install pyromenu

Metadata

Release files for pyromenu 2.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyromenu 2.0
File Size Uploaded
pyromenu-2.0.tar.gz 5.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyromenu 2.0
File Interpreter ABI Platform
pyromenu-2.0-py3-none-any.whl Python 3 none any Details

Total release size: 18.1 kB

Release files / pyromenu-2.0.tar.gz

Download URL pyromenu-2.0.tar.gz
Size 5.4 kB
Tags Source
SHA-256 checksum
How to use checksums
e35b8433b8348b6f11828e6fae8631916cc2ddf125c75c6a2e2707bde4a8cef9
BLAKE2b-256 checksum
How to use checksums
31b955593799592158a1e6a0406a0863676ef6e18e9e3a66c1f69727a99a1244
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.3

Release files / pyromenu-2.0-py3-none-any.whl

Download URL pyromenu-2.0-py3-none-any.whl
Size 12.6 kB
Tags Python 3
SHA-256 checksum
How to use checksums
582e7f9c8e9050b6b5b9f0249521c2be84e6deb37719afe543eb3f5ab2c99c96
BLAKE2b-256 checksum
How to use checksums
8f481779c023de28bbf69f943f4360c07988f09098360a6e0a36037dbd666468
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.1.1 pkginfo/1.5.0.1 requests/2.23.0 setuptools/47.3.1 requests-toolbelt/0.9.1 tqdm/4.46.1 CPython/3.7.3

Release history Release notifications | RSS feed

This release

2.0 This release

2 release files

1.3

2 release files

1.2

2 release files

1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page