Helper for add transitions functionality in sqlalchemy
Project description
sqlalchemy-state-machine ==
[![ci](https://github.com/bigbag/sqlalchemy-state-machine/workflows/CI/badge.svg)](https://github.com/bigbag/sqlalchemy-state-machine/actions?query=workflow%3ACI) [![pypi](https://img.shields.io/pypi/v/sqlalchemy-state-machine.svg)](https://pypi.python.org/pypi/sqlalchemy-state-machine)
sqlalchemy-state-machine is a helper for add transitions functionality in sqlalchemy.
Installation
sqlalchemy-state-machine is available on PyPI. Use pip to install:
$ pip install sqlalchemy-state-machine
Basic Usage
import sqlalchemy as sa
from sqlalchemy.ext.declarative import declarative_base
from sqlalchemy_state_machine import StateConfig, StateMixin
Base = declarative_base()
NEW = "new"
SENT = "sent"
FAILED = "failed"
class Event(Base, StateMixin):
__tablename__ = "users"
state_config = StateConfig(
initial=NEW,
states=[NEW, SENT, FAILED],
transitions=[
["set_sent", NEW, SENT],
["set_failed", NEW, FAILED],
],
)
id = sa.Column(sa.Integer, primary_key=True)
name = sa.Column(sa.String)
status = sa.Column(sa.String(), nullable=False, index=True)
sa.event.listen(Event, "init", Event.init_state_machine)
sa.event.listen(Event, "load", Event.init_state_machine)
event = Event(name="Event1")
event.set_sent()
License
sqlalchemy-state-machine is developed and distributed under the Apache 2.0 license.
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
Hashes for sqlalchemy-state-machine-0.3.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | ec12e0c6d400f1e717f24244d3aefb25989ef1bcb3b0d0efa28ea16e869df22a |
|
MD5 | 66aceadbe80ccef5876e84689f2c38ba |
|
BLAKE2b-256 | 17597026894b559c1532ea8d784d6eeb24c271e8ea09c0a5e3a79c1e4809b32a |
Hashes for sqlalchemy_state_machine-0.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 025cc511c6b1a3dce8e8234ab55133f77be225ac61e1f7d8bd7acbad9239b03c |
|
MD5 | a628c8aab86c635233cb2d2ce08c380f |
|
BLAKE2b-256 | e21ee3044bf461e3058026e8f8a3f20b1fc72def5d6e3bb7f1f27478615ea44a |