Skip to main content

Super simple state machine

Project description

Tilakone

Super simple state machine

from tilakone import StateChart, StateMachine
from typing import Literal

States = Literal["ON", "OFF"]
Events = Literal["toggle", "turn_off"]

state_chart = StateChart[States, Events]({
    "OFF": {
        "initial": True,
        "on": {
            "toggle": "ON"
        }
    },
    "ON": {
        "initial": False,
        "on": {
            "toggle": "OFF",
            "turn_off": "OFF"
        }
    }
})

machine = StateMachine(state_chart)
assert machine.current_state == "OFF"

transitioned = machine.send("toggle")
assert transitioned == True
assert machine.current_state == "ON"

transitioned = machine.send("turn_off")
assert transitioned == True
assert machine.current_state == "OFF"

# Irrelevant events are ignored
transitioned = machine.send("turn_off")
assert transitioned == False
assert machine.current_state == "OFF"

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

tilakone-0.1.0.tar.gz (1.7 kB view details)

Uploaded Source

Built Distribution

tilakone-0.1.0-py3-none-any.whl (2.1 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: tilakone-0.1.0.tar.gz
  • Upload date:
  • Size: 1.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.9 FreeBSD/14.1-RELEASE-p3

File hashes

Hashes for tilakone-0.1.0.tar.gz
Algorithm Hash digest
SHA256 0f7b6e83583bbf56895153314f00beebf23d5fd94d8bbac622369e4544067cbe
MD5 ec27219f8f49b987eda1d2c5cff686cc
BLAKE2b-256 0b927fe6819631c95679cb0aab6a1e3d9db80fcf292b7c7db3817e00f24b1510

See more details on using hashes here.

File details

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

File metadata

  • Download URL: tilakone-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 2.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.3 CPython/3.11.9 FreeBSD/14.1-RELEASE-p3

File hashes

Hashes for tilakone-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 fc225bc5c3231a28356970e1a98da74736dc6be0f6a085b7efdf938ea0f5fbe3
MD5 4aba5a6a5d53a1fbe2b462a92649b62f
BLAKE2b-256 5cbd37e23f468c9baf4e6341c1122d895104e7b31f72b69eb4e7775ee2e1e38b

See more details on using hashes here.

Supported by

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