{ "info": { "author": "", "author_email": "", "bugtrack_url": null, "classifiers": [], "description": "# Deterministic, Finite State Machine\n\n## Contents\n* [Installation](#installation)\n* [State Machine](#statemachine)\n* * [blueprint](#blueprint)\n* * [state](#state)\n* * [context](#context)\n* * [initial](#initial)\n* * [accepted](#accepted)\n* * [final](#final)\n* [Usage](#usage)\n\n---\n\n## Installation\n\n```\npython setyp.py install\n```\n\n---\n\n## StateMachine\n\n### Members\n\n#### blueprint\n\nThis is a propery with a getter and setter that defines the state machine.\nSetting the blueprint will also reset the state machine.\n\n```python\n{\n \"initialState\": state,\n \"initialContext\": dict(),\n \"alphabet\": set(),\n \"validStates\": set(),\n \"acceptedStates\": set(),\n \"finalStates\": set(),\n \"transition\": lambda state, context, event: new_state,\n \"lifecycles\": dict()\n}\n```\n\n##### Initial Context\n\nAn optional dictionary, which can be used to share information between states\nand updated during state transitions.\n\n##### Alphabet\n\nA set of events, which are used to drive state transitions.\n\n##### Initial State\n\nThe starting state. Must be a valid state.\n\n##### Valid States\n\nA set of valid states.\n\n##### Accepted States\n\nA set of accepted states.\n\n##### Final States\n\nA set of final states, once reached, new transitions will raise `StopMachine`.\n\n##### Transition\n\nA function, which takes state, context and event as parameters\nand returns the next state. The event must be a member of the alphabet\nand the new state must be a valid state.\n\n##### Lifecycles\n\nLifecycle actions can be ran before or after specific events.\n\n###### Events\n\nA set of events, which are used to drive lifecycle actions.\n\n###### Actions\n\nA list of functions, which take state, context and event as parameters.\n\n```python\n{\n \"lifecycles\": {\n \"before\": [{\n \"events\": {0, 1, 2, 3},\n \"actions\": [before_any]\n }],\n \"after\": [{\n events: {3},\n \"actions\": [after_three]\n }, {\n \"events\": {2, 3},\n \"actions\": [action1, action2]\n }]\n }\n}\n```\n\n* before_any executes before events 0, 1, 2 & 3 transitions are executed\n* after_three executres after event 3 transition is executed\n* action1, then action2 executes after events 2 & 3 transitions are executed\n\n#### state\n\nThe current state of the state machine.\n\n#### context\n\nThe current context of the state machine.\n\n#### initial\n\nTrue or False if the current state is the initial state.\n\n#### accepted\n\nTrue or False if the current state is an accepted state.\n\n#### final\n\nTrue or False if the current state is a final state.\n\n### Methods\n\n#### reset()\n\nResets the state machine's state and context to their initial values defined\nin the blueprint. The initial state must be a valid state.\n\n* `ValueError` - Invalid initial state\n\n#### set_state(state, context)\n\nSet the state machine's state and context. The state must be a valid state.\n\n* `ValueError` - Invalid state\n\n#### transition(event)\n\nTransitions the state machine to the next state by executing the transition\ndefined in the blueprint. The event must be a valid member of the alphabet\ndefined in the blueprint. The state must be a valid state.\n\n* `StopMachine` - Current state is final\n* `ValueError` - Invalid event\n\n#### is_initial(state) -> True | False\n\n#### is_valid(state) -> True | False\n\n#### is_accepted(state) -> True | False\n\n#### is_final(state) -> True | False\n\n#### is_event(event) -> True | False\n\n---\n\n## Usage\n\nCreate a state machine with a blueprint and transition\nfrom the initial state `1` to accepted, final state `2`.\n\n```python\nfrom dfsmpy import StateMachine\n\nmachine = StateMachine({\n \"alphabet\": {1, 2},\n \"initialState\": 1,\n \"validStates\": {1, 2},\n \"acceptedStates\": {2},\n \"finalStates\": {2},\n \"transition\": lambda a, c, e: e\n})\n\nmachine.transition(2)\n```", "description_content_type": "text/markdown", "docs_url": null, "download_url": "", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/jg75/dfsmpy", "keywords": "", "license": "", "maintainer": "", "maintainer_email": "", "name": "dfsmpy", "package_url": "https://pypi.org/project/dfsmpy/", "platform": "", "project_url": "https://pypi.org/project/dfsmpy/", "project_urls": { "Homepage": "https://github.com/jg75/dfsmpy" }, "release_url": "https://pypi.org/project/dfsmpy/0.0.1/", "requires_dist": null, "requires_python": "", "summary": "Deterministic, Finite State Machine.", "version": "0.0.1" }, "last_serial": 5580354, "releases": { "0.0.1": [ { "comment_text": "", "digests": { "md5": "12a6944800d86ebe137dce84f7d938d9", "sha256": "ad64b03a3bc18725362b06d4c2b9e8f07e4a8b466699a6aa5e27b1871be8626a" }, "downloads": -1, "filename": "dfsmpy-0.0.1.tar.gz", "has_sig": false, "md5_digest": "12a6944800d86ebe137dce84f7d938d9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3485, "upload_time": "2019-07-24T23:48:34", "url": "https://files.pythonhosted.org/packages/da/2c/1ba84020d29be5d7183595d91c0c6f70d0d339e5a62074509db62c791557/dfsmpy-0.0.1.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "12a6944800d86ebe137dce84f7d938d9", "sha256": "ad64b03a3bc18725362b06d4c2b9e8f07e4a8b466699a6aa5e27b1871be8626a" }, "downloads": -1, "filename": "dfsmpy-0.0.1.tar.gz", "has_sig": false, "md5_digest": "12a6944800d86ebe137dce84f7d938d9", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3485, "upload_time": "2019-07-24T23:48:34", "url": "https://files.pythonhosted.org/packages/da/2c/1ba84020d29be5d7183595d91c0c6f70d0d339e5a62074509db62c791557/dfsmpy-0.0.1.tar.gz" } ] }