# state-machine
[documentation](https://state-machine.readthedocs.io/en/latest/)
a state machine that can change difference backends (current only redis backend, lately the filelockbackend)
and keep state synchronously in different state even different host.
# Install
```
sudo pip3 install state-machine-2
```
# Quick Start
1. Create a State Backend
```
from state_machine import StateMachine, RedisBackend
from redis import Redis
# you will need to install redis
# see more information here: https://redis.io/download#installation
redis_backend = RedisBackend(con=Redis(decode_responses=True))
```
2. Create a State Machine Class
```
class Job(StateMachine):
backend = redis_backend
def __init__(self, state=None, jobid=None):
self.jobid = jobid
super().__init__(state=state, jobid=jobid)
def __str__(self):
return f"Job: {self.jobid}"
```
3. Use
```
# first progress
>>> job1_0 = Job(jobid=1, state="NEW")
>>> job1_0.state = "STARTED"
# second progress
>>> job1_1 = Job(jobid=1, state="NEW")
>>> job1_1.state = "STARTED"
Error: StateChangedException() # raise Exception because the state has changed by job1_0
```
# test and contribute
```
git clone git@github.com:ramwin/state-machine.git
cd state-machine
pip3 install -e ./
sh test.sh
```
Raw data
{
"_id": null,
"home_page": "https://github.com/ramwin/state-machine",
"name": "state-machine-2",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.7",
"maintainer_email": null,
"keywords": null,
"author": "Xiang Wang",
"author_email": "ramwin@qq.com",
"download_url": "https://files.pythonhosted.org/packages/59/ea/3d8e3d22f2f873c1a4c7e2fe2264c769e16183b0399df11273397ebbf954/state-machine-2-0.2.4.tar.gz",
"platform": null,
"description": "# state-machine\n[documentation](https://state-machine.readthedocs.io/en/latest/) \na state machine that can change difference backends (current only redis backend, lately the filelockbackend) \nand keep state synchronously in different state even different host.\n\n# Install\n```\nsudo pip3 install state-machine-2\n```\n\n# Quick Start\n1. Create a State Backend\n```\nfrom state_machine import StateMachine, RedisBackend\nfrom redis import Redis\n# you will need to install redis\n# see more information here: https://redis.io/download#installation\nredis_backend = RedisBackend(con=Redis(decode_responses=True))\n```\n2. Create a State Machine Class\n```\nclass Job(StateMachine):\n backend = redis_backend\n\n def __init__(self, state=None, jobid=None):\n self.jobid = jobid\n super().__init__(state=state, jobid=jobid)\n\n def __str__(self):\n return f\"Job: {self.jobid}\"\n```\n3. Use\n```\n# first progress\n>>> job1_0 = Job(jobid=1, state=\"NEW\")\n>>> job1_0.state = \"STARTED\"\n# second progress\n>>> job1_1 = Job(jobid=1, state=\"NEW\")\n>>> job1_1.state = \"STARTED\"\nError: StateChangedException() # raise Exception because the state has changed by job1_0\n```\n\n# test and contribute\n```\ngit clone git@github.com:ramwin/state-machine.git\ncd state-machine\npip3 install -e ./\nsh test.sh\n```\n\n\n",
"bugtrack_url": null,
"license": null,
"summary": "a state machine that support multi process",
"version": "0.2.4",
"project_urls": {
"Homepage": "https://github.com/ramwin/state-machine"
},
"split_keywords": [],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "79980fe1cffa58fed826f9097813c437228438ce05ec5237b7c8e987c55f8ece",
"md5": "a4afa87910b90ef43e26ffa086a0e6dc",
"sha256": "d83cdd681e99b252c14cbacca37140c6723199ccddef6057833e3c0011127f18"
},
"downloads": -1,
"filename": "state_machine_2-0.2.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "a4afa87910b90ef43e26ffa086a0e6dc",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.7",
"size": 17636,
"upload_time": "2024-05-06T14:41:54",
"upload_time_iso_8601": "2024-05-06T14:41:54.777896Z",
"url": "https://files.pythonhosted.org/packages/79/98/0fe1cffa58fed826f9097813c437228438ce05ec5237b7c8e987c55f8ece/state_machine_2-0.2.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "59ea3d8e3d22f2f873c1a4c7e2fe2264c769e16183b0399df11273397ebbf954",
"md5": "a228305e49181acbf94bbda4772f1fe1",
"sha256": "cf165cfb5d75960652c3ae1a5fa24842cb0545e0ed17380db622d55c3e374c2d"
},
"downloads": -1,
"filename": "state-machine-2-0.2.4.tar.gz",
"has_sig": false,
"md5_digest": "a228305e49181acbf94bbda4772f1fe1",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.7",
"size": 15970,
"upload_time": "2024-05-06T14:41:56",
"upload_time_iso_8601": "2024-05-06T14:41:56.698642Z",
"url": "https://files.pythonhosted.org/packages/59/ea/3d8e3d22f2f873c1a4c7e2fe2264c769e16183b0399df11273397ebbf954/state-machine-2-0.2.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-05-06 14:41:56",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "ramwin",
"github_project": "state-machine",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"requirements": [
{
"name": "sphinx",
"specs": []
},
{
"name": "sphinx-autobuild",
"specs": []
},
{
"name": "sphinx-design",
"specs": []
},
{
"name": "myst-parser",
"specs": []
},
{
"name": "sphinx-rtd-theme",
"specs": []
},
{
"name": "sphinxcontrib-jquery",
"specs": []
}
],
"lcname": "state-machine-2"
}