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.2.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | fe5a59bc24fd71eedd9652d5a2ee81a6ca8a9e230a9237eacfe96a557e618e36 |
|
MD5 | c05a00dfaa8ea7deb8b6fd13b1647e1b |
|
BLAKE2b-256 | 925a21082fe5b2adb491e2ee48aa9036ffd19732aae432c6e1dcd81df4a77e05 |
Close
Hashes for sqlalchemy_state_machine-1.2.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 25b13815342e9c610f07216ac6538ea6df690e92c06ba8d8cb8167b35a00d392 |
|
MD5 | 054152b1ced0a34ea7849f070864593f |
|
BLAKE2b-256 | 1bec9be7e7a39923344520bc6ad1b0a943c644de1cdc5956311588417f4de09e |