Skip to main content

A hierarchical finite state machine library

Project description

gotstate

Security Quality Tests Lint

A hierarchical finite state machine (HFSM) library for Python, focusing on reliability and ease of use.

Features

  • Hierarchical state machines with composite states
  • Type-safe state and event handling
  • Thread-safe event processing
  • Guard conditions and transition actions
  • State data management with lifecycle hooks
  • Timeout events
  • History states (both shallow and deep)
  • Error handling
  • Activation hooks for monitoring
  • Plugin system

Status

Version 1.0

Features:

  • Full test coverage
  • Type hints
  • Input validation
  • Error handling
  • API documentation

Design Philosophy

gotstate is designed with the following principles:

  • Safety: Runtime validation and type checking
  • Clarity: Intuitive API design
  • Reliability: Built for real-world applications
  • Performance: Minimal overhead
  • Flexibility: Extensible through plugins

Example

from hsm.core import StateMachine, State, Event, Transition

# Define states
class Idle(State):
    pass

class Running(State):
    pass

# Define events
class Start(Event):
    pass

class Stop(Event):
    pass

# Create state machine
sm = StateMachine("example")
idle = sm.add_state(Idle("idle"))
running = sm.add_state(Running("running"))

# Add transitions
sm.add_transition(Transition(idle, running, Start))
sm.add_transition(Transition(running, idle, Stop))

# Initialize and use
sm.initialize()
assert sm.current_state == idle
sm.handle_event(Start())
assert sm.current_state == running

Installation

Install using pip:

pip install gotstate

Requirements

  • Python 3.8 or higher
  • See requirements.txt for full dependencies

Documentation

Documentation is available in the docs/ directory:

  • API Reference
  • Usage Guide
  • Examples

License

Licensed under the MIT License. See the LICENSE file for details.

Contributing

Contributions are welcome! Please read our contributing guidelines in CONTRIBUTING.md.

Security

This package follows Python security best practices.

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

gotstate-1.0.1.tar.gz (4.0 kB view details)

Uploaded Source

Built Distribution

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

gotstate-1.0.1-py3-none-any.whl (3.2 kB view details)

Uploaded Python 3

File details

Details for the file gotstate-1.0.1.tar.gz.

File metadata

  • Download URL: gotstate-1.0.1.tar.gz
  • Upload date:
  • Size: 4.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.12

File hashes

Hashes for gotstate-1.0.1.tar.gz
Algorithm Hash digest
SHA256 8ffbb30fd7f8c28d6aabfb9a826f89a44cfa7501846a24cfa6afc19b55f643d3
MD5 bd15511329e07045132e9ea183824d1b
BLAKE2b-256 0370de6ae385f01ae06dde67cfb95b3a37458b7e492ed076ab270eba8948dd2b

See more details on using hashes here.

File details

Details for the file gotstate-1.0.1-py3-none-any.whl.

File metadata

  • Download URL: gotstate-1.0.1-py3-none-any.whl
  • Upload date:
  • Size: 3.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.0.1 CPython/3.10.12

File hashes

Hashes for gotstate-1.0.1-py3-none-any.whl
Algorithm Hash digest
SHA256 94f0ae56ea018473ec5698bc13d7ab752d1ff5b61163e684afd1e21318c1d920
MD5 8bae58bf182eff4f9794b5bc3c75c274
BLAKE2b-256 5c354a49f056d77e8006905a92906a81f77ac146a9513d3cd58198d98b349c67

See more details on using hashes here.

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