a strictly typed, flexible library for building and running state machines in Python
Project description
Statomata
Statomata is a strictly typed, flexible library for building and running finite state machines (FSMs) and automata in Python. It provides core automata implementations out of the box and lets you define custom states and state management logic.
Features
- 🧠 State Interface & Context: Follow the state machine OOP pattern with clear, isolated state definitions.
- ⚡ Built-in Automata: feel free to use one of the predefined automata classes from SDK.
- 🏗 Custom Automata Support: Build your own automata with custom state management logic. You can choose declarative style or built custom automata using provided interfaces.
- ✅ Strict Typing: Designed for type safety and clarity with full type hints.
Installation
pip install statomata
Quick Start
Use high-level declarative style:
from statomata.declarative import DeclarativeStateMachine, State
class OpenCloseExample(DeclarativeStateMachine):
closed = State(initial=True)
opened = State()
@closed.to(opened)
def open(self) -> str:
return "Opened"
@opened.to(closed)
def close(self) -> str:
return "Closed"
Run the state machine:
from contextlib import suppress
from statomata.exception import InvalidStateError
sm = OpenCloseExample()
print(sm.open()) # Output: Opened
print(sm.close()) # Output: Closed
with suppress(InvalidStateError):
sm.close()
Or you can use low-level style:
from statomata.abc import State, Context
from statomata.exception import InvalidStateError
class OpenState(State[str, str]):
def handle(self, income: str, context: Context[State[str, str]]) -> str:
if income != "close":
raise InvalidStateError(self, message="already opened")
context.set_state(ClosedState())
return "Closed"
class ClosedState(State[str, str]):
def handle(self, income: str, context: Context[State[str, str]]) -> str:
if income != "open":
raise InvalidStateError(self,message="already closed")
context.set_state(OpenState())
return "Opened"
Run the state machine:
from contextlib import suppress
from statomata.exception import InvalidStateError
from statomata.sdk import create_unary_sm
sm = create_unary_sm(ClosedState())
print(sm.run("open")) # Output: Opened
print(sm.run("close")) # Output: Closed
with suppress(InvalidStateError):
sm.run("close")
Examples
- order control
- positive number store
- traffic light
- transition cases
Project details
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
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file statomata-0.2.0.tar.gz.
File metadata
- Download URL: statomata-0.2.0.tar.gz
- Upload date:
- Size: 16.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8f0120f151a9bdb6fa2ea6d59b439f0c9e4f5c97cf3250994e311558b5c7887e
|
|
| MD5 |
036a0cb29291e798e0cfda8bae7009b9
|
|
| BLAKE2b-256 |
a0e750f64228172ca7ea131e3165f9724b34898e67d4cfb9f5760de5e6ca5b10
|
Provenance
The following attestation bundles were made for statomata-0.2.0.tar.gz:
Publisher:
publish.yaml on zerlok/statomata
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
statomata-0.2.0.tar.gz -
Subject digest:
8f0120f151a9bdb6fa2ea6d59b439f0c9e4f5c97cf3250994e311558b5c7887e - Sigstore transparency entry: 214845262
- Sigstore integration time:
-
Permalink:
zerlok/statomata@8a70221dbb9df929427f59ab58934795d45e8d10 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/zerlok
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@8a70221dbb9df929427f59ab58934795d45e8d10 -
Trigger Event:
release
-
Statement type:
File details
Details for the file statomata-0.2.0-py3-none-any.whl.
File metadata
- Download URL: statomata-0.2.0-py3-none-any.whl
- Upload date:
- Size: 21.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d40833829564a216f96eb03c2ee67debdbc8ef7b3717c823d433a59049218b9f
|
|
| MD5 |
fb6a9120627b14adf96d730d982482f4
|
|
| BLAKE2b-256 |
ad40b672d49e6d414734ab4f2827bb684dbf0e675cfef66c3a583a0a830f22dd
|
Provenance
The following attestation bundles were made for statomata-0.2.0-py3-none-any.whl:
Publisher:
publish.yaml on zerlok/statomata
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
statomata-0.2.0-py3-none-any.whl -
Subject digest:
d40833829564a216f96eb03c2ee67debdbc8ef7b3717c823d433a59049218b9f - Sigstore transparency entry: 214845264
- Sigstore integration time:
-
Permalink:
zerlok/statomata@8a70221dbb9df929427f59ab58934795d45e8d10 -
Branch / Tag:
refs/tags/v0.2.0 - Owner: https://github.com/zerlok
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish.yaml@8a70221dbb9df929427f59ab58934795d45e8d10 -
Trigger Event:
release
-
Statement type: