InlineKeyboard¶
Class
Advanced inline keyboard with built-in pagination and 50+ language selection.
Constructor¶
InlineKeyboard(
row_width: int = 3,
callback_pattern: str = "",
count_pages: int = 0,
current_page: int = 0,
custom_locales: dict[str, str] | None = None,
)
| Parameter | Type | Default | Description |
|---|---|---|---|
row_width | int | 3 | Buttons per row |
callback_pattern | str | "" | Pattern for callback data |
count_pages | int | 0 | Total pages (pagination) |
current_page | int | 0 | Current page number |
custom_locales | dict | None | User-defined custom locales |
Methods¶
paginate method¶
Create pagination keyboard with duplicate prevention and LRU caching.
keyboard.paginate(
count_pages: int,
current_page: int,
callback_pattern: str,
source: str | None = None,
)
| Parameter | Type | Description |
|---|---|---|
count_pages | int | Total pages (≥ 1) |
current_page | int | Current page (≥ 1) |
callback_pattern | str | Must contain {number} placeholder |
source | str \| None | Source ID for multi-client isolation |
Raises
PaginationError— invalid parametersPaginationUnchangedError— identical keyboard already exists for this source
Usage
languages method¶
Create language selection keyboard with validation.
| Parameter | Type | Description |
|---|---|---|
callback_pattern | str | Must contain {locale} placeholder |
locales | str \| list[str] | Locale code(s) to display |
row_width | int | Buttons per row (≥ 1) |
Raises
LocaleError — invalid locale parameters
add method¶
Add buttons in rows based on row_width.
Usage
row method¶
Add a single row of buttons (ignores row_width).
add_custom_locale method¶
Register a custom locale for language keyboards.
Usage
remove_custom_locale method¶
Remove a custom locale. Returns True if removed, False if it didn't exist.
get_custom_locales method¶
Get all custom locales defined on this keyboard.
Returns: dict[str, str] — locale codes → display names
get_all_locales method¶
Get all available locales (built-in + custom).
Returns: dict[str, str] — all locale codes → display names
clear_pagination_hashes classmethod¶
Clear stored pagination hashes for memory management.
Returns: Number of hashes cleared.
get_pagination_hash_stats classmethod¶
Get statistics about stored pagination hashes.
Returns: dict[str, Any] with hash storage stats.
Properties¶
pyrogram_markup property¶
Get the Pyrogram InlineKeyboardMarkup for use with reply_markup=.
Returns: InlineKeyboardMarkup