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-1.11.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ac880cc2e8c13fcb9d3391a01a4809bb9dc845324423dab51af81d41204ef2a |
|
MD5 | db83631a2ff19893ccf5cadf3a4c7cf9 |
|
BLAKE2b-256 | 14977b80ec8d397de5d91aadad50d3a54a1470a74667ab3ab3ef3a4462777b92 |
Close
Hashes for sqlalchemy_state_machine-1.11.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | bd6a15033625d216c797a21b0784c5ee844ae2af385fdd3d1b09e271eb38d5ef |
|
MD5 | d522955ccd48fb2d774b1280be849fcc |
|
BLAKE2b-256 | 4aa1a2b439e029dc5d83a7df076855e4be41cdc7771406e9aaeccf16591dac01 |