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.3.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | a953fb8a8ce9ca619ed72e714687f55ffcba5023df3585d37b58d91d35d5c19a |
|
MD5 | 509e29e10ccc30bd69ad1a896c49433e |
|
BLAKE2b-256 | 8c4858dbbc12f99a3e38c6620b89d06a65b93594d8e7ff22867e327bc30d7421 |
Close
Hashes for sqlalchemy_state_machine-1.3.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 05232a8e4128f170c70104461be1f875242e6c36b2b64d41eeab24e856185ebe |
|
MD5 | ccc10763998be0e0d47145a7e6525fbc |
|
BLAKE2b-256 | b3891ec456229e3838df0f187c6d182ec199b1edf8e1166342bf4505b58b5af8 |