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.1.0.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | cc76d92e8b8a6c92a08ce7d18860b6077ec3f5eb557a0a0f798564abaa0140eb |
|
MD5 | b37c968418798588d79a4f4e2c5e797c |
|
BLAKE2b-256 | 9facdc4a6d74978fe547f15015ea117318ca34b02c964b8cf00ebe0dd61735f3 |
Close
Hashes for sqlalchemy_state_machine-1.1.0-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81c0704d2ddcba9f425b68d6ec9ed89d725484142e9db542e0cc869dcac5baee |
|
MD5 | da0484103591e6219b01f83df442f408 |
|
BLAKE2b-256 | e58c3960e50c561db4359607b4c84783fd975a780300c65ed2602fdf031fe4b4 |