Skip to main content

Minimata is a minimalist state-machine implementation.

Project description

Minimata: minimalist state-machine in Python

Miniata is a very small library to manage state-machines in Python.

Because it doesn't bundle a lot of features, it's pretty flexible.

Installation

Use the package manager pip to install minimata.

pip install minimata

Why

I needed a really simple implementations and didn't wanted to reach to heavier alternatives like transitions.

Usage

Here is an example:

from minimata import StateMachine, skip_transition

model_onboarding_state_machine = StateMachine("onboarding_state")

@model_onboarding_state_machine.on("event", {"source_state": "destination_state"})
def callback(model: Model, param: bool = False, **kwargs):
    if param:
        print(model)

@dataclass
class UserModel:
    onboarding_state: str

user_model = UserModel(onboarding_state="source_state")

model_onboarding_state_machine.trigger(
    model=user_model,
    event="event",
    param=True,
) # Executes callback (prints user_model) *THEN* update its state.

Contributing

With a hundred line of code, it's possible to get there and customize this. It'll probably make sense for you to copy-paste that code rather than to add it as a dependency.

That being said, pull-requests are welcome. It would be nice to polish the library, please open an issue first to discuss what you would like to change.

Please make sure to update tests as appropriate.

Credits

Inspiration was heavily taken from the following projects.

Many thanks to their authors, maintainers, and contributors.

License

MIT

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

minimata-0.1.1.tar.gz (4.9 kB view hashes)

Uploaded Source

Built Distribution

minimata-0.1.1-py3-none-any.whl (7.1 kB view hashes)

Uploaded Python 3

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