Metadata-Version: 2.1
Name: superstate
Version: 1.6.2a0
Summary: Robust statechart for configurable automation rules.
Author-email: "Jesse P. Johnson" <jpj6652@gmail.com>
Maintainer-email: "Jesse P. Johnson" <jpj6652@gmail.com>
License: The MIT License
        
        Copyright (c) 2022 Jesse P. Johnson
        
        Permission is hereby granted, free of charge, to any person obtaining a copy
        of this software and associated documentation files (the "Software"), to deal
        in the Software without restriction, including without limitation the rights
        to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
        copies of the Software, and to permit persons to whom the Software is
        furnished to do so, subject to the following conditions:
        
        The above copyright notice and this permission notice shall be included in
        all copies or substantial portions of the Software.
        
        THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
        IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
        FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
        AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
        LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
        OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
        THE SOFTWARE.
        
Project-URL: repository, https://github.com/kuwv/python-superstate
Keywords: statechart,state machine,scxml,Harel
Classifier: Development Status :: 3 - Alpha
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Programming Language :: Python
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.6
Classifier: Programming Language :: Python :: 3.7
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Software Development :: Libraries
Requires-Python: >=3.6.2
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: RestrictedPython
Requires-Dist: typing_extensions
Provides-Extra: ecmascript
Requires-Dist: js2py; extra == "ecmascript"
Provides-Extra: scxml
Requires-Dist: xmltodict; extra == "scxml"
Provides-Extra: build
Requires-Dist: build; extra == "build"
Requires-Dist: proman-versioning>=0.5.0-alpha.2; extra == "build"
Requires-Dist: twine; extra == "build"
Provides-Extra: dev
Requires-Dist: pytest>=7; extra == "dev"
Requires-Dist: pytest-benchmark>=4; extra == "dev"
Requires-Dist: pytest-cov>=2.10.0; extra == "dev"
Requires-Dist: tox>=3.25.0; extra == "dev"
Requires-Dist: mypy>=1; extra == "dev"
Requires-Dist: pylint>=3; extra == "dev"
Requires-Dist: black==22.3.0; extra == "dev"
Requires-Dist: isort>=5.10.1; extra == "dev"
Requires-Dist: flake8>=3.8.3; extra == "dev"
Requires-Dist: bandit>=1.6.2; extra == "dev"
Requires-Dist: safety>=1.9.0; extra == "dev"
Provides-Extra: docs
Requires-Dist: docstr-coverage>=1.2.0; extra == "docs"
Requires-Dist: mkdocs>=1.2; extra == "docs"
Requires-Dist: mkdocs-material>=7.2; extra == "docs"
Requires-Dist: mkdocstrings>=0.15.2; extra == "docs"
Requires-Dist: pydocstyle[toml]>=6.1.1; extra == "docs"

Superstate
==========

Robust statechart for configurable automation rules.


## How to use

A very simple example taken from specs.

```python
>>> from superstate import StateChart

>>> class SimpleMachine(StateChart):
...     state = {
...         'initial': 'created',
...         'states': [
...             {
...                 'name': 'created',
...                 'transitions': [
...                     {'event': 'queue', 'target': 'waiting'},
...                     {'event': 'cancel', 'target': 'canceled'},
...                 ],
...             },
...             {
...                 'name': 'waiting',
...                 'transitions': [
...                     {'event': 'process', 'target': 'processed'},
...                     {'event': 'cancel', 'target': 'canceled'},
...                 ]
...             },
...             {'name': 'processed'},
...             {'name': 'canceled'},
...         ]
...     }

>>> machine = SimpleMachine()
>>> machine.current_state
'AtomicState(created)'

>>> machine.trigger('queue')
>>> machine.current_state
'AtomicState(waiting)'

>>> machine.trigger('process')
>>> machine.current_state
'AtomicState(processed)'

>>> cancel_machine = SimpleMachine()
>>> cancel_machine.current_state
'AtomicState(created)'

>>> cancel_machine.trigger('cancel')
>>> cancel_machine.current_state
'AtomicState(canceled)'

```


## States

A Superstate state machine must have one initial state and at least one other additional state.

A state may have pre and post callbacks, for running some code on state `on_entry`
and `on_exit`, respectively. These params can be method names (as strings),
callables, or lists of method names or callables.


## Transitions

Transitions lead the machine from a state to another. Transitions must have
both `event`, and `target` parameters. The `event` is the method that have to be
called to launch the transition. The `target` is the state to which the
transition will move the machine. This method is automatically created
by the Superstate engine.

A transition can have optional `action` and `cond` parameters. `action` is a
method (or callable) that will be called when transition is launched. If
parameters are passed to the event method, they are passed to the `action`
method, if it accepts these parameters. `cond` is a method (or callable) that
is called to allow or deny the transition, depending on the result of its
execution. Both `action` and `cond` can be lists.

The same event can be in multiple transitions, going to different states, having
their respective needs as selectors. For the transitions having the same event,
only one `cond` should return a true value at a time.


### Install

```
pip install superstate
```


### Test

```
tox
```


## Attribution

Superstate is forked from https://github.com/nsi-iff/fluidity created by Rodrigo Manhães.
