Skip to main content

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 pattern with clear, isolated state definitions.
  • Built-in Automata: Unary, async unary, unary iterable, and async iterable automata.
  • 🏗 Custom Automata Support: Build your own automata with custom state management logic.
  • Strict Typing: Designed for type safety and clarity with full type hints.

Installation

pip install statomata

Quick Start

Define your states:

from statomata.abc import State, Context


class OpenState(State[str, str]):
    def handle(self, income: str, context: Context[State[str, str]]) -> str:
        if income == "close":
            context.set_state(ClosedState())
            return "Closed"

        return "Still open"


class ClosedState(State[str, str]):
    def handle(self, income: str, context: Context[State[str, str]]) -> str:
        if income == "open":
            context.set_state(OpenState())
            return "Opened"

        return "Still closed"

Run the state machine with a built-in automaton:

from statomata.sdk import create_unary_sm

sm = create_unary_sm(OpenState())

print(sm.run("close"))  # Output: Closed
print(sm.run("open"))  # Output: Opened

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

statomata-0.1.0.tar.gz (7.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

statomata-0.1.0-py3-none-any.whl (9.7 kB view details)

Uploaded Python 3

File details

Details for the file statomata-0.1.0.tar.gz.

File metadata

  • Download URL: statomata-0.1.0.tar.gz
  • Upload date:
  • Size: 7.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for statomata-0.1.0.tar.gz
Algorithm Hash digest
SHA256 7a66f614ea6e856123fa4e724ab247018eb177f8ee3985c8697788609f2aa17b
MD5 06dcfb993c7b2cbaa7a6c3cd6e799584
BLAKE2b-256 32714851930e3570ec22c74cc66a8d0225b6169351ae88056403e37b040a081b

See more details on using hashes here.

Provenance

The following attestation bundles were made for statomata-0.1.0.tar.gz:

Publisher: publish.yaml on zerlok/statomata

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file statomata-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: statomata-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 9.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.12.9

File hashes

Hashes for statomata-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 48bb460f21ada4e1ea7749195b13cf420d86ccd3b1c7d748deb326d331b7e2f7
MD5 c4c44f41e28c72dfb174c1287073c0f5
BLAKE2b-256 c2d53f8097518cfcce4f3b6c7c9a82aee0cad8306e65420f7f558f70a91cb96e

See more details on using hashes here.

Provenance

The following attestation bundles were made for statomata-0.1.0-py3-none-any.whl:

Publisher: publish.yaml on zerlok/statomata

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page