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.7.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ee287c005e249539df9dbd7d6164eb7eb5714d88941163697ea135916155272 |
|
MD5 | beae6c15e12cab8adc08b11d1299c7e7 |
|
BLAKE2b-256 | 6f6c3f2b90b2e9408a8a043aa759b1a6a06b7b0d046c017a523d066583ebbed0 |
Close
Hashes for sqlalchemy_state_machine-1.7.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 01257d408cb4cff4477f92d9d0fe807b4e3642247d8a46589accf6d6d9d9c6f2 |
|
MD5 | cdb51c23796325effb66d4a82b47e8bb |
|
BLAKE2b-256 | 7424db68e624a2dff7e8d1ec9272de8e16b009feb7b67bb0f06bde5131eb67ce |