Skip to main content

A minimalistic UI framework for aiogram bots.

Project description

PyPI Package License: MIT

aiogramui 1.2.0

✨ A minimalistic UI framework for aiogram bots.

Installation

pip install aiogramui

Documentation

Pages

Let's create start page and child page "Wallet":

from aiogramui import *

init(router)

startpage = Root('start', backtext='Back')
wallet = startpage.page('Wallet')

@startpage
@router.message(Command('start'))
async def on_start(msg: Message, keyboard=None):
    await msg.answer('start page', reply_markup=startpage.keyboard(msg).as_markup())

@wallet
async def on_wallet(msg: Message, keyboard=None):
    await msg.answer('wallet page', reply_markup=keyboard.as_markup())

register()

init() and register() are required. Root() - a root page that doesn't have back button. All pages has elements functions, to learn more about them, keep read.

Elements

Dialog

Root.dialog(text, *filters)

Usage:

users = {
    'evr4': '1234',
    'evryoneowo': '1337',
    'bestusr': '111111'
}

login = start.dialog('Log in')

@passwd.arg('Enter your login')
async def on_login(msg: Message, args):
    login = args[0]
    if login not in users: return 
    # If user entered not valid login then it will ask him again.

    return True
    # All arg handlers must return True if all correct
    # (if they return None then arg will be repeated)

@passwd.arg('Enter the password')
async def on_passwd(msg: Message, args):
    password = users[args[0]]
    entered_password = args[1]
    if password != entered_password: await login.cancel(msg)
    # If user entered not valid password then it will cancel dialog.

    await msg.answer(f'Welcome, {args[0]}!')

Button

Root.button(text, *filters)

Usage:

hwbtn = start.button('Click me')

@hwbtn
async def on_hwbtn(msg: Message):
    await msg.answer('Hello, World!')

Checkbox

Root.checkbox(off, on, *filters, default=False)

Usage:

checkbox = start.checkbox('off', 'on')

@checkbox
async def on_checkbox(msg: Message, state):
    await msg.answer(f'State: {state}')

You can also save values of checkboxes for loading them later using chats arg in checkbox().

Handle

handle(cqdata, *filters)

Usage: If you has inline keyboard with cqdata "delete" that deletes message:

@handle(data == 'hi')
async def on_hi(cq: CallbackQuery):
    await cq.message.delete()

Filters

You can use filters at pages or elements. e.g.

from aiogramui.filters import UserFilter

admins = [12453, 21546, 69283]

adminpage = start.page('Admin', UserFilter(admin))

@adminpage
async def on_adminpage(msg: Message, keyboard):
    await msg.answer('Admin page', reply_markup=keyboard.as_markup())

Doc

doc = start.generate_doc()

It will generate docs of your menu using docstrings for descriptions.

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

aiogramui-1.2.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

aiogramui-1.2.0-py3-none-any.whl (8.2 kB view details)

Uploaded Python 3

File details

Details for the file aiogramui-1.2.0.tar.gz.

File metadata

  • Download URL: aiogramui-1.2.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for aiogramui-1.2.0.tar.gz
Algorithm Hash digest
SHA256 138481ca94b1c80cb79229016d5807a02c985f789362dd12cdb0480d08600e15
MD5 ee5fb7debd1fb6628e2fc66f698514f2
BLAKE2b-256 54079078af46beebfce9996ee03a5157a257762dc1d6e9c575e62a20ee2a2f8d

See more details on using hashes here.

File details

Details for the file aiogramui-1.2.0-py3-none-any.whl.

File metadata

  • Download URL: aiogramui-1.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.13.11

File hashes

Hashes for aiogramui-1.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 3e0ac8507b1a46fc3da39e9e49c1ccbb985697063f0fe461aa951cf659188873
MD5 b08b357726099d7f87f9b5ee05dd20b3
BLAKE2b-256 153a9402cba9effb2af7e581fda0d2f850f6ea59870be4bd90d99395f15c15ba

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page