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.10.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | d5717e58a9e8304f1067e8f0bd5dee71cd127416c6adb67dd7f3374d368bf7df |
|
MD5 | e054ab3a91eaff6dd09b81743986b669 |
|
BLAKE2b-256 | 88c4b4e7202cb3640d81c78953e0b6425061459b06100b6e1e0c8164992f1564 |
Close
Hashes for sqlalchemy_state_machine-1.10.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 353c1d373454d69275ad98d9aaf66f6b90c51d594e4bef364c638cf56720829f |
|
MD5 | 98e9b1ada3833ba95d4f537df35dd496 |
|
BLAKE2b-256 | 35b6889ecde682bf72329ba44ef337735af505e8dba3c16f4f862c2ed37b2b52 |