Helper for add transitions functionality in sqlalchemy
Project description
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")
event.set_sent()
License
sqlalchemy-state-machine is developed and distributed under the Apache 2.0 license.
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.3.2.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51981bbc3aa7f24acf58c0d019bb82d2031741bc1ec92baf865bb10a8afdf351 |
|
MD5 | 93ad208d685d2ccfabe815cd0860c236 |
|
BLAKE2b-256 | d2233a892872af66989b59017e3bea17d3b2c0e434b65fc7349159eb184053f2 |
Close
Hashes for sqlalchemy_state_machine-0.3.2-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | ea7a32cdb01e18a8e6d3a177eb49b7e2748d99f6a1e7abe6b04ab45ea5837e8d |
|
MD5 | a93fabfceca081eb4c587f5a2fc38207 |
|
BLAKE2b-256 | eaf1fea87599e3fdb21464da7e3ba43ed8025587c765e0a92addad532d94823a |