Helper for add transitions functionality in sqlalchemy
Project description
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")
assert event.status == NEW
assert event.set_sent()
assert event.status == SENT
License
sqlalchemy-state-machine is developed and distributed under the Apache 2.0 license.
Reporting a Security Vulnerability
See our security policy.
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
Close
Hashes for sqlalchemy-state-machine-0.5.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 522cf2d73f4f7925d7f5c3ec60fa103aba49afb9c54d24bbffc25394a1b0b3c6 |
|
MD5 | b1b6c344e9aa9f9e777fea257bded4c6 |
|
BLAKE2b-256 | 728916bc69902cae5f5ed5831df920f76786b10095ee69bdf240c87c1d4d12bd |
Close
Hashes for sqlalchemy_state_machine-0.5.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 72dcb661f772c127f5afbb3f1b4351852f0194acb1e1f338ad8b7dcdf8f8d204 |
|
MD5 | b90b79585b19c988df95fc28cc047c26 |
|
BLAKE2b-256 | 5bd3b0e64f9f3ab5b493376740edbbfe88d24ebe405e47855af043d39b67b706 |