{"id":18257905,"url":"https://github.com/linkdd/easy_fsm","last_synced_at":"2025-04-08T22:46:49.342Z","repository":{"id":57673875,"uuid":"482372804","full_name":"linkdd/easy_fsm","owner":"linkdd","description":"Easy to implement Finite State Machines","archived":false,"fork":false,"pushed_at":"2022-04-17T00:10:17.000Z","size":16,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":2,"default_branch":"main","last_synced_at":"2025-03-25T09:15:19.338Z","etag":null,"topics":["easy","finite-state-machine","python"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/linkdd.png","metadata":{"files":{"readme":"README.rst","changelog":null,"contributing":null,"funding":null,"license":"LICENSE.txt","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null}},"created_at":"2022-04-16T22:16:29.000Z","updated_at":"2022-04-16T23:49:26.000Z","dependencies_parsed_at":"2022-08-31T11:20:29.678Z","dependency_job_id":null,"html_url":"https://github.com/linkdd/easy_fsm","commit_stats":null,"previous_names":[],"tags_count":2,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdd%2Feasy_fsm","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdd%2Feasy_fsm/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdd%2Feasy_fsm/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/linkdd%2Feasy_fsm/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/linkdd","download_url":"https://codeload.github.com/linkdd/easy_fsm/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":247941719,"owners_count":21022037,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["easy","finite-state-machine","python"],"created_at":"2024-11-05T10:28:07.000Z","updated_at":"2025-04-08T22:46:49.322Z","avatar_url":"https://github.com/linkdd.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"easy_fsm\n========\n\nEasy to implement Finite State Machines.\n\n.. image:: https://img.shields.io/pypi/l/easy_fsm.svg?style=flat-square\n   :target: https://pypi.python.org/pypi/easy_fsm/\n   :alt: License\n\n.. image:: https://img.shields.io/pypi/status/easy_fsm.svg?style=flat-square\n   :target: https://pypi.python.org/pypi/easy_fsm/\n   :alt: Development Status\n\n.. image:: https://img.shields.io/pypi/v/easy_fsm.svg?style=flat-square\n   :target: https://pypi.python.org/pypi/easy_fsm/\n   :alt: Latest release\n\n.. image:: https://img.shields.io/pypi/pyversions/easy_fsm.svg?style=flat-square\n   :target: https://pypi.python.org/pypi/easy_fsm/\n   :alt: Supported Python versions\n\n.. image:: https://img.shields.io/pypi/implementation/easy_fsm.svg?style=flat-square\n   :target: https://pypi.python.org/pypi/easy_fsm/\n   :alt: Supported Python implementations\n\n.. image:: https://img.shields.io/pypi/wheel/easy_fsm.svg?style=flat-square\n   :target: https://pypi.python.org/pypi/easy_fsm\n   :alt: Download format\n\n.. image:: https://img.shields.io/github/workflow/status/linkdd/easy_fsm/run-test-suite?style=flat-square\n   :target: https://github.com/linkdd/easy_fsm/actions/workflows/test-suite.yml\n   :alt: Build Status\n\n.. image:: https://img.shields.io/pypi/dm/easy_fsm.svg?style=flat-square\n   :target: https://pypi.python.org/pypi/easy_fsm/\n   :alt: Downloads\n\nIntroduction\n------------\n\n**easy_fsm** provides a very simple API to build finite state machines.\n\nThe state machine holds a context that is passed to the different states.\n\nEach state returns either the next state to execute or `None` if the execution\nis done.\n\nThis allows you to implement business logic in small, well separated, chunks of\ncode.\n\nExample\n-------\n\n.. code-block:: python\n\n   from typing import Optional\n   from easy_fsm import StateMachine, State\n   from dataclasses import dataclass, field\n\n\n   @dataclass\n   class Stats:\n       altitude: int = 0\n       fly_time: int = 0\n       suite: list[int] = field(default_factory=list)\n\n\n   class ComputeSyracuse(State[Stats]):\n       def __init__(self, n: int):\n           self.n = n\n\n       def run(self, context: Stats) -\u003e Optional[State[Stats]]:\n           context.altitude = max(context.altitude, self.n)\n           context.fly_time += 1\n           context.suite.append(self.n)\n\n           if self.n == 1:\n               return None\n\n           elif self.n % 2 == 0:\n               return ComputeSyracuse(self.n // 2)\n\n           else:\n               return ComputeSyracuse(3 * self.n + 1)\n\n\n   class Syracuse(StateMachine[Stats]):\n       def __init__(self):\n           super().__init__(Stats())\n\n       def compute(self, n: int) -\u003e None:\n           self.run_from(ComputeSyracuse(n))\n\n\n   def test_fsm():\n       fsm = Syracuse()\n       fsm.compute(5)\n\n       assert fsm.context.altitude == 16\n       assert fsm.context.fly_time == 6\n       assert fsm.context.suite == [5, 16, 8, 4, 2, 1]\n\n\nLicense\n-------\n\nThis project is released under the terms of the `MIT License`_.\n\n.. _MIT License: https://github.com/linkdd/easy_fsm/blob/main/LICENSE.txt\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinkdd%2Feasy_fsm","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Flinkdd%2Feasy_fsm","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Flinkdd%2Feasy_fsm/lists"}