⌨️ Keyboards¢

Raito has two keyboard decorators. Both return a ready aiogram markup, so you never manage builders or markup objects at the call site.

  • @rt.keyboard.static β€” declare the layout as the function’s return value;

  • @rt.keyboard.dynamic β€” build it imperatively with a builder.

Static β€” layout by return valueΒΆ

Return a list of rows. Each item is either a button (a str or a tuple) or a row (a list of buttons):

from raito import rt


@rt.keyboard.static(inline=False)
def start_markup():
    return [
        "πŸ€ Throw a ball",           # a row with one button
        ["πŸ“„ FAQ", "πŸ† Leaderboard"],  # a row with two buttons
    ]

For inline keyboards a button is a (text, value) tuple. value becomes callback_data, unless it looks like a URL (https://, tg://, t.me/...), in which case it becomes a URL button:

@rt.keyboard.static(inline=True)
def info_markup():
    return [
        ("πŸ’¬ Support", "support"),                    # callback button
        [("πŸ”’ Privacy", "privacy"), ("πŸ“„ TOS", "terms")],  # a two-button row
        ("🌐 Website", "https://example.com"),        # URL button
    ]

The decorator returns a ReplyKeyboardMarkup or InlineKeyboardMarkup depending on inline=. Call the function to get the markup:

await message.answer("Menu:", reply_markup=start_markup())

Dynamic β€” build with a builderΒΆ

When the layout depends on data, take the builder as the first argument and add buttons yourself. Any extra parameters are yours to pass at call time:

from aiogram.utils.keyboard import InlineKeyboardBuilder
from raito import rt


@rt.keyboard.dynamic(1, 2, inline=True)
def links_markup(builder: InlineKeyboardBuilder, privacy_url: str, tos_url: str):
    builder.button(text="πŸ’¬ Support", callback_data="support")
    builder.button(text="πŸ”’ Privacy", url=privacy_url)
    builder.button(text="πŸ“„ TOS", url=tos_url)


await message.answer(
    "Links:",
    reply_markup=links_markup(privacy_url="...", tos_url="..."),
)

ParametersΒΆ

Parameter

Meaning

inline

Build an inline (True) or reply (False) keyboard.

*sizes

Row-size pattern for adjust (e.g. 1, 2, 1).

adjust

Auto-arrange buttons with builder.adjust(*sizes).

repeat

Repeat the *sizes pattern to cover all buttons.

Set adjust=False to lay the keyboard out yourself β€” useful when the shape is conditional:

@rt.keyboard.dynamic(adjust=False)
def admin_markup(builder: InlineKeyboardBuilder, show_balance: bool = False):
    sizes = [1]
    builder.button(text="πŸ‘€ Users", callback_data="users")

    if show_balance:
        builder.button(text="πŸ“€ Withdraw", callback_data="withdraw")
        builder.button(text="πŸ“₯ Deposit", callback_data="deposit")
        sizes.append(2)

    builder.adjust(*sizes)