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.4.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 99ed3dd61fb777034ba6d7834d987bdd39cb0b81970150c2ea30fea2d2d2838f |
|
MD5 | c8011bc477f2d803c770ee7771dae831 |
|
BLAKE2b-256 | f34763c1819791fb21c1a1459fa01a069bdf8f47b32573bab61a7089527adbcd |
Close
Hashes for sqlalchemy_state_machine-0.5.4-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 84ea5dac62d9178c1026bc49d53251d0230f94742ead2cf8a3131e1a644cb0c3 |
|
MD5 | 53e1a1b5d7d79cbb6abc2d6e753a200f |
|
BLAKE2b-256 | 7320c9ea35a64e882b9e37af85e70a195008923953c422a8c7c2c25de2f14db0 |