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.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 33daa8b388e6be95b7a010db8f1f65b9fede9839c143baba9487912bf86bf367 |
|
MD5 | 9eb1fd0b5f59abc0fced3bc6a7c524c5 |
|
BLAKE2b-256 | f3430a7b95e2b04f05db967c91430e19f03c441e674082b210fc80e71fad2342 |
Close
Hashes for sqlalchemy_state_machine-0.5.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 7a6f95ab1be999cd5c5d223b51ee81e88869b28de7fff12a292a06235f9b73e4 |
|
MD5 | a73ee06597fc5a2422c8d1a538c5c4de |
|
BLAKE2b-256 | b4dfed826497a2c80e64b032f087d46d5941aefee39b262c80e83355828c73d2 |