{ "info": { "author": "Sumanau Sareen", "author_email": "finist-python@googlegroups.com", "bugtrack_url": null, "classifiers": [], "description": "Finist\n======\n\nRedis based Finite State Machine.\n\nDescription\n-----------\n\nFinist is a finite state machine that is defined and persisted in\n[Redis][redis].\n\nCommunity\n---------\n\nMeet us on IRC: [#lesscode](irc://chat.freenode.net/#lesscode) on\n[freenode.net](http://freenode.net/).\n\nRelated projects\n----------------\n\n* [Finist implemented in Lua][finist.lua]\n* [Finist implemented in Ruby][finist.lua]\n* [Finist implemented in Rust][finist.ruby]\n\nGetting started\n---------------\n\nInstall [Redis][redis]. On most platforms it's as easy as grabbing\nthe sources, running make and then putting the `redis-server` binary\nin the PATH.\n\nOnce you have it installed, you can execute `redis-server` and it\nwill run on `localhost:6379` by default. Check the `redis.conf`\nfile that comes with the sources if you want to change some settings.\n\nUsage\n-----\n\nFinist requires a Redis [Python Redis] compatible client. To make things\neasier, `redic` is listed as a runtime dependency so the examples\nin this document will work.\n\n```python\nfrom finist import Finist\nimport redis\nredis_conn = redis.Redis()\n\n# Initialize with a Redis client, the name of the machine and the\n# initial state. In this example, the machine is called \"order\" and\n# the initial status is \"pending\". The Redis client is connected to\n# the default host (127.0.0.1:6379).\nmachine = Finist(redis_conn, \"order\", \"pending\")\n\n# Available transitions are defined with the `on` method\n# `machine.on(, , )`\nmachine.on(\"approve\", \"pending\", \"approved\")\nmachine.on(\"cancel\", \"pending\", \"cancelled\")\nmachine.on(\"cancel\", \"approved\", \"cancelled\")\nmachine.on(\"reset\", \"cancelled\", \"pending\")\n```\n\nNow that the possible transitions are defined, we can check the\ncurrent state:\n\n```python\nmachine.state()\n# => \"pending\"\n```\n\nAnd we can trigger an event:\n\n```python\nmachine.trigger(\"approve\")\n# => [\"approved\", true]\n```\n\nThe `trigger` method returns an array of two values: the first\nrepresents the current state, and the second represents whether\na transition occurred.\n\nHere's what happens if an event doesn't cause a transition:\n\n```python\nmachine.trigger(\"reset\")\n# => [\"approved\", false]\n```\n\nHere's a convenient way to use this flag:\n\n```python\nstate, changed = machine.trigger(\"reset\")\n\nif changed\n print \"State changed to %s\\n\" %state\n```\n\nIf you need to remove all the transitions for a given event, you\ncan use `rm`:\n\n```python\nmachine.rm(\"reset\")\n```\n\nNote that every change is persisted in Redis.\n\nRepresentation\n--------------\n\nEach event is represented as a hash in Redis, and its field/value\npairs are the possible transitions.\n\nFor the FSM described in the examples above, the keys are laid out\nas follows:\n\n```ini\n# Current state\nfinist:order (string)\n\n# Transitions for event `approve`\nfinist:order:approve (hash)\n\tpending -> approved\n\n# Transitions for event `cancel`\nfinist:order:cancel (hash)\n\tpending -> cancelled\n\tapproved -> cancelled\n\n# Transitions for event `reset`\nfinist:order:reset (hash)\n\tcancelled -> pending\n```\n\nInstallation\n------------\n\n```\n$ python setup.py install\nor \n$ pip install finist\n```\n\n[redis]: http://redis.io\n[Python Redis]: https://github.com/andymccurdy/redis-py\n[finist.lua]: https://github.com/soveran/finist.lua\n[finist.rust]: https://github.com/badboy/finist\n[finist.ruby]: https://github.com/soveran/finist", "description_content_type": null, "docs_url": null, "download_url": "UNKNOWN", "downloads": { "last_day": -1, "last_month": -1, "last_week": -1 }, "home_page": "https://github.com/sumanau7/finist", "keywords": "redis state machine python", "license": "APACHE", "maintainer": null, "maintainer_email": null, "name": "finist", "package_url": "https://pypi.org/project/finist/", "platform": "UNKNOWN", "project_url": "https://pypi.org/project/finist/", "project_urls": { "Download": "UNKNOWN", "Homepage": "https://github.com/sumanau7/finist" }, "release_url": "https://pypi.org/project/finist/0.1.2/", "requires_dist": null, "requires_python": null, "summary": "Redis based Finite State Machine.", "version": "0.1.2" }, "last_serial": 1652994, "releases": { "0.1.1": [ { "comment_text": "", "digests": { "md5": "fcad002f1d8231afac22f3545bd5b008", "sha256": "2fd88271a4e1da6a7ba948ecb68e562f843f7d3a573f498afe6b3d06e8b9cdfb" }, "downloads": -1, "filename": "finist-0.1.1.tar.gz", "has_sig": false, "md5_digest": "fcad002f1d8231afac22f3545bd5b008", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3410, "upload_time": "2015-07-26T15:43:18", "url": "https://files.pythonhosted.org/packages/1d/81/c13e31f1413c37ad4f8bc2fb425633b56b18a9d702e6905c2875038b1c48/finist-0.1.1.tar.gz" } ], "0.1.2": [ { "comment_text": "", "digests": { "md5": "bbfbca55dea7d2d56f01fd9822e08993", "sha256": "795fc4d9f73e6e0e1af4c151d577f4a7b31bd591cd7163e1a99bb4a17faf2742" }, "downloads": -1, "filename": "finist-0.1.2.tar.gz", "has_sig": false, "md5_digest": "bbfbca55dea7d2d56f01fd9822e08993", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3688, "upload_time": "2015-07-28T10:16:02", "url": "https://files.pythonhosted.org/packages/7e/30/0a1b593e638372de5550f2daf9964f514cf1ab16143db46903070bef0304/finist-0.1.2.tar.gz" } ] }, "urls": [ { "comment_text": "", "digests": { "md5": "bbfbca55dea7d2d56f01fd9822e08993", "sha256": "795fc4d9f73e6e0e1af4c151d577f4a7b31bd591cd7163e1a99bb4a17faf2742" }, "downloads": -1, "filename": "finist-0.1.2.tar.gz", "has_sig": false, "md5_digest": "bbfbca55dea7d2d56f01fd9822e08993", "packagetype": "sdist", "python_version": "source", "requires_python": null, "size": 3688, "upload_time": "2015-07-28T10:16:02", "url": "https://files.pythonhosted.org/packages/7e/30/0a1b593e638372de5550f2daf9964f514cf1ab16143db46903070bef0304/finist-0.1.2.tar.gz" } ] }