StateManager - fsm for people
Convenient FSM implementation for telegram/vk
Installation
Supports python3.8+
Library only
pip install state-manager
Library and vkwave
pip install state-manager[vk]
Library and aiogram
pip install state-manager[telegram]
Full installation
pip install state-manager[full]
Examples
from vkwave.bots import SimpleLongPollBot
import logging
from state_manager import VkWaveMainRouter, VkWaveStateManager
logging.basicConfig(level=logging.INFO)
bot = SimpleLongPollBot(tokens="your token", group_id=123123,)
main_state = VkWaveMainRouter(bot)
@main_state.message_handler()
async def home(event: bot.SimpleBotEvent, state_manager: VkWaveStateManager):
await event.answer("go to home2")
await state_manager.set_next_state("home2")
@main_state.message_handler()
async def home2(event: bot.SimpleBotEvent, state_manager: VkWaveStateManager):
await event.answer("go to home")
await state_manager.back_to_pre_state()
main_state.install()
bot.run_forever(ignore_errors=True)
import logging
from aiogram import Bot, Dispatcher, executor, types
from state_manager import AiogramStateManager
from state_manager.routes.aiogram import AiogramMainRouter
logging.basicConfig(level=logging.INFO)
bot = Bot(token='your token')
dp = Dispatcher(bot)
main_state = AiogramMainRouter(dp)
main_state.install()
@main_state.message_handler()
async def home(msg: types.Message, state_manager: AiogramStateManager):
await msg.answer("go to home2")
await state_manager.set_next_state("home2")
@main_state.message_handler()
async def home2(msg: types.Message, state_manager: AiogramStateManager):
await msg.answer("go to home")
await state_manager.set_next_state("home")
executor.start_polling(dp, skip_updates=True)
Storage
The library currently supports:
- RedisStorage
- MemoryStorage
If you do not pass arguments to install, Redis Storage is used, which takes the settings from env.
Settings:
- storage_dsn, default: "redis://localhost:6379"
- storage_ssl, default: None
- storage_db: default: None
- pool_size: default: 10
- storage_timeout: default: 5
Filters
The library supports out of the box:
- text_filter
- text_contains_filter
- regex_filter
You can also write your filters. aiogram, vkwave
Architecture
Search state in routers
Router architecture
Metadata
Release files for state-manager 0.2.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| state_manager-0.2.0.tar.gz | 13.3 kB | Without provenance | Details for state_manager-0.2.0.tar.gz |
Release files / state_manager-0.2.0.tar.gz
| Download URL | state_manager-0.2.0.tar.gz |
|---|---|
| Size | 13.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
3d0d4b6b3bfa3a9dea6d329febe35d4be6162f658cdc232807ec5281c79c9bba
|
|
BLAKE2b-256 checksum How to use checksums |
a314b5dcbf35233a75259567ee0671b72fa7f4c129e9d5bdaac6364997a9f6fe
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.2.0 pkginfo/1.5.0.1 requests/2.24.0 setuptools/47.1.0 requests-toolbelt/0.9.1 tqdm/4.48.2 CPython/3.7.8
|
Security for state-manager 0.2.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.