peyk.fsm.storage¶
FSM storage backends and event isolation.
- class peyk.fsm.storage.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.storage.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.
- class peyk.fsm.storage.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.storage.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.storage.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.storage.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.storage.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.storage.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.storage.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.storage.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.storage.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.storage.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¶
Modules