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")
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.
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.3.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 0f3992dcd34bda016ad577ad172717866ce032eb43af8a7e7c81fc17b2ab2a0c |
|
MD5 | 5b46096de27a45011bc02056897f85e3 |
|
BLAKE2b-256 | 26546facaab755e1a6d1afd639ef1a517823aa93f0ce2f5e13b6a2132fd68bfd |
Close
Hashes for sqlalchemy_state_machine-0.3.3-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | beb780c6475f18c4376269c825e346060b69ae5fc2962ee4aab589b4dcba0f5f |
|
MD5 | ccb4ab8e21315e763a0e6bd0bd9bafea |
|
BLAKE2b-256 | ea333fff511e46f8ee2df97e6a0dba88dbcc98cdbabc7659d3ab74d44ad7993a |