Distributed FSM over etcd
Project description
etcd-fsm
🤖 absolute ai, 0% of code written by human 🤖
A typed, asynchronous distributed finite-state machine over etcd.
The current implementation contains the declarative type system, schema and
processor compiler, signature-derived transition graph, an internal etcd
contract, a deterministic MVCC fake, and the production aetcd adapter. The
production runtime is under construction.
from enum import StrEnum, auto
from typing import Literal
from uuid import UUID
from etcd_fsm import BaseState, FSMProcessor, FSMSchema, Retry
class OrderStatus(StrEnum):
CREATED = auto()
PAYMENT_REQUIRED = auto()
class OrderState[S: OrderStatus](BaseState[S]):
order_id: UUID
def fsm_key(self) -> str:
return str(self.order_id)
class Created(OrderState[Literal[OrderStatus.CREATED]]):
state: Literal[OrderStatus.CREATED] = OrderStatus.CREATED
class PaymentRequired(OrderState[Literal[OrderStatus.PAYMENT_REQUIRED]]):
state: Literal[OrderStatus.PAYMENT_REQUIRED] = OrderStatus.PAYMENT_REQUIRED
attempt: int = 1
orders = FSMSchema(
name="orders",
namespace="/state/orders",
state_enum=OrderStatus,
states=(Created, PaymentRequired),
)
payments = FSMProcessor(schema=orders, name="payments")
@payments.reaction()
async def request_payment(state: Created) -> PaymentRequired | Retry:
return PaymentRequired(order_id=state.order_id)
payments.finalize()
Function annotations are the transition definition. Concrete State Models use literal enum discriminators, models are immutable snapshots, and the schema rejects incomplete or inconsistent declarations before a runtime starts.
The public Python API and graph CLI are documented in Russian in docs/API.md. The PyPI release process is documented in docs/RELEASING.md.
Transition graph
Import modules containing schemas and processors and render their combined transition graph as Mermaid:
etcd-fsm graph my_service.orders my_service.payments
Python file paths are accepted as well:
etcd-fsm graph tests/order_domain.py
Every transition is labeled with its processor, function, and producer kind.
Use explicit module:OBJECT or path/to/file.py:OBJECT references when
automatic discovery is not appropriate, or render Graphviz DOT into a file:
etcd-fsm graph my_service.orders:ORDER_SCHEMA \
my_service.payments:PAYMENTS --format dot -o orders.dot
The architectural vocabulary is documented in CONTEXT.md.
Design premises and implementation order are recorded in
docs/DESIGN-NOTES.md, with accepted decisions under
docs/adr/.
Local etcd
Start an ephemeral etcd instance for integration tests:
docker compose up -d --wait
The client endpoint is http://127.0.0.1:12379. Stop it and discard its data
with docker compose down.
Run the real-etcd integration suite explicitly:
uv run pytest --run-integration -m integration
The integration tests use a unique /etcd-fsm-tests/<uuid>/ prefix and clean
it after each test. Override the endpoint with ETCD_FSM_TEST_HOST and
ETCD_FSM_TEST_PORT.
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
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 etcd_fsm-0.1.2.tar.gz.
File metadata
- Download URL: etcd_fsm-0.1.2.tar.gz
- Upload date:
- Size: 76.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
242f236a526f21ded5531b104a223bf55f3fc0f6e705a13d360103d5f628f7a7
|
|
| MD5 |
ff34b6dd08dfa0ded3cf023b0ff81de6
|
|
| BLAKE2b-256 |
653443e195aa91a9acc04ced01116f86a8276e50577b882beb5e11ca3544f7f2
|
Provenance
The following attestation bundles were made for etcd_fsm-0.1.2.tar.gz:
Publisher:
release.yml on Rubikoid/etcd-fsm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
etcd_fsm-0.1.2.tar.gz -
Subject digest:
242f236a526f21ded5531b104a223bf55f3fc0f6e705a13d360103d5f628f7a7 - Sigstore transparency entry: 2295459988
- Sigstore integration time:
-
Permalink:
Rubikoid/etcd-fsm@aa7aa61ff98af56ff13eecb495c5ecb522fe6aba -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/Rubikoid
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@aa7aa61ff98af56ff13eecb495c5ecb522fe6aba -
Trigger Event:
push
-
Statement type:
File details
Details for the file etcd_fsm-0.1.2-py3-none-any.whl.
File metadata
- Download URL: etcd_fsm-0.1.2-py3-none-any.whl
- Upload date:
- Size: 26.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/7.0.0 CPython/3.13.14
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
677c3657a871916d20db53a350d162523f37bb8870af57795a0313d80c32a9f6
|
|
| MD5 |
785868ef2e865b839628d3349c6b53be
|
|
| BLAKE2b-256 |
1fef0ce8088576de4e9ee08b60b8f32e813fb47b552f98732eb05d15f4408103
|
Provenance
The following attestation bundles were made for etcd_fsm-0.1.2-py3-none-any.whl:
Publisher:
release.yml on Rubikoid/etcd-fsm
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
etcd_fsm-0.1.2-py3-none-any.whl -
Subject digest:
677c3657a871916d20db53a350d162523f37bb8870af57795a0313d80c32a9f6 - Sigstore transparency entry: 2295460071
- Sigstore integration time:
-
Permalink:
Rubikoid/etcd-fsm@aa7aa61ff98af56ff13eecb495c5ecb522fe6aba -
Branch / Tag:
refs/tags/v0.1.2 - Owner: https://github.com/Rubikoid
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
release.yml@aa7aa61ff98af56ff13eecb495c5ecb522fe6aba -
Trigger Event:
push
-
Statement type: