superstate


Namesuperstate JSON
Version 1.6.1a1 PyPI version JSON
download
home_pageNone
SummaryRobust statechart for configurable automation rules.
upload_time2024-06-05 02:11:15
maintainerNone
docs_urlNone
authorNone
requires_python>=3.6.2
licenseThe 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.
keywords statechart state machine scxml harel
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            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.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "superstate",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6.2",
    "maintainer_email": "\"Jesse P. Johnson\" <jpj6652@gmail.com>",
    "keywords": "statechart, state machine, scxml, Harel",
    "author": null,
    "author_email": "\"Jesse P. Johnson\" <jpj6652@gmail.com>",
    "download_url": null,
    "platform": null,
    "description": "Superstate\n==========\n\nRobust statechart for configurable automation rules.\n\n\n## How to use\n\nA very simple example taken from specs.\n\n```python\n>>> from superstate import StateChart\n\n>>> class SimpleMachine(StateChart):\n...     state = {\n...         'initial': 'created',\n...         'states': [\n...             {\n...                 'name': 'created',\n...                 'transitions': [\n...                     {'event': 'queue', 'target': 'waiting'},\n...                     {'event': 'cancel', 'target': 'canceled'},\n...                 ],\n...             },\n...             {\n...                 'name': 'waiting',\n...                 'transitions': [\n...                     {'event': 'process', 'target': 'processed'},\n...                     {'event': 'cancel', 'target': 'canceled'},\n...                 ]\n...             },\n...             {'name': 'processed'},\n...             {'name': 'canceled'},\n...         ]\n...     }\n\n>>> machine = SimpleMachine()\n>>> machine.current_state\n'AtomicState(created)'\n\n>>> machine.trigger('queue')\n>>> machine.current_state\n'AtomicState(waiting)'\n\n>>> machine.trigger('process')\n>>> machine.current_state\n'AtomicState(processed)'\n\n>>> cancel_machine = SimpleMachine()\n>>> cancel_machine.current_state\n'AtomicState(created)'\n\n>>> cancel_machine.trigger('cancel')\n>>> cancel_machine.current_state\n'AtomicState(canceled)'\n\n```\n\n\n## States\n\nA Superstate state machine must have one initial state and at least one other additional state.\n\nA state may have pre and post callbacks, for running some code on state `on_entry`\nand `on_exit`, respectively. These params can be method names (as strings),\ncallables, or lists of method names or callables.\n\n\n## Transitions\n\nTransitions lead the machine from a state to another. Transitions must have\nboth `event`, and `target` parameters. The `event` is the method that have to be\ncalled to launch the transition. The `target` is the state to which the\ntransition will move the machine. This method is automatically created\nby the Superstate engine.\n\nA transition can have optional `action` and `cond` parameters. `action` is a\nmethod (or callable) that will be called when transition is launched. If\nparameters are passed to the event method, they are passed to the `action`\nmethod, if it accepts these parameters. `cond` is a method (or callable) that\nis called to allow or deny the transition, depending on the result of its\nexecution. Both `action` and `cond` can be lists.\n\nThe same event can be in multiple transitions, going to different states, having\ntheir respective needs as selectors. For the transitions having the same event,\nonly one `cond` should return a true value at a time.\n\n\n### Install\n\n```\npip install superstate\n```\n\n\n### Test\n\n```\ntox\n```\n\n\n## Attribution\n\nSuperstate is forked from https://github.com/nsi-iff/fluidity created by Rodrigo Manh\u00e3es.\n",
    "bugtrack_url": null,
    "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. ",
    "summary": "Robust statechart for configurable automation rules.",
    "version": "1.6.1a1",
    "project_urls": {
        "repository": "https://github.com/kuwv/python-superstate"
    },
    "split_keywords": [
        "statechart",
        " state machine",
        " scxml",
        " harel"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "761a2f92a6c50cc717991bc12b87f1d365b6d7feaf12d8e1592c0a7761cbac84",
                "md5": "4fbd578224a54f2080313f285ad091eb",
                "sha256": "64b7a64a3e52a0421c5f112c11a6a8b07181d0082fd68bdd0a53766d4f35cb03"
            },
            "downloads": -1,
            "filename": "superstate-1.6.1a1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "4fbd578224a54f2080313f285ad091eb",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6.2",
            "size": 28773,
            "upload_time": "2024-06-05T02:11:15",
            "upload_time_iso_8601": "2024-06-05T02:11:15.917199Z",
            "url": "https://files.pythonhosted.org/packages/76/1a/2f92a6c50cc717991bc12b87f1d365b6d7feaf12d8e1592c0a7761cbac84/superstate-1.6.1a1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-06-05 02:11:15",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "kuwv",
    "github_project": "python-superstate",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "superstate"
}
        
Elapsed time: 0.25471s