Skip to content

meshya/aiogram-sqlalchemy-storage

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

17 Commits
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

SQLAlchemyStorage for aiogram FSM

GitHub Actions Workflow Status

PyPI - License

PyPI - Version

PyPI - Wheel

Overview

SQLAlchemyStorage is a storage backend for aiogram's finite state machine (FSM) using SQLAlchemy. It provides an efficient and flexible way to persist FSM state and data using an asynchronous database session.

Installation

Use pip to install in your environment:

pip install aiogram-sqlalchemy-storage

Quick Start

from sqlalchemy.ext.asyncio import AsyncSession, create_async_engine, async_sessionmaker
from sqlalchemy.orm import declarative_base
from sqlalchemy_storage import SQLAlchemyStorage
from aiogram import Bot, Dispatcher

# Setup database
engine = create_async_engine("sqlite+aiosqlite:///database.db")
SessionLocal = async_sessionmaker(bind=engine, class_=AsyncSession, expire_on_commit=False)
Base = declarative_base()

# Initialize storage
storage = SQLAlchemyStorage(sessionmaker=SessionLocal, metadata=Base.metadata)

# Setup bot
bot = Bot(token="YOUR_BOT_TOKEN")
dp = Dispatcher(storage=storage)

Features

  • Asynchronous support with AsyncSession
  • Customizable table name for storing FSM data
  • Pluggable key-building strategy
  • JSON serialization customization

Documentation

For detailed documentation, configuration options, and advanced usage, see:

Change Log

License

MIT License

Contributions

Contributions are welcome! Feel free to submit issues or pull requests on the repository.

About

A fsm storage based on sqlalchemy

Resources

License

Stars

Watchers

Forks

Packages

No packages published

Languages