API referenceΒΆ
Bot and applicationΒΆ
Platform-neutral Bot facade for Phase 2.
- class peyk.bot.base.ClientLifecycle(*args, **kwargs)[source]ΒΆ
Bases:
ProtocolClientLifecycle provides the bot API surface used by peyk.
- class peyk.bot.base.BotDefaults(parse_mode: ParseMode | str | None = None, link_preview: bool | None = None, protect_content: bool | None = None, style_fallback: StyleFallback = StyleFallback.NONE)[source]ΒΆ
Bases:
objectDefaults applied only when the active capability registry confirms them.
- link_preview: bool | None = NoneΒΆ
- protect_content: bool | None = NoneΒΆ
- style_fallback: StyleFallback = 'none'ΒΆ
- class peyk.bot.base.Bot(token: str, *, platform: Literal['bale', 'telegram', 'rubika'], defaults: BotDefaults | None = None, on_unsupported: UnsupportedPolicy = UnsupportedPolicy.DEFAULT, session: Session | None = None, retry_policy: RetryPolicy | None = None, logger: Logger | None = None, base_url: str | None = None)[source]ΒΆ
Bases:
Generic[ClientT]Unified async bot facade over one audited platform client.
Example
bot = Bot("TOKEN", platform="telegram") @bot.command("start") async def start(message): await bot.send_message(message.chat.id, "Hello") bot.run()
- property client: ClientTΒΆ
Return the lazily-created raw platform client.
- async set_webhook(url: str, *, max_connections: int | None = None, allowed_updates: Sequence[str] | None = None, drop_pending_updates: bool | None = None, secret_token: str | None = None) bool[source]ΒΆ
Set the platform webhook after checking its audited capabilities.
secret_tokenis enforceable by Telegram only. Bale and Rubika use the framework-level path secret instead and therefore reject this platform-specific option rather than silently ignoring it.
- async delete_webhook(*, drop_pending_updates: bool | None = None) bool[source]ΒΆ
Remove the configured webhook when the platform exposes that operation.
- async get_webhook_info() WebhookInfo | WebhookInfo[source]ΒΆ
Return the native webhook-info model where the platform exposes it.
- normalize_update(raw: Update | Update | Update | InlineMessage) Message | CallbackQuery | IncomingChatMemberStatusUpdate | IncomingPreCheckoutQuery | IncomingShippingQuery | IncomingMessageDeleted | IncomingBotMembershipChange | Update | Update | Update[source]ΒΆ
Normalize a raw platform update and bind supported events to this bot.
- command(*names: str, prefix: str = '/') Callable[[Callable[[HandlerP], HandlerR]], Callable[[HandlerP], HandlerR]][source]ΒΆ
Register one handler for one or more command names.
Each alias is registered independently so all aliases share the exact original Python callable and its type signature. This delegates to
peyk.dispatcher.router.Router.command()on the botβs router.
- message(*filters: object) Callable[[Callable[[HandlerP], HandlerR]], Callable[[HandlerP], HandlerR]][source]ΒΆ
Register a message handler on the botβs plain router.
- callback_query(*filters: object) Callable[[Callable[[HandlerP], HandlerR]], Callable[[HandlerP], HandlerR]][source]ΒΆ
Register a callback-query handler on the botβs plain router.
- callback(data: str, *, prefix: bool = False) Callable[[Callable[[HandlerP], HandlerR]], Callable[[HandlerP], HandlerR]][source]ΒΆ
Register a callback handler for exact data or a data prefix.
- on_startup(callback: Callable[[], Awaitable[None] | None]) Callable[[], Awaitable[None] | None][source]ΒΆ
Register a startup callback using the bare-decorator form.
- on_shutdown(callback: Callable[[], Awaitable[None] | None]) Callable[[], Awaitable[None] | None][source]ΒΆ
Register a shutdown callback using the bare-decorator form.
- async run_async(**polling_options: object) None[source]ΒΆ
Validate the token, log startup, and run automatic polling asynchronously.
- run(**polling_options: object) None[source]ΒΆ
Run this botβs router with automatic polling in a blocking call.
- async send_message(chat_id: int | str, text: str | 'RichText' | Text, *, reply_to_message_id: int | str | None = None, reply_markup: object | None = None, parse_mode: ParseMode | str | None = None, **kwargs: object) Message[source]ΒΆ
Send plain or composable text and resolve formatting for the active platform.
- async send_photo(chat_id: int | str, photo: object, *, caption: str | 'RichText' | Text | None = None, parse_mode: ParseMode | str | None = None, **kwargs: object) Message[source]ΒΆ
Sends photo through the bot API.
- Parameters:
chat_id β Identifier of the target chat.
photo β Photo input supplied to the operation.
caption β Value used by this operation.
parse_mode β Value used by this operation.
- Returns:
Result produced by the bot operation.
- async send_video(chat_id: int | str, video: object, *, caption: str | 'RichText' | Text | None = None, parse_mode: ParseMode | str | None = None, **kwargs: object) Message[source]ΒΆ
Sends video through the bot API.
- Parameters:
chat_id β Identifier of the target chat.
video β Video input supplied to the operation.
caption β Value used by this operation.
parse_mode β Value used by this operation.
- Returns:
Result produced by the bot operation.
- async send_audio(chat_id: int | str, audio: object, *, caption: str | 'RichText' | Text | None = None, parse_mode: ParseMode | str | None = None, **kwargs: object) Message[source]ΒΆ
Sends audio through the bot API.
- Parameters:
chat_id β Identifier of the target chat.
audio β Audio input supplied to the operation.
caption β Value used by this operation.
parse_mode β Value used by this operation.
- Returns:
Result produced by the bot operation.
- async send_voice(chat_id: int | str, voice: object, *, caption: str | 'RichText' | Text | None = None, parse_mode: ParseMode | str | None = None, **kwargs: object) Message[source]ΒΆ
Sends voice through the bot API.
- Parameters:
chat_id β Identifier of the target chat.
voice β Voice input supplied to the operation.
caption β Value used by this operation.
parse_mode β Value used by this operation.
- Returns:
Result produced by the bot operation.
- async send_document(chat_id: int | str, document: object, *, caption: str | 'RichText' | Text | None = None, parse_mode: ParseMode | str | None = None, **kwargs: object) Message[source]ΒΆ
Sends document through the bot API.
- Parameters:
chat_id β Identifier of the target chat.
document β Document input supplied to the operation.
caption β Value used by this operation.
parse_mode β Value used by this operation.
- Returns:
Result produced by the bot operation.
- async edit_message_text(chat_id: int | str, message_id: int | str, text: str | 'RichText' | Text, *, parse_mode: ParseMode | str | None = None, **kwargs: object) Message[source]ΒΆ
Edits message text through the bot API.
- Parameters:
chat_id β Identifier of the target chat.
message_id β Identifier of the target message.
text β Text content supplied to the operation.
parse_mode β Value used by this operation.
- Returns:
Result produced by the bot operation.
- async send_contact(chat_id: int | str, phone_number: str, first_name: str, **kwargs: object) Message[source]ΒΆ
Sends contact through the bot API.
- Parameters:
chat_id β Identifier of the target chat.
phone_number β Value used by this operation.
first_name β Value used by this operation.
- Returns:
Result produced by the bot operation.
- async send_location(chat_id: int | str, latitude: float, longitude: float, **kwargs: object) Message[source]ΒΆ
Sends location through the bot API.
- Parameters:
chat_id β Identifier of the target chat.
latitude β Value used by this operation.
longitude β Value used by this operation.
- Returns:
Result produced by the bot operation.
- async send_poll(chat_id: int | str, question: str, options: Sequence[str], **kwargs: object) Message[source]ΒΆ
Sends poll through the bot API.
- Parameters:
chat_id β Identifier of the target chat.
question β Value used by this operation.
options β Value used by this operation.
- Returns:
Result produced by the bot operation.
- async edit_message_reply_markup(chat_id: int | str, message_id: int | str, **kwargs: object) Message[source]ΒΆ
Edits message reply markup through the bot API.
- Parameters:
chat_id β Identifier of the target chat.
message_id β Identifier of the target message.
- Returns:
Result produced by the bot operation.
- async delete_message(chat_id: int | str, message_id: int | str) bool[source]ΒΆ
Removes message through the bot API.
- Parameters:
chat_id β Identifier of the target chat.
message_id β Identifier of the target message.
- Returns:
Result produced by the bot operation.
- async forward_message(chat_id: int | str, from_chat_id: int | str, message_id: int | str) Message[source]ΒΆ
Performs the forward message operation for the bot client.
- Parameters:
chat_id β Identifier of the target chat.
from_chat_id β Value used by this operation.
message_id β Identifier of the target message.
- Returns:
Result produced by the bot operation.
- async send_media_group(chat_id: int | str, media: Sequence[object], **kwargs: object) list[Message][source]ΒΆ
Send a media group when the active platform advertises album support.
- async answer_callback_query(callback_query_id: str, *, text: str | None = None, show_alert: bool = False) bool[source]ΒΆ
Answers the callback query request through the bot API.
- Parameters:
callback_query_id β Identifier of the callback query.
text β Text content supplied to the operation.
show_alert β Value used by this operation.
- Returns:
Result produced by the bot operation.
- async send_chat_action(chat_id: int | str, action: str) bool[source]ΒΆ
Sends chat action through the bot API.
- Parameters:
chat_id β Identifier of the target chat.
action β Value used by this operation.
- Returns:
Result produced by the bot operation.
- async get_chat(chat_id: int | str) Chat[source]ΒΆ
Retrieves chat from the bot API.
- Parameters:
chat_id β Identifier of the target chat.
- Returns:
Result produced by the bot operation.
- async get_chat_member(chat_id: int | str, user_id: int) ChatMember[source]ΒΆ
Retrieves chat member from the bot API.
- Parameters:
chat_id β Identifier of the target chat.
user_id β Identifier of the target user.
- Returns:
Result produced by the bot operation.
- async ban_chat_member(chat_id: int | str, user_id: int) bool[source]ΒΆ
Performs the ban chat member operation for the bot client.
- Parameters:
chat_id β Identifier of the target chat.
user_id β Identifier of the target user.
- Returns:
Result produced by the bot operation.
Dispatcher and RouterΒΆ
- class peyk.dispatcher.dispatcher.Dispatcher(*, name: str | None = None, storage: BaseStorage | None = None, fsm_strategy: FSMStrategy | str = FSMStrategy.USER_IN_CHAT, events_isolation: BaseEventIsolation | None = None, **workflow_data: object)[source]ΒΆ
Bases:
RouterRoot router that feeds normalized updates from one or more bots.
The dispatcher owns polling tasks but deliberately delegates event matching to
Router; Phase 3 does not alter router matching semantics.- resolve_used_update_types() list[str][source]ΒΆ
Return the Telegram update types this dispatcher should receive.
Telegram remembers the
allowed_updateslast sent for a bot token, whether it came fromgetUpdates, fromsetWebhookor from a completely different program that used the same token earlier. If a new run does not send the parameter, the old filter silently stays in effect, so e.g.callback_queryandinline_queryupdates never arrive even though the handlers are registered. Peyk therefore always sends an explicit list.The list contains every update type Peyk can parse, except the three opt-in types Telegram does not deliver by default (
chat_member,message_reactionandmessage_reaction_count); those are added only when a router in the tree has a handler that needs them.- Returns:
Update type names in Telegramβs
allowed_updatesspelling.
- async feed_raw_update(bot: Bot[object], raw_update: object) object[source]ΒΆ
Normalize one raw update, inject dispatcher context, and propagate it.
- async start_polling(*bots: Bot[object], polling_timeout: int = 30, allowed_updates: Sequence[str] | None = None, skip_updates: bool = False, handle_signals: bool = True, close_bots: bool = True, handle_as_tasks: bool = False, max_concurrent_updates: int = 100) None[source]ΒΆ
Poll all supplied bots concurrently until stopped or cancelled.
- run_polling(*bots: Bot[object], **kwargs: object) None[source]ΒΆ
Run
start_polling()throughasyncio.run.
- async start_webhook(*bots: Bot[object], base_url: str, host: str = '0.0.0.0', port: int = 8080, path_prefix: str = '/webhook', secrets: Sequence[str] | None = None, ssl_context: object | None = None, allowed_updates: Sequence[str] | None = None, drop_pending_updates: bool = False, manage_registration: bool = True, delete_on_shutdown: bool = False, max_connections: int | None = None, handle_in_background: bool = True) None[source]ΒΆ
Serve Telegram, Bale and Rubika webhooks from one aiohttp app.
Each bot receives a non-token URL of
{path_prefix}/{platform}/{secret}. Rubikaβs confirmed inline endpoint is registered at the additional/inlinepath.
- run_webhook(*bots: Bot[object], **kwargs: object) None[source]ΒΆ
Run
start_webhook()throughasyncio.runfor Windows-safe automation.
- class peyk.dispatcher.router.Observer(router: Router, name: str)[source]ΒΆ
Bases:
objectHandler collection for one event type, with filters and middleware.
- register(handler: Callable[[P], R], *filters: object) Callable[[P], R][source]ΒΆ
Performs the register operation for the dispatcher client.
- Parameters:
handler β Value used by this operation.
- Returns:
Result produced by the dispatcher operation.
- filter(*filters: object) Observer[source]ΒΆ
Performs the filter operation for the dispatcher client.
- Returns:
Result produced by the dispatcher operation.
- middleware(middleware: BaseMiddleware) BaseMiddleware[source]ΒΆ
Performs the middleware operation for the dispatcher client.
- Parameters:
middleware β Value used by this operation.
- Returns:
Result produced by the dispatcher operation.
- outer_middleware(middleware: BaseMiddleware) BaseMiddleware[source]ΒΆ
Performs the outer middleware operation for the dispatcher client.
- Parameters:
middleware β Value used by this operation.
- Returns:
Result produced by the dispatcher operation.
- class peyk.dispatcher.router.Router(*, name: str | None = None)[source]ΒΆ
Bases:
objectAiogram-style first-match router with nested ordered subrouters.
- command(*names: str, prefix: str = '/') Callable[[Callable[[P], R]], Callable[[P], R]][source]ΒΆ
Register a message handler for one or more bot commands.
This is shorthand for
router.message(Command(name, prefix=prefix))and is available onRouter,Dispatcherand (throughBot.command()) on the botβs own router. Each alias is registered independently, so all of them share the same Python callable:@router.command("start", "help") async def start(message): ...
- include_router(router: Router) Router[source]ΒΆ
Performs the include router operation for the dispatcher client.
- Parameters:
router β Value used by this operation.
- Returns:
Result produced by the dispatcher operation.
- middleware(middleware: BaseMiddleware) BaseMiddleware[source]ΒΆ
Register outer whole-subtree middleware, preserving the D3 API.
- handler_middleware(middleware: BaseMiddleware) BaseMiddleware[source]ΒΆ
Register middleware that runs after handler flags have been injected.
- has_handlers() bool[source]ΒΆ
Performs the has handlers operation for the dispatcher client.
- Returns:
Result produced by the dispatcher operation.
- async propagate_platform_event(update: object, *, platform: str, **data: object) object[source]ΒΆ
Dispatch a native platform update and its named Telegram field observer.
platform_eventreceives the complete native update object. For Telegram, a named observer receives the native model stored in the correspondingUpdatefield; other platforms currently have no named-native observer surface.
TypesΒΆ
Neutral inbound bot objects and their bound actions.
- class peyk.types.core.User(id: int | str, is_bot: bool, first_name: str, last_name: str | None = None, username: str | None = None, language_code: str | None = None, raw: object = None)[source]ΒΆ
Bases:
objectPlatform-neutral user identity.
- id: int | strΒΆ
- is_bot: boolΒΆ
- first_name: strΒΆ
- last_name: str | None = NoneΒΆ
- username: str | None = NoneΒΆ
- language_code: str | None = NoneΒΆ
- raw: object = NoneΒΆ
- class peyk.types.core.Chat(id: int | str, type: ChatType, title: str | None = None, username: str | None = None, language_code: str | None = None, raw: object = None)[source]ΒΆ
Bases:
objectPlatform-neutral chat identity and display metadata.
- id: int | strΒΆ
- title: str | None = NoneΒΆ
- username: str | None = NoneΒΆ
- language_code: str | None = NoneΒΆ
- raw: object = NoneΒΆ
- class peyk.types.core.File(id: str, path: str | None = None, name: str | None = None, size: int | None = None, raw: object = None)[source]ΒΆ
Bases:
objectPlatform-neutral file descriptor returned by
Bot.get_file.- id: strΒΆ
- path: str | None = NoneΒΆ
- name: str | None = NoneΒΆ
- size: int | None = NoneΒΆ
- raw: object = NoneΒΆ
- class peyk.types.core.ChatMember(status: str, user: User | None = None, raw: object = None)[source]ΒΆ
Bases:
objectPlatform-neutral chat membership status.
- status: strΒΆ
- raw: object = NoneΒΆ
- class peyk.types.core.Message(message_id: Identifier | None = None, chat_id: Identifier | None = None, chat_type: str | None = None, sender_id: Identifier | None = None, text: str | None = None, date: int | None = None, is_edited: bool = False, update_kind: str = 'message', reply_to_message_id: Identifier | None = None, media: object = None, new_chat_members: list[Identifier] | None = None, left_chat_member: Identifier | None = None, successful_payment: object = None, raw: object = None, from_user: User | None = None, chat: Chat | None = None, content_type: ContentType = ContentType.UNKNOWN, bot: 'Bot' | None = None)[source]ΒΆ
Bases:
IncomingMessage,_BoundActionsNormalized message with a bound
peyk.Botaction surface.- content_type: ContentType = 'unknown'ΒΆ
- bot: 'Bot' | None = NoneΒΆ
- async answer(text: TextContent, **kwargs: object) Message[source]ΒΆ
Send a text message to this messageβs chat.
- async answer_photo(photo: object, *, caption: TextContent | None = None, **kwargs: object) Message[source]ΒΆ
Send a photo in this messageβs chat.
- async answer_video(video: object, *, caption: TextContent | None = None, **kwargs: object) Message[source]ΒΆ
Send a video in this messageβs chat.
- async answer_audio(audio: object, *, caption: TextContent | None = None, **kwargs: object) Message[source]ΒΆ
Send audio in this messageβs chat.
- async answer_voice(voice: object, *, caption: TextContent | None = None, **kwargs: object) Message[source]ΒΆ
Send a voice message in this messageβs chat.
- class peyk.types.core.CallbackQuery(id: str | None = None, from_user_id: Identifier | None = None, chat_id: Identifier | None = None, message_id: Identifier | None = None, inline_message_id: str | None = None, data: str | None = None, raw: object = None, from_user: User | None = None, message: Message | None = None, bot: 'Bot' | None = None)[source]ΒΆ
Bases:
IncomingCallbackQuery,_BoundActionsNormalized callback event with message actions when a message exists.
- bot: 'Bot' | None = NoneΒΆ
FiltersΒΆ
Aiogram-style platform-neutral filters.
- class peyk.filters.BaseFilter[source]ΒΆ
Bases:
ABCBase class for filters that may also contribute handler data.
- peyk.filters.and_f(*filters: object) BaseFilter[source]ΒΆ
Provides the and f operation for the peyk integration.
- Returns:
Result produced by the operation.
- peyk.filters.or_f(*filters: object) BaseFilter[source]ΒΆ
Provides the or f operation for the peyk integration.
- Returns:
Result produced by the operation.
- peyk.filters.invert_f(filter_: object) BaseFilter[source]ΒΆ
Provides the invert f operation for the peyk integration.
- Parameters:
filter β Value used by this operation.
- Returns:
Result produced by the operation.
- peyk.filters.normalize_filter(value: object) BaseFilter[source]ΒΆ
Provides the normalize filter operation for the peyk integration.
- Parameters:
value β Value used by this operation.
- Returns:
Result produced by the operation.
- class peyk.filters.Command(*values: str, prefix: str = '/', ignore_case: bool = False, ignore_mention: bool = False, magic: object | None = None)[source]ΒΆ
Bases:
BaseFilterMatch a command and expose its parsed
CommandObjectascommand.
- class peyk.filters.CommandStart(deep_link: bool = False, **kwargs: object)[source]ΒΆ
Bases:
CommandMatch the
/startcommand, optionally requiring deep-link arguments.
- class peyk.filters.CommandObject(prefix: str, command: str, mention: str | None = None, args: str | None = None, regexp_match: Match[str] | None = None, magic_result: object | None = None)[source]ΒΆ
Bases:
objectParsed command information supplied to a matching handler.
- args: str | None = NoneΒΆ
- magic_result: object | None = NoneΒΆ
- mention: str | None = NoneΒΆ
- regexp_match: Match[str] | None = NoneΒΆ
- prefix: strΒΆ
- command: strΒΆ
- class peyk.filters.CallbackData[source]ΒΆ
Bases:
BaseFilterDataclass-based callback-data factory compatible with aiogramβs model.
- classmethod filter(magic: object | None = None) BaseFilter[source]ΒΆ
Provides the filter operation for the peyk integration.
- Parameters:
magic β Value used by this operation.
- Returns:
Result produced by the operation.
- class peyk.filters.CallbackDataEquals(value: str)[source]ΒΆ
Bases:
BaseFilterMatch an exact callback-data string.
- class peyk.filters.CallbackDataStartsWith(prefix: str)[source]ΒΆ
Bases:
BaseFilterMatch callback data beginning with a prefix.
- class peyk.filters.ChatTypeFilter(*chat_types: ChatType | str)[source]ΒΆ
Bases:
BaseFilterMatch a neutral chat type, treating Telegram
supergroupas group.
- peyk.filters.ChatTypeΒΆ
alias of
ChatTypeFilter
- class peyk.filters.StateFilter(*states: State | type[StatesGroup] | str | None | Pattern[str], storage: BaseStorage | None = None, platform: str | None = None)[source]ΒΆ
Bases:
BaseFilterMatch
raw_stateinjected byFSMContextMiddleware.StateGroupvalues match any state in the group,re.Patternvalues usematch(),Nonematches the default empty state, andpeyk.fsm.state.any_statematches every state.
- class peyk.filters.MagicData(magic: object)[source]ΒΆ
Bases:
BaseFilterEvaluate a magic filter against dispatcher dependency data.
- class peyk.filters.ExceptionTypeFilter(*types: type[BaseException])[source]ΒΆ
Bases:
BaseFilterMatch an
ErrorEventby exception type.
- class peyk.filters.ExceptionMessageFilter(message: str, *, contains: bool = False)[source]ΒΆ
Bases:
BaseFilterMatch an
ErrorEventby exception message.
- class peyk.filters.PlatformFilter(*platforms: str)[source]ΒΆ
Bases:
BaseFilterMatch events handled by one of the named platforms.
- class peyk.filters.SupportsFilter(feature: Feature)[source]ΒΆ
Bases:
BaseFilterMatch when the injected bot advertises audited support for a feature.
- class peyk.filters.TextEquals(value: str, case_sensitive: bool = True)[source]ΒΆ
Bases:
BaseFilterMatch a message whose text equals
value.
- class peyk.filters.TextContains(value: str, case_sensitive: bool = True)[source]ΒΆ
Bases:
BaseFilterMatch a message containing
value.
KeyboardΒΆ
- class peyk.keyboard.builder.InlineKeyboardBuilder[source]ΒΆ
Bases:
_Builder[InlineButton]Build an inline keyboard without selecting a platform.
- button(**fields: object) InlineKeyboardBuilder[source]ΒΆ
Performs the button operation for the keyboard client.
- Returns:
Result produced by the keyboard operation.
- as_markup(**options: object) InlineKeyboard[source]ΒΆ
Performs the as markup operation for the keyboard client.
- Returns:
Result produced by the keyboard operation.
- classmethod from_markup(markup: InlineKeyboard) InlineKeyboardBuilder[source]ΒΆ
Performs the from markup operation for the keyboard client.
- Parameters:
markup β Value used by this operation.
- Returns:
Result produced by the keyboard operation.
- class peyk.keyboard.builder.ReplyKeyboardBuilder[source]ΒΆ
Bases:
_Builder[ReplyButton]Build a reply keyboard without selecting a platform.
- button(**fields: object) ReplyKeyboardBuilder[source]ΒΆ
Performs the button operation for the keyboard client.
- Returns:
Result produced by the keyboard operation.
- as_markup(**options: object) ReplyKeyboard[source]ΒΆ
Performs the as markup operation for the keyboard client.
- Returns:
Result produced by the keyboard operation.
- classmethod from_markup(markup: ReplyKeyboard) ReplyKeyboardBuilder[source]ΒΆ
Performs the from markup operation for the keyboard client.
- Parameters:
markup β Value used by this operation.
- Returns:
Result produced by the keyboard operation.
FormattingΒΆ
aiogram-style composable formatting built on Peykβs RichText IR.
The composition objects are platform-neutral. Rendering happens only when a target platform is known, so application code does not carry platform names.
- class peyk.formatting.Text(*body: str | RichText | Text, sep: str = '')[source]ΒΆ
Bases:
objectA composable sequence of text fragments and formatting nodes.
- bold(*body: str | RichText | Text) Text[source]ΒΆ
Append a bold fragment and return a new composition.
- italic(*body: str | RichText | Text) Text[source]ΒΆ
Append an italic fragment and return a new composition.
- underline(*body: str | RichText | Text) Text[source]ΒΆ
Append an underlined fragment and return a new composition.
- strikethrough(*body: str | RichText | Text) Text[source]ΒΆ
Append a strikethrough fragment and return a new composition.
- spoiler(*body: str | RichText | Text) Text[source]ΒΆ
Append a spoiler fragment and return a new composition.
- code(*body: str | RichText | Text) Text[source]ΒΆ
Append an inline-code fragment and return a new composition.
- pre(*body: str | RichText | Text, language: str | None = None) Text[source]ΒΆ
Append a preformatted fragment and return a new composition.
- link(text: str | RichText | Text, url: str) Text[source]ΒΆ
Append a URL link and return a new composition.
- mention(text: str | RichText | Text, user_id: int | str) Text[source]ΒΆ
Append a Telegram user mention and return a new composition.
- blockquote(*body: str | RichText | Text) Text[source]ΒΆ
Append a block quote and return a new composition.
- expandable_blockquote(*body: str | RichText | Text) Text[source]ΒΆ
Append an expandable block quote and return a new composition.
- render(target: PlatformCapabilities | str) str[source]ΒΆ
Render this composition for a platform or audited capability object.
- as_kwargs(target: PlatformCapabilities | str) dict[str, object][source]ΒΆ
Return the exact text-bearing keyword arguments for
target.
- class peyk.formatting.Bold(*body: str | RichText | Text, sep: str = '')[source]ΒΆ
Bases:
TextRender children in bold.
- class peyk.formatting.Italic(*body: str | RichText | Text, sep: str = '')[source]ΒΆ
Bases:
TextRender children in italics.
- class peyk.formatting.Underline(*body: str | RichText | Text, sep: str = '')[source]ΒΆ
Bases:
TextRender children with an underline where the target supports it.
- class peyk.formatting.Strikethrough(*body: str | RichText | Text, sep: str = '')[source]ΒΆ
Bases:
TextRender children with a strikethrough where the target supports it.
- class peyk.formatting.Spoiler(*body: str | RichText | Text, sep: str = '')[source]ΒΆ
Bases:
TextRender children as a spoiler where the target supports it.
- class peyk.formatting.Code(*body: str | RichText | Text, sep: str = '')[source]ΒΆ
Bases:
TextRender children as inline code.
- class peyk.formatting.Pre(*body: str | RichText | Text, language: str | None = None)[source]ΒΆ
Bases:
TextRender children as a preformatted block.
- language: str | NoneΒΆ
- class peyk.formatting.TextLink(*body: str | RichText | Text, url: str)[source]ΒΆ
Bases:
TextRender children as a URL link.
- url: strΒΆ
- class peyk.formatting.TextMention(*body: str | RichText | Text, user_id: int | str)[source]ΒΆ
Bases:
TextRender children as a Telegram user mention.
- user_id: int | strΒΆ
- class peyk.formatting.BlockQuote(*body: str | RichText | Text, sep: str = '')[source]ΒΆ
Bases:
TextRender children as a block quote.
- class peyk.formatting.ExpandableBlockQuote(*body: str | RichText | Text, sep: str = '')[source]ΒΆ
Bases:
TextRender children as an expandable block quote.
- peyk.formatting.as_line(*items: str | RichText | Text, sep: str = ' ') Text[source]ΒΆ
Join items on one line.
- peyk.formatting.as_list(*items: str | RichText | Text | Iterable[str | RichText | Text], sep: str = '\n') Text[source]ΒΆ
Join items as a list separated by
sep; one iterable is also accepted.
- peyk.formatting.as_marked_list(*items: str | ~peyk.utils.text_formatting.RichText | ~peyk.formatting.Text | ~typing.Iterable[str | ~peyk.utils.text_formatting.RichText | ~peyk.formatting.Text], marker: str = 'β«οΈ', se, sep: str = ) ->) Text[source]ΒΆ
Prefix each item with
marker.
- peyk.formatting.as_numbered_list(*items: str | RichText | Text | Iterable[str | RichText | Text], sep: str = '\n') Text[source]ΒΆ
Prefix each item with its one-based position.
- peyk.formatting.as_section(title: str | RichText | Text, *body: str | RichText | Text, sep: str = '\n') Text[source]ΒΆ
Return a title followed by body lines.
- peyk.formatting.as_marked_section(title: str | ~peyk.utils.text_formatting.RichText | ~peyk.formatting.Text, *body: str | ~peyk.utils.text_formatting.RichText | ~peyk.formatting.Text, marker: str = 'β«οΈ', se, sep: str = ) ->) Text[source]ΒΆ
Return a title followed by a marked list.
- peyk.formatting.as_key_value(key: str | RichText | Text, value: str | RichText | Text, sep: str = ': ') Text[source]ΒΆ
Join a key and value with
sep.
- peyk.formatting.resolve_text(content: str | RichText | Text, platform_caps: PlatformCapabilities, policy: UnsupportedPolicy, defaults: TextDefaults) tuple[str, dict[str, object]][source]ΒΆ
Resolve text once at send time into target text and native keyword arguments.
Plain strings remain plain unless a default parse mode is configured. Rich compositions are rendered from the neutral IR; Rubika additionally receives its structured metadata. Explicit parse-mode handling is applied by
peyk.Botbefore this resolver is called.
- class peyk.formatting.TextDefaults(*args, **kwargs)[source]ΒΆ
Bases:
ProtocolMinimal defaults contract required by
resolve_text().
- peyk.formatting.bold(text: str | RichText) RichText[source]ΒΆ
Performs the bold operation for the utility client.
- Parameters:
text β Text content supplied to the operation.
- Returns:
Result produced by the utility operation.
- peyk.formatting.italic(text: str | RichText) RichText[source]ΒΆ
Performs the italic operation for the utility client.
- Parameters:
text β Text content supplied to the operation.
- Returns:
Result produced by the utility operation.
- peyk.formatting.underline(text: str | RichText) RichText[source]ΒΆ
Performs the underline operation for the utility client.
- Parameters:
text β Text content supplied to the operation.
- Returns:
Result produced by the utility operation.
- peyk.formatting.strikethrough(text: str | RichText) RichText[source]ΒΆ
Performs the strikethrough operation for the utility client.
- Parameters:
text β Text content supplied to the operation.
- Returns:
Result produced by the utility operation.
- peyk.formatting.spoiler(text: str | RichText) RichText[source]ΒΆ
Performs the spoiler operation for the utility client.
- Parameters:
text β Text content supplied to the operation.
- Returns:
Result produced by the utility operation.
- peyk.formatting.code(text: str | RichText) RichText[source]ΒΆ
Performs the code operation for the utility client.
- Parameters:
text β Text content supplied to the operation.
- Returns:
Result produced by the utility operation.
- peyk.formatting.pre(text: str | RichText, language: str | None = None) RichText[source]ΒΆ
Performs the pre operation for the utility client.
- Parameters:
text β Text content supplied to the operation.
language β Value used by this operation.
- Returns:
Result produced by the utility operation.
- peyk.formatting.link(text: str | RichText, url: str) RichText[source]ΒΆ
Performs the link operation for the utility client.
- Parameters:
text β Text content supplied to the operation.
url β Target URL.
- Returns:
Result produced by the utility operation.
- peyk.formatting.mention_user(text: str | RichText, user_id: int | str) RichText[source]ΒΆ
Performs the mention user operation for the utility client.
- Parameters:
text β Text content supplied to the operation.
user_id β Identifier of the target user.
- Returns:
Result produced by the utility operation.
- peyk.formatting.mention_username(text: str | RichText, username: str) RichText[source]ΒΆ
Performs the mention username operation for the utility client.
- Parameters:
text β Text content supplied to the operation.
username β Value used by this operation.
- Returns:
Result produced by the utility operation.
- peyk.formatting.bale_expandable(title: str, text: str | RichText) RichText[source]ΒΆ
Performs the bale expandable operation for the utility client.
- Parameters:
title β Title to apply to the target resource.
text β Text content supplied to the operation.
- Returns:
Result produced by the utility operation.
WebhookΒΆ
- class peyk.webhook.IPFilter(networks: Sequence[str], *, trust_forwarded_for: bool = False)[source]ΒΆ
Bases:
objectAllow webhook requests only when their source IP is in configured networks.
trust_forwarded_foris deliberately opt-in. When disabled, only the transport peer address is considered, so an untrusted client cannot choose its own address throughX-Forwarded-For.
- class peyk.webhook.WebhookOptions(allowed_updates: list[str] | None = None, drop_pending_updates: bool = False, max_connections: int | None = None)[source]ΒΆ
Bases:
objectPlatform-neutral webhook registration options.
- allowed_updates: list[str] | None = NoneΒΆ
- drop_pending_updates: bool = FalseΒΆ
- max_connections: int | None = NoneΒΆ
- class peyk.webhook.WebhookProcessor(dispatcher: object, *, secret: str | None = None, max_body_size: int = MAX_DEFAULT_BODY_SIZE, handle_in_background: bool = True, endpoint_type: str | None = None)[source]ΒΆ
Bases:
objectParse and dispatch webhook requests without depending on an HTTP server.
- async handle(bot: Bot[object], body: bytes, headers: Mapping[str, str]) WebhookResult[source]ΒΆ
Verify, parse and dispatch one webhook request.
Malformed JSON and oversized bodies are rejected. Authentication failures return the same 404 used by route failures so callers cannot distinguish a secret oracle from an absent endpoint.
- class peyk.webhook.WebhookRegistrar(*args, **kwargs)[source]ΒΆ
Bases:
ProtocolRegister and remove a webhook for one platform.
- async install(bot: Bot[object], url: str, secret: str, options: WebhookOptions) None[source]ΒΆ
Provides the install operation for the peyk integration.
- Parameters:
bot β Value used by this operation.
url β Value used by this operation.
secret β Value used by this operation.
options β Value used by this operation.
- class peyk.webhook.WebhookResult(status: int, body: bytes | None = None)[source]ΒΆ
Bases:
objectHTTP result returned by a webhook processor.
- body: bytes | None = NoneΒΆ
- status: intΒΆ
- peyk.webhook.constant_time_compare(a: str | None, b: str | None) bool[source]ΒΆ
Compare two non-empty strings without ordinary early-exit timing.
- peyk.webhook.registrar_for(bot: Bot[object]) WebhookRegistrar[source]ΒΆ
Return the audited registrar for
bot.platform.
FSMΒΆ
Finite-state conversation support for Peyk.
- class peyk.fsm.BaseEventIsolation[source]ΒΆ
Bases:
objectSerialize handlers that share one
StorageKey.- lock(key: StorageKey) AsyncIterator[None][source]ΒΆ
Return an async context manager for the event lock.
- class peyk.fsm.BaseStorage(*, key_builder: KeyBuilder | None = None)[source]ΒΆ
Bases:
ABCAbstract asynchronous FSM storage keyed by
StorageKey.- abstractmethod async get_data(key: StorageKey | str) dict[str, object][source]ΒΆ
Retrieves data from the FSM API.
- Parameters:
key β Value used by this operation.
- Returns:
Result produced by the FSM operation.
- abstractmethod async get_state(key: StorageKey | str) str | None[source]ΒΆ
Retrieves state from the FSM API.
- Parameters:
key β Value used by this operation.
- Returns:
Result produced by the FSM operation.
- abstractmethod async set_data(key: StorageKey | str, data: Mapping[str, object]) None[source]ΒΆ
Updates data through the FSM API.
- Parameters:
key β Value used by this operation.
data β Value used by this operation.
- abstractmethod async set_state(key: StorageKey | str, state: str | None) None[source]ΒΆ
Updates state through the FSM API.
- Parameters:
key β Value used by this operation.
state β Value used by this operation.
- abstractmethod async update_data(key: StorageKey | str, data: Mapping[str, object] | None = None, **kwargs: object) dict[str, object][source]ΒΆ
Performs the update data operation for the FSM client.
- Parameters:
key β Value used by this operation.
data β Value used by this operation.
- Returns:
Result produced by the FSM operation.
- peyk.fsm.build_storage_key(event: object, *, platform: str, bot_id: int | str, strategy: str | FSMStrategy = FSMStrategy.USER_IN_CHAT, destiny: str = 'default') StorageKey[source]ΒΆ
Build a platform/bot-aware key from a normalized event.
- peyk.fsm.conversation_key(event: object, *, platform: str | None = None, bot_id: int | str | None = None) StorageKey[source]ΒΆ
Return a compatibility
StorageKeyfor an event.The old form inferred the platform from
event.rawand had no bot ID. That form is deprecated; dispatcher integrations must pass both values.
- class peyk.fsm.DefaultKeyBuilder(prefix: str = 'peyk', separator: str = ':', with_bot_id: bool = True, with_destiny: bool = True)[source]ΒΆ
Bases:
objectBuild aiogram-shaped FSM keys with platform and bot namespaces.
The default is equivalent to aiogramβs
with_bot_id=Trueplus the additional platform segment required by Peykβs multi-platform contract.- prefix: strΒΆ
- separator: strΒΆ
- with_bot_id: boolΒΆ
- with_destiny: boolΒΆ
- build(key: StorageKey, part: str | None = None) str[source]ΒΆ
Performs the build operation for the FSM client.
- Parameters:
key β Value used by this operation.
part β Value used by this operation.
- Returns:
Result produced by the FSM operation.
- class peyk.fsm.DisabledEventIsolation[source]ΒΆ
Bases:
BaseEventIsolationDo not serialize events.
- lock(key: StorageKey) AsyncIterator[None][source]ΒΆ
Performs the lock operation for the FSM client.
- Parameters:
key β Value used by this operation.
- Returns:
Result produced by the FSM operation.
- class peyk.fsm.FSMContext(storage: BaseStorage, key: StorageKey)[source]ΒΆ
- class peyk.fsm.FSMContext(event: object, storage: BaseStorage | LegacyStringStorage, *, platform: str | None = None, bot_id: int | str | None = None)
Bases:
objectRead and mutate state/data for one
StorageKey.- classmethod for_event(event: object, storage: BaseStorage, *, platform: str, bot_id: int | str, strategy: str | FSMStrategy = FSMStrategy.USER_IN_CHAT, destiny: str = 'default') FSMContext[source]ΒΆ
Create a context for a normalized event using explicit identity data.
- class peyk.fsm.FSMStrategy(*values)[source]ΒΆ
Bases:
str,EnumSelect which event identities share one FSM conversation.
- USER_IN_CHAT = 'USER_IN_CHAT'ΒΆ
- CHAT = 'CHAT'ΒΆ
- GLOBAL_USER = 'GLOBAL_USER'ΒΆ
- class peyk.fsm.KeyBuilder(*args, **kwargs)[source]ΒΆ
Bases:
ProtocolBuild backend keys from a
StorageKey.- build(key: StorageKey, part: str | None = None) str[source]ΒΆ
Performs the build operation for the FSM client.
- Parameters:
key β Value used by this operation.
part β Value used by this operation.
- Returns:
Result produced by the FSM operation.
- class peyk.fsm.LegacyStorageAdapter(storage: LegacyStringStorage, *, key_builder: KeyBuilder | None = None)[source]ΒΆ
Bases:
BaseStorageAdapt the pre-Phase-8 string-key storage API to
StorageKey.- async get_data(key: StorageKey | str) dict[str, object][source]ΒΆ
Retrieves data from the FSM API.
- Parameters:
key β Value used by this operation.
- Returns:
Result produced by the FSM operation.
- async get_state(key: StorageKey | str) str | None[source]ΒΆ
Retrieves state from the FSM API.
- Parameters:
key β Value used by this operation.
- Returns:
Result produced by the FSM operation.
- async set_data(key: StorageKey | str, data: Mapping[str, object]) None[source]ΒΆ
Updates data through the FSM API.
- Parameters:
key β Value used by this operation.
data β Value used by this operation.
- async set_state(key: StorageKey | str, state: str | None) None[source]ΒΆ
Updates state through the FSM API.
- Parameters:
key β Value used by this operation.
state β Value used by this operation.
- async update_data(key: StorageKey | str, data: Mapping[str, object] | None = None, **kwargs: object) dict[str, object][source]ΒΆ
Performs the update data operation for the FSM client.
- Parameters:
key β Value used by this operation.
data β Value used by this operation.
- Returns:
Result produced by the FSM operation.
- class peyk.fsm.LegacyStringStorage(*args, **kwargs)[source]ΒΆ
Bases:
ProtocolProtocol for the pre-Phase-8 string-key storage API.
- async get_data(key: str) dict[str, object][source]ΒΆ
Retrieves data from the FSM API.
- Parameters:
key β Value used by this operation.
- Returns:
Result produced by the FSM operation.
- async get_state(key: str) str | None[source]ΒΆ
Retrieves state from the FSM API.
- Parameters:
key β Value used by this operation.
- Returns:
Result produced by the FSM operation.
- async set_data(key: str, data: Mapping[str, object]) None[source]ΒΆ
Updates data through the FSM API.
- Parameters:
key β Value used by this operation.
data β Value used by this operation.
- class peyk.fsm.MemoryStorage(*, key_builder: KeyBuilder | None = None)[source]ΒΆ
Bases:
BaseStorageStore FSM state and data in process memory.
- async get_data(key: StorageKey | str) dict[str, object][source]ΒΆ
Return a defensive copy of conversation data.
- async get_state(key: StorageKey | str) str | None[source]ΒΆ
Return the stored state for
key.
- async set_data(key: StorageKey | str, data: Mapping[str, object]) None[source]ΒΆ
Replace conversation data with a defensive copy.
- async set_state(key: StorageKey | str, state: str | None) None[source]ΒΆ
Set or clear the stored state.
- async update_data(key: StorageKey | str, data: Mapping[str, object] | None = None, **kwargs: object) dict[str, object][source]ΒΆ
Merge mapping and keyword values into conversation data.
- class peyk.fsm.RedisEventIsolation(redis: RedisLockClient, *, key_builder: KeyBuilder | None = None, lock_timeout: float | None = 30.0, blocking_timeout: float | None = None)[source]ΒΆ
Bases:
BaseEventIsolationSerialize events using Redis distributed locks.
- lock(key: StorageKey) AsyncIterator[None][source]ΒΆ
Performs the lock operation for the FSM client.
- Parameters:
key β Value used by this operation.
- Returns:
Result produced by the FSM operation.
- class peyk.fsm.RedisStorage(redis: AsyncRedisClient | None = None, *, state_ttl: int | float | None = None, data_ttl: int | float | None = None, key_builder: KeyBuilder | None = None, url: str | None = None, prefix: str | None = None)[source]ΒΆ
Bases:
BaseStoragePersist FSM state/data in Redis with independent optional TTLs.
- async get_data(key: StorageKey | str) dict[str, object][source]ΒΆ
Decode JSON conversation data from Redis.
- async get_state(key: StorageKey | str) str | None[source]ΒΆ
Return a stored state string, if present.
- async set_data(key: StorageKey | str, data: Mapping[str, object]) None[source]ΒΆ
Replace JSON conversation data and apply
data_ttl.
- async set_state(key: StorageKey | str, state: str | None) None[source]ΒΆ
Set or clear state, applying
state_ttlwhen configured.
- async update_data(key: StorageKey | str, data: Mapping[str, object] | None = None, **kwargs: object) dict[str, object][source]ΒΆ
Read, merge and persist conversation data.
- class peyk.fsm.SimpleEventIsolation[source]ΒΆ
Bases:
BaseEventIsolationSerialize by key and evict idle locks after release.
- lock(key: StorageKey) AsyncIterator[None][source]ΒΆ
Performs the lock operation for the FSM client.
- Parameters:
key β Value used by this operation.
- Returns:
Result produced by the FSM operation.
- class peyk.fsm.State(state: str | None = None, group_name: str | None = None)[source]ΒΆ
Bases:
objectDescribe one named FSM state, optionally with an explicit group name.
- property group: type[StatesGroup]ΒΆ
Return the owning state-group class.
- set_parent(group: type[StatesGroup]) None[source]ΒΆ
Bind this state to a
StatesGroupclass.
- property state: str | NoneΒΆ
Return the fully-qualified state name.
- class peyk.fsm.StatesGroup[source]ΒΆ
Bases:
objectBase class for declarative FSM state groups.
- classmethod get_root() type[StatesGroup][source]ΒΆ
Return the root group for a nested group.
- class peyk.fsm.StorageKey(platform: str, bot_id: int | str, chat_id: int | str | None, user_id: int | str | None, destiny: str = 'default')[source]ΒΆ
Bases:
objectIdentify one FSM namespace without embedding a bot token.
platformis deliberately part of the identity so equal numeric IDs on Telegram and Bale cannot share state.bot_idisolates two bots on the same platform.- platform: strΒΆ
- bot_id: int | strΒΆ
- chat_id: int | str | NoneΒΆ
- user_id: int | str | NoneΒΆ
- destiny: strΒΆ
FlagsΒΆ
- class peyk.flags.FlagDecorator(name: str, value: object)[source]ΒΆ
Bases:
objectFlagDecorator defines a public API type for peyk.
- name: strΒΆ
- value: objectΒΆ
- class peyk.flags.Flags[source]ΒΆ
Bases:
objectFactory for handler flags used by dispatcher middleware.
UtilitiesΒΆ
- class peyk.utils.I18n(path: str | Path, default_locale: str = 'fa', domain: str = 'messages')[source]ΒΆ
Bases:
objectLoad GNU gettext catalogs and provide aiogram-style translation helpers.
- gettext(message: str, locale: str | None = None) str[source]ΒΆ
Performs the gettext operation for the utility client.
- Parameters:
message β Value used by this operation.
locale β Locale used for translation lookup.
- Returns:
Result produced by the utility operation.
- lazy_gettext(message: str, locale: str | None = None) LazyText[source]ΒΆ
Performs the lazy gettext operation for the utility client.
- Parameters:
message β Value used by this operation.
locale β Locale used for translation lookup.
- Returns:
Result produced by the utility operation.
- ngettext(singular: str, plural: str, n: int, locale: str | None = None) str[source]ΒΆ
Performs the ngettext operation for the utility client.
- Parameters:
singular β Value used by this operation.
plural β Value used by this operation.
n β Value used by this operation.
locale β Locale used for translation lookup.
- Returns:
Result produced by the utility operation.
- class peyk.utils.I18nMiddleware(i18n: I18n, get_locale: Callable[[object, Mapping[str, object]], str] | None = None)[source]ΒΆ
Bases:
objectInject
i18n,localeand translation callables into dispatcher DI.
- class peyk.utils.LazyText(resolver: Callable[[], str])[source]ΒΆ
Bases:
objectLazyText provides the utility API surface used by peyk.
- class peyk.utils.MediaGroupBuilder(items: list[~peyk.utils.media_group.T] = <factory>)[source]ΒΆ
Bases:
Generic[T]Collect media items for a platform-supported media group.
- add(media: T) MediaGroupBuilder[T][source]ΒΆ
Performs the add operation for the utility client.
- Parameters:
media β Value used by this operation.
- Returns:
Result produced by the utility operation.
- build() list[T][source]ΒΆ
Performs the build operation for the utility client.
- Returns:
Result produced by the utility operation.
- items: list[T]ΒΆ
- peyk.utils.check_webapp_signature(init_data: str, bot_token: str) bool[source]ΒΆ
Validate Telegram Web App init data according to the documented HMAC scheme.
- peyk.utils.safe_parse_webapp_init_data(init_data: str, bot_token: str) dict[str, str][source]ΒΆ
Validate and parse Telegram Web App init data.
- peyk.utils.encode_payload(payload: str | bytes) str[source]ΒΆ
Encode UTF-8 payload using unpadded URL-safe base64.