FSM Storage for YDB (Yandex Database)
Project description
aiogram YDB Storage
aiogram_ydb_storage
is a storage implementation for aiogram FSM
that utilizes Yandex Database (YDB) as the storage backend. This allows you to persist state data for state machines used in your Telegram bots.
Installation
You can install aiogram_ydb_storage
via pip:
pip install aiogram_ydb_storage
Usage
To use aiogram_ydb_storage
, you need to first set up your YDB database and obtain necessary credentials. Then, you can use it in conjunction with aiogram
as follows:
import asyncio
from aiogram import Bot, Dispatcher, types
from aiogram.filters import CommandStart
from aiogram.types import Message
from aiogram.fsm.context import FSMContext
from aiogram.fsm.state import StatesGroup, State
import ydb
from aiogram_ydb_storage import YDBStorage
# Configure YDB driver
driver_config = ydb.DriverConfig(
"grpcs://...", # YDB endpoint
"...", # Database name
credentials=ydb.credentials_from_env_variables(), # Use YDB credentials from environment
)
# Initialize YDBStorage
my_storage = YDBStorage(driver_config=driver_config)
# Initialize aiogram Bot and Dispatcher
dp = Dispatcher(storage=my_storage)
bot = Bot("token")
# Define your states
class MyStates(StatesGroup):
test1 = State()
test2 = State()
# Handlers
@dp.message(CommandStart())
async def command_start_handler(message: Message, state: FSMContext) -> None:
await state.set_state(MyStates.test1)
await message.answer("Set state test1")
@dp.message(MyStates.test1)
async def handler(message: types.Message, state: FSMContext) -> None:
await message.answer("state test1. Set state test2")
await state.set_state(MyStates.test2)
@dp.message()
async def echo_handler(message: types.Message, state: FSMContext) -> None:
await message.answer("not state test1. Set state test1")
await state.set_state(MyStates.test1)
# Main function
async def main() -> None:
await dp.start_polling(bot)
# Run the main function
if __name__ == "__main__":
asyncio.run(main())
Contributing
Contributions are welcome! Please feel free to submit issues or pull requests.
License
This project is licensed under the MIT License - see the LICENSE file for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file aiogram_ydb_storage-0.1.0.tar.gz
.
File metadata
- Download URL: aiogram_ydb_storage-0.1.0.tar.gz
- Upload date:
- Size: 4.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.12.1 Windows/11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a01fac447b45a87d613847ced129dab121003366ab9784502682acc9dfe8145 |
|
MD5 | bc04af1bcdfe864176f7b2ac9e1abb48 |
|
BLAKE2b-256 | d839077752d9c84087a766fc9148b8aed4f799be8576b63dcbc928374e60ce76 |
File details
Details for the file aiogram_ydb_storage-0.1.0-py3-none-any.whl
.
File metadata
- Download URL: aiogram_ydb_storage-0.1.0-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.6.1 CPython/3.12.1 Windows/11
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 55a5e95c5ea194f17c4aae1924963c519d34dca5a512008ad209dc5362236058 |
|
MD5 | 3d8679b60bc0daae9e08fb09b6338d56 |
|
BLAKE2b-256 | 44319c9ee4a235fe264fb7f287048b1d375099b097ee8795282b7e5429936626 |