fluidstate


Namefluidstate JSON
Version 1.1.0a8 PyPI version JSON
download
home_pageNone
SummaryCompact statechart that can be vendored.
upload_time2024-12-04 21:31:12
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
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            Fluidstate
==========

Compact statechart that can be vendored.


## How to use

A very simple example taken from specs.

```python
>>> from fluidstate import StateChart

>>> class SimpleMachine(StateChart):
...     __statechart__ = {
...         'name': 'machine',
...         '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.state
'State(created)'

>>> machine.queue()

>>> machine.state
'State(waiting)'

>>> machine.process()

>>> machine.state
'State(processed)'

>>> cancel_machine = SimpleMachine()

>>> cancel_machine.state
'State(created)'

>>> cancel_machine.cancel()

>>> cancel_machine.state
'State(canceled)'

```


## A slightly more complex example

For demonstrating more advanced capabilities::

```python
>>> from fluidstate import StateChart

>>> class Relationship(StateChart):
...     __statechart__ = {
...         'initial': 'dating',
...         'states': [
...             {
...                 'name': 'dating',
...                 'transitions': [
...                     {
...                         'event': 'get_intimate',
...                         'target': 'intimate',
...                         'cond': 'drunk',
...                     }
...                 ],
...                 'on_entry': 'make_happy',
...                 'on_exit': 'make_depressed',
...             },
...             {
...                 'name': 'intimate',
...                 'transitions': [
...                     {
...                         'event': 'get_married',
...                         'target': 'married',
...                         'cond': 'willing_to_give_up_manhood',
...                     }
...                 ],
...                 'on_entry': 'make_very_happy',
...                 'on_exit': 'never_speak_again',
...             },
...             {
...                 'name': 'married',
...                 'on_entry': 'give_up_intimacy',
...                 'on_exit': 'buy_exotic_car',
...             }
...         ]
...     }

...     def strictly_for_fun(self) -> None:
...         pass

...     def drunk(self) -> bool:
...         return True

...     def willing_to_give_up_manhood(self) -> bool:
...         return True

...     def make_happy(self) -> None:
...         pass

...     def make_depressed(self) -> None:
...         pass

...     def make_very_happy(self) -> None:
...         pass

...     def never_speak_again(self) -> None:
...         pass

...     def give_up_intimacy(self) -> None:
...         pass

...     def buy_exotic_car(self) -> None:
...         pass

# >>> relationship = Relationship()

```


## States

A Fluidstate 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
the *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 Fluidstate 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 fluidstate
```


### Test

```
tox
```


## Attribution

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

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "fluidstate",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.6.2",
    "maintainer_email": "\"Jesse P. Johnson\" <jpj6652@gmail.com>",
    "keywords": "statechart, state machine",
    "author": null,
    "author_email": "\"Jesse P. Johnson\" <jpj6652@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/04/27/9d620873a2bf2fe2daef7ab1ec3c907af831b1636e537e6cc53437e0c872/fluidstate-1.1.0a8.tar.gz",
    "platform": null,
    "description": "Fluidstate\n==========\n\nCompact statechart that can be vendored.\n\n\n## How to use\n\nA very simple example taken from specs.\n\n```python\n>>> from fluidstate import StateChart\n\n>>> class SimpleMachine(StateChart):\n...     __statechart__ = {\n...         'name': 'machine',\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\n>>> machine.state\n'State(created)'\n\n>>> machine.queue()\n\n>>> machine.state\n'State(waiting)'\n\n>>> machine.process()\n\n>>> machine.state\n'State(processed)'\n\n>>> cancel_machine = SimpleMachine()\n\n>>> cancel_machine.state\n'State(created)'\n\n>>> cancel_machine.cancel()\n\n>>> cancel_machine.state\n'State(canceled)'\n\n```\n\n\n## A slightly more complex example\n\nFor demonstrating more advanced capabilities::\n\n```python\n>>> from fluidstate import StateChart\n\n>>> class Relationship(StateChart):\n...     __statechart__ = {\n...         'initial': 'dating',\n...         'states': [\n...             {\n...                 'name': 'dating',\n...                 'transitions': [\n...                     {\n...                         'event': 'get_intimate',\n...                         'target': 'intimate',\n...                         'cond': 'drunk',\n...                     }\n...                 ],\n...                 'on_entry': 'make_happy',\n...                 'on_exit': 'make_depressed',\n...             },\n...             {\n...                 'name': 'intimate',\n...                 'transitions': [\n...                     {\n...                         'event': 'get_married',\n...                         'target': 'married',\n...                         'cond': 'willing_to_give_up_manhood',\n...                     }\n...                 ],\n...                 'on_entry': 'make_very_happy',\n...                 'on_exit': 'never_speak_again',\n...             },\n...             {\n...                 'name': 'married',\n...                 'on_entry': 'give_up_intimacy',\n...                 'on_exit': 'buy_exotic_car',\n...             }\n...         ]\n...     }\n\n...     def strictly_for_fun(self) -> None:\n...         pass\n\n...     def drunk(self) -> bool:\n...         return True\n\n...     def willing_to_give_up_manhood(self) -> bool:\n...         return True\n\n...     def make_happy(self) -> None:\n...         pass\n\n...     def make_depressed(self) -> None:\n...         pass\n\n...     def make_very_happy(self) -> None:\n...         pass\n\n...     def never_speak_again(self) -> None:\n...         pass\n\n...     def give_up_intimacy(self) -> None:\n...         pass\n\n...     def buy_exotic_car(self) -> None:\n...         pass\n\n# >>> relationship = Relationship()\n\n```\n\n\n## States\n\nA Fluidstate 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\nthe *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 Fluidstate 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 fluidstate\n```\n\n\n### Test\n\n```\ntox\n```\n\n\n## Attribution\n\nFluidstate 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": "Compact statechart that can be vendored.",
    "version": "1.1.0a8",
    "project_urls": {
        "repository": "https://github.com/python-tinker/fluidstate"
    },
    "split_keywords": [
        "statechart",
        " state machine"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "469562fb7592d6e2d44248ff97eb95770ba9fbdd46e719dc627fca2b38d9adc3",
                "md5": "755e625cb046bf602c2370f4aa48ce83",
                "sha256": "6082846e800039877429463ef1752e7fa0a7c68e33389391f6c802f6d6dc505a"
            },
            "downloads": -1,
            "filename": "fluidstate-1.1.0a8-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "755e625cb046bf602c2370f4aa48ce83",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.6.2",
            "size": 9887,
            "upload_time": "2024-12-04T21:31:11",
            "upload_time_iso_8601": "2024-12-04T21:31:11.030442Z",
            "url": "https://files.pythonhosted.org/packages/46/95/62fb7592d6e2d44248ff97eb95770ba9fbdd46e719dc627fca2b38d9adc3/fluidstate-1.1.0a8-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "04279d620873a2bf2fe2daef7ab1ec3c907af831b1636e537e6cc53437e0c872",
                "md5": "4bab882aef739ee55c810fd1ed8c519c",
                "sha256": "ebc8103c9f2a853ac457a3f20b78ea0677f7a345db4d268bd57571504144eeff"
            },
            "downloads": -1,
            "filename": "fluidstate-1.1.0a8.tar.gz",
            "has_sig": false,
            "md5_digest": "4bab882aef739ee55c810fd1ed8c519c",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.6.2",
            "size": 12846,
            "upload_time": "2024-12-04T21:31:12",
            "upload_time_iso_8601": "2024-12-04T21:31:12.723007Z",
            "url": "https://files.pythonhosted.org/packages/04/27/9d620873a2bf2fe2daef7ab1ec3c907af831b1636e537e6cc53437e0c872/fluidstate-1.1.0a8.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-12-04 21:31:12",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "python-tinker",
    "github_project": "fluidstate",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": false,
    "tox": true,
    "lcname": "fluidstate"
}
        
Elapsed time: 0.43529s