pyfsm-tool


Namepyfsm-tool JSON
Version 0.1.0 PyPI version JSON
download
home_page
Summarypyfsm-tool is a module to create and manipulate finite states machines.
upload_time2023-02-01 23:03:57
maintainer
docs_urlNone
author
requires_python>=3.7
licenseMIT
keywords fsm pyfsm pyfsm-tool state states transition transitions fintite state machine fintite states machine finite states machines graph pygraph pygraph-tool
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # pyfsm-tool

pyfsm-tool is a module to create and manipulate finite states machines (fsm).

## Getting started

### Import modules
FiniteStateMachine module:
```python
from pyfsm_tool import FiniteStateMachine, StateBehaviour
```
Exceptions module:
```python
from pyfsm_tool import FSMException
```

### Create new FSM
The new fsm is empty (No state and no transition).
```python
fsm: FiniteStateMachine = FiniteStateMachine()
```

### Initialize the fsm data store
Initialize fsm data store wit 'message' and 'count' available for all states.
```python
fsm.fsm_data_store = {"message": "", "count": 0}
```

### Create new behaviours
Create new behaviours for fsm states.
- First behaviour: add 'Hello' in fsm data store (key = 'message') and next transition is 't1'
```python
class Behaviour1(StateBehaviour):
    def action(self) -> None:
        self.state_data_store["message"] += "Hello"

    def next_transition_id(self) -> str:
        return "t1"
```
- Second behaviour: add ' ' in fsm data store (key = 'message') and next transition is 't2'
```python
class Behaviour2(StateBehaviour):
    def action(self) -> None:
        self.state_data_store["message"] += " "

    def next_transition_id(self) -> str:
        return "t2"
```
- Third behaviour: add 'world' in fsm data store (key = 'message') and next transition is 't3'
```python
class Behaviour3(StateBehaviour):
    def action(self) -> None:
        self.state_data_store["message"] += "world"

    def next_transition_id(self) -> str:
        return "t3"
```
- Fourth behaviour: add '!' in fsm data store (key = 'message') and next transition is 't4' (itself) if the key 'count' in fsm data store is less than 2 (there is incrementation of fsm data store for key 'count'), else next transition is 't5' 
```python
class Behaviour4(StateBehaviour):
    def action(self) -> None:
        self.state_data_store["message"] += "!"

    def next_transition_id(self) -> str:
        if self.state_data_store.get("count") < 2:
            self.state_data_store["count"] += 1
            return "t4"
        return "t5"
```
- Fifth behaviour: display fsm data store (key = 'message') and finish fsm. 
```python
class Behaviour5(StateBehaviour):
    def action(self) -> None:
        print(self.state_data_store.get("message"))
```

### Register all states
- Register first state with first behaviour
```python
fsm.register_first_state(Behaviour1(), "b1")
```
- Register next states with next behaviours
```python
fsm.register_state(Behaviour2(), "b2")
fsm.register_state(Behaviour3(), "b3")
fsm.register_state(Behaviour4(), "b4")
```
- Register last state with last behaviour
```python
fsm.register_last_state(Behaviour5(), "b5")
```

### Register all transitions
```python
fsm.register_transition("b1", "b2", "t1")
fsm.register_transition("b2", "b3", "t2")
fsm.register_transition("b3", "b4", "t3")
fsm.register_transition("b4", "b4", "t4")
fsm.register_transition("b4", "b5", "t5")
```

### Run FSM
```python
fsm.run()
```

## Author
If you have any questions or suggestions, please don't hesitate to contact me : <belaich.david@outlook.fr>.

            

Raw data

            {
    "_id": null,
    "home_page": "",
    "name": "pyfsm-tool",
    "maintainer": "",
    "docs_url": null,
    "requires_python": ">=3.7",
    "maintainer_email": "",
    "keywords": "fsm,pyfsm,pyfsm-tool,state,states,transition,transitions,fintite state machine,fintite states machine,finite states machines,graph,pygraph,pygraph-tool",
    "author": "",
    "author_email": "BEL AICH David <belaich.david@outlook.fr>",
    "download_url": "https://files.pythonhosted.org/packages/28/73/26202fed1dad967702b07b89f96059ee41fea8a3513b6d23dab11d86734b/pyfsm-tool-0.1.0.tar.gz",
    "platform": null,
    "description": "# pyfsm-tool\n\npyfsm-tool is a module to create and manipulate finite states machines (fsm).\n\n## Getting started\n\n### Import modules\nFiniteStateMachine module:\n```python\nfrom pyfsm_tool import FiniteStateMachine, StateBehaviour\n```\nExceptions module:\n```python\nfrom pyfsm_tool import FSMException\n```\n\n### Create new FSM\nThe new fsm is empty (No state and no transition).\n```python\nfsm: FiniteStateMachine = FiniteStateMachine()\n```\n\n### Initialize the fsm data store\nInitialize fsm data store wit 'message' and 'count' available for all states.\n```python\nfsm.fsm_data_store = {\"message\": \"\", \"count\": 0}\n```\n\n### Create new behaviours\nCreate new behaviours for fsm states.\n- First behaviour: add 'Hello' in fsm data store (key = 'message') and next transition is 't1'\n```python\nclass Behaviour1(StateBehaviour):\n    def action(self) -> None:\n        self.state_data_store[\"message\"] += \"Hello\"\n\n    def next_transition_id(self) -> str:\n        return \"t1\"\n```\n- Second behaviour: add ' ' in fsm data store (key = 'message') and next transition is 't2'\n```python\nclass Behaviour2(StateBehaviour):\n    def action(self) -> None:\n        self.state_data_store[\"message\"] += \" \"\n\n    def next_transition_id(self) -> str:\n        return \"t2\"\n```\n- Third behaviour: add 'world' in fsm data store (key = 'message') and next transition is 't3'\n```python\nclass Behaviour3(StateBehaviour):\n    def action(self) -> None:\n        self.state_data_store[\"message\"] += \"world\"\n\n    def next_transition_id(self) -> str:\n        return \"t3\"\n```\n- Fourth behaviour: add '!' in fsm data store (key = 'message') and next transition is 't4' (itself) if the key 'count' in fsm data store is less than 2 (there is incrementation of fsm data store for key 'count'), else next transition is 't5' \n```python\nclass Behaviour4(StateBehaviour):\n    def action(self) -> None:\n        self.state_data_store[\"message\"] += \"!\"\n\n    def next_transition_id(self) -> str:\n        if self.state_data_store.get(\"count\") < 2:\n            self.state_data_store[\"count\"] += 1\n            return \"t4\"\n        return \"t5\"\n```\n- Fifth behaviour: display fsm data store (key = 'message') and finish fsm. \n```python\nclass Behaviour5(StateBehaviour):\n    def action(self) -> None:\n        print(self.state_data_store.get(\"message\"))\n```\n\n### Register all states\n- Register first state with first behaviour\n```python\nfsm.register_first_state(Behaviour1(), \"b1\")\n```\n- Register next states with next behaviours\n```python\nfsm.register_state(Behaviour2(), \"b2\")\nfsm.register_state(Behaviour3(), \"b3\")\nfsm.register_state(Behaviour4(), \"b4\")\n```\n- Register last state with last behaviour\n```python\nfsm.register_last_state(Behaviour5(), \"b5\")\n```\n\n### Register all transitions\n```python\nfsm.register_transition(\"b1\", \"b2\", \"t1\")\nfsm.register_transition(\"b2\", \"b3\", \"t2\")\nfsm.register_transition(\"b3\", \"b4\", \"t3\")\nfsm.register_transition(\"b4\", \"b4\", \"t4\")\nfsm.register_transition(\"b4\", \"b5\", \"t5\")\n```\n\n### Run FSM\n```python\nfsm.run()\n```\n\n## Author\nIf you have any questions or suggestions, please don't hesitate to contact me : <belaich.david@outlook.fr>.\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "pyfsm-tool is a module to create and manipulate finite states machines.",
    "version": "0.1.0",
    "split_keywords": [
        "fsm",
        "pyfsm",
        "pyfsm-tool",
        "state",
        "states",
        "transition",
        "transitions",
        "fintite state machine",
        "fintite states machine",
        "finite states machines",
        "graph",
        "pygraph",
        "pygraph-tool"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "9b57622300c4f05867d6988d3bcf93ebb67c96a24966366246153a23b3f67fab",
                "md5": "099898809afcf900ce5159062d5b779f",
                "sha256": "ab3eccccc586543062e7ac8f7163ad72e3d5fc0ee2fd94d441d5db994443b990"
            },
            "downloads": -1,
            "filename": "pyfsm_tool-0.1.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "099898809afcf900ce5159062d5b779f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.7",
            "size": 5703,
            "upload_time": "2023-02-01T23:03:56",
            "upload_time_iso_8601": "2023-02-01T23:03:56.591447Z",
            "url": "https://files.pythonhosted.org/packages/9b/57/622300c4f05867d6988d3bcf93ebb67c96a24966366246153a23b3f67fab/pyfsm_tool-0.1.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "287326202fed1dad967702b07b89f96059ee41fea8a3513b6d23dab11d86734b",
                "md5": "fe8142d3df5bebd2c7cc087f37f05597",
                "sha256": "2f8055d841d5f1506c53ca13921fe5836e0884277722beef9b32c4ef1b3d71d8"
            },
            "downloads": -1,
            "filename": "pyfsm-tool-0.1.0.tar.gz",
            "has_sig": false,
            "md5_digest": "fe8142d3df5bebd2c7cc087f37f05597",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.7",
            "size": 4768,
            "upload_time": "2023-02-01T23:03:57",
            "upload_time_iso_8601": "2023-02-01T23:03:57.840745Z",
            "url": "https://files.pythonhosted.org/packages/28/73/26202fed1dad967702b07b89f96059ee41fea8a3513b6d23dab11d86734b/pyfsm-tool-0.1.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2023-02-01 23:03:57",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "lcname": "pyfsm-tool"
}
        
Elapsed time: 0.04459s