Skip to main content

Simple and universal keyboard/message builder for aiogram bots.

Project description

simple_aiogram

Powerful, declarative message and keyboard builder for aiogram bots, powered by Pydantic models.
Send, edit, and manage all kinds of Telegram messages and keyboards — as Python classes.

PyPI MIT License


✨ Features

  • Declarative: Describe messages, media, and keyboards as Python models.
  • Universal: Works with text, photo, video, documents, and all Telegram keyboards.
  • Auto-keyboards: Define buttons as class fields, get reply_markup automatically.
  • Flexible: Format any text/callback with runtime variables (str.format_map).
  • Async: All methods awaitable and designed for modern aiogram.
  • File caching: Smart file_id cache for instant media re-use.
  • Extensible: Use as a base class or mixin for your own message types.

🚀 Quick Start

from aiogram.types import Message, InlineKeyboardButton
from aiogram.filters import CommandStart

from simple_aiogram import TelegramWindow, BotModel

from my_routers import main_router

bot = BotModel(token="YOUR_BOT_TOKEN")
dp = bot.dispatcher

bot.include_router(main_router)


class HelloWindow(TelegramWindow):
    text: str = "Hello, {username}!"
    one: InlineKeyboardButton = InlineKeyboardButton(
        text="Click me",
        callback_data="clicked_{user_id}"
    )


@dp.message(CommandStart())
async def hello_handler(msg: Message):
    window = HelloWindow(event=msg)
    await window.answer(username=msg.from_user.username, user_id=msg.from_user.id)


if __name__ == "__main__":
    bot.run()

🎛️ Keyboard Example

Inline or Reply Keyboard — just declare buttons as class attributes:

from aiogram.types import InlineKeyboardButton, KeyboardButton

class KeyboardExample(MessageMethods):
    text: str = "Choose:"
    btn1: InlineKeyboardButton = InlineKeyboardButton(text="Yes", callback_data="yes_{user_id}")
    btn2: InlineKeyboardButton = InlineKeyboardButton(text="No", callback_data="no_{user_id}")
    btn3: InlineKeyboardButton = InlineKeyboardButton(text="Maybe", callback_data="maybe_{user_id}")

# Send with auto-built keyboard
await KeyboardExample(event=msg).answer(user_id=msg.from_user.id)

Or add buttons dynamically:

window = HelloWindow(event=msg)
window.add_buttons(
    InlineKeyboardButton(text="Profile", callback_data="profile_{user_id}")
)
await window.answer(username=msg.from_user.username, user_id=msg.from_user.id)

📦 Sending Media with File Caching

Send a photo/document/audio/video and automatically cache file_id:

class MediaWindow(MessageMethods):
    text: str = "Here is your file"
    photo: str = "/path/to/image.png"

# First send uploads, next times re-uses file_id!
await MediaWindow(event=msg).answer_photo()

🛠️ Advanced Usage

  • format_buttons(kwargs): Format all buttons and callback_data with dynamic values.

  • edit_text(), edit_reply_markup(), edit_media(): Fully supported for CallbackQuery events.

  • @cache: Decorator for auto file_id management (for InputFile uploads).

  • Easily extend for your own forms (see /models/text.py, /models/files.py).

📚 Documentation

Full API Reference

Examples

Pydantic models

aiogram docs

⚡️ Why simple_aiogram?

  • Cut boilerplate and repetitive keyboard code.

  • Add message logic as Python classes — not spaghetti handlers.

  • Maximum type safety and flexibility.

License

MIT License.

Author: belyankiss

Contributions and stars welcome!

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

simple_aiogram-0.1.0b0.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

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

simple_aiogram-0.1.0b0-py3-none-any.whl (13.7 kB view details)

Uploaded Python 3

File details

Details for the file simple_aiogram-0.1.0b0.tar.gz.

File metadata

  • Download URL: simple_aiogram-0.1.0b0.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.0 Windows/11

File hashes

Hashes for simple_aiogram-0.1.0b0.tar.gz
Algorithm Hash digest
SHA256 118e91195608b3b2a644ce3f7f0135797c233bdb73213f2d65f216c5ab193a90
MD5 bfe6c9bf40de6444a0531b5405535b0e
BLAKE2b-256 b873487cf12b67d002f8bd56e027453350af9c0a04f4316792ce624ab5b923ec

See more details on using hashes here.

File details

Details for the file simple_aiogram-0.1.0b0-py3-none-any.whl.

File metadata

  • Download URL: simple_aiogram-0.1.0b0-py3-none-any.whl
  • Upload date:
  • Size: 13.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.3 CPython/3.13.0 Windows/11

File hashes

Hashes for simple_aiogram-0.1.0b0-py3-none-any.whl
Algorithm Hash digest
SHA256 39298350a1997209c36c291fef1f9f97a418cb4de96aed57f041dae66880e2bd
MD5 61c22329226c6afc812cc15a68eefbe3
BLAKE2b-256 5f516d3993140ca88936f747293cd3acbbefae1645b442a434c0f6726567d8b0

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