Skip to main content

A minimalistic UI framework for aiogram bots.

Project description

PyPI version License: MIT

aiogramui

✨ A minimalistic UI framework for aiogram bots.

Contents

Installation

  1. Via pip
pip install aiogramui
  1. Using git
git clone https://github.com/evryoneowo/aiogramui && cd aiogramui
pip install .

Features

Building menu

from aiogram import Router
from aiogram.types import Message
from aiogram.filters import Command

from aiogramui import init, Root, register

router = Router()

init(router)

start = Root('Start', backtext='back')
wallet = start.page('Wallet')

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

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

register()

Adding buttons and dialogs

from aiogram.types import CallbackQuery

helloworld = start.button('HelloWorld')

@helloworld
async def on_helloworld(cq: CallbackQuery):
    await cq.message.answer('Hello, world!')
helloname = start.dialog('HelloName')

@helloname.arg('Enter your name:')
async def on_helloname(msg: Message, args):
    await msg.answer(f'Hello, {args[0]}!')

    return True

Generating doc

doc = start.generate_doc()

Pro tips

Cancel and repeat in dialogs

password = start.dialog('Password')

@password.arg('Enter the password:')
async def on_password(msg: Message, args):
    if args[0] != '1234': return # <- If user entered not valid password then it will ask him again.

    await msg.answer('Right!')
    
    return True
password = start.dialog('Password')

@password.arg('Enter the password:')
async def on_password(msg: Message, args):
    if args[0] != '1234': await password.cancel(msg) # <- If user entered not valid password then it will cancel dialog.

    await msg.answer('Right!')
    
    return True

Pages only for allowed users

admins = [123, 321]

admin = start.page('Admin', allow=admins)

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

[!WARNING] If you show a page only for allowed users, then you must get keyboard manually with user arg in parent page.

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.0.tar.gz (3.5 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.0-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: aiogramui-1.0.tar.gz
  • Upload date:
  • Size: 3.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for aiogramui-1.0.tar.gz
Algorithm Hash digest
SHA256 3a1c58adc81b9f65ff14648658b826de1fbd29bd61fff0e70c47ddae40fbeed9
MD5 a0f2f284760f577b09d6851063148b5c
BLAKE2b-256 92f5485c398b2778dfa7278d7591f48186b460fa001e13ba0818a946cc62772a

See more details on using hashes here.

File details

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

File metadata

  • Download URL: aiogramui-1.0-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.1.0 CPython/3.13.5

File hashes

Hashes for aiogramui-1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 e38a718bbb5b6951b9bfc66d9134e6d3ca3f8f7acb76c5c173a4047eee51a3b6
MD5 a74fcef2609abf5d37b005515447752e
BLAKE2b-256 f659b1692f712c284877c553e83dd1254e0ae5762577e3298fb7b0952844ecfa

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