{"id":29796450,"url":"https://github.com/calebbell/lazy-state-machine","last_synced_at":"2025-07-28T05:10:03.462Z","repository":{"id":306371230,"uuid":"1025935425","full_name":"CalebBell/lazy-state-machine","owner":"CalebBell","description":"An implementation of a state machine that accepts a general python function","archived":false,"fork":false,"pushed_at":"2025-07-25T05:24:16.000Z","size":48,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":0,"default_branch":"master","last_synced_at":"2025-07-25T09:41:03.940Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":null,"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/CalebBell.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2025-07-25T03:54:57.000Z","updated_at":"2025-07-25T05:24:19.000Z","dependencies_parsed_at":"2025-07-25T09:41:11.150Z","dependency_job_id":"0b6c86bd-7504-4a0d-9a6b-1fe761df8bcf","html_url":"https://github.com/CalebBell/lazy-state-machine","commit_stats":null,"previous_names":["calebbell/lazy-state-machine"],"tags_count":null,"template":false,"template_full_name":null,"purl":"pkg:github/CalebBell/lazy-state-machine","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CalebBell%2Flazy-state-machine","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CalebBell%2Flazy-state-machine/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CalebBell%2Flazy-state-machine/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CalebBell%2Flazy-state-machine/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/CalebBell","download_url":"https://codeload.github.com/CalebBell/lazy-state-machine/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/CalebBell%2Flazy-state-machine/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":267464522,"owners_count":24091505,"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","status":"online","status_checked_at":"2025-07-28T02:00:09.689Z","response_time":68,"last_error":null,"robots_txt_status":"success","robots_txt_updated_at":"2025-07-24T06:49:26.215Z","robots_txt_url":"https://github.com/robots.txt","online":true,"can_crawl_api":true,"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":[],"created_at":"2025-07-28T05:10:02.901Z","updated_at":"2025-07-28T05:10:03.446Z","avatar_url":"https://github.com/CalebBell.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# lazy-state-machine\n\nThis repository contains an implementation of a programmable finite state machine (FSM).\n\nThis implementation accepts a transition function which is a general-purpose Python function.\n\nI chose this approach because while understanding how the rules for a modulus-3 state machine were derived,\nI noticed the rules table grows very quickly with modulus number, and I ran out of\nmemory when I tried to obtain the table for a 64-bit number. The name `lazy-state-machine`\nwas chosen because it allows for rules to be derived on-demand instead of pretabulated.\n\nAccepting a Python function in the FSM also allows for computing nondeterminism.\n\nIn practice accepting a Python function makes the machines hard to analyze,\nand in production code where possible I would want to use a transition table\nand draw it out in a nice diagram.\n\n## Code Structure\n\n* `lazy_state_machine/exceptions.py` - Errors the machine can generate representing various misconfigurations or transition function misbehaviors\n* `lazy_state_machine/lazy_state_machine.py` - The state machine, which is configured on `__init__` and is immutable, accepting inputs through three different functions for different purposes\n* `tests/test_invalid_inputs.py` - Cases where each of the exceptions would be triggered\n* `tests/test_modulus.py` - My first use of the FSM, and where I explored the derivation of modulus rules\n* `tests/test_turnstile.py` - A second example\n* `examples/FSM_modulus_three.py` - A standalone modulus three demonstration\n* `examples/schrodingers_cat.py` - A little fun example of nondeterminism, and a FSM's state after processing a provided input not being in the accepted final states\n\nThe tests provide complete coverage.\n\n## Running Examples\n\nThe examples depend on the `lazy_state_machine` library. Run them from the repository root using `uv`:\n\n```bash\nuv run --with . examples/FSM_modulus_three.py\nuv run --with . examples/schrodingers_cat.py\n```\n\n## Development Setup\n\nTo develop on this library, it can also be installed into the system Python via the traditional approach:\n\n```bash\npip install -e .\n```\n\n## Building and Distribution\n\nThe package can be built as a wheel with `make build` and installed into any other python environment via:\n\n```bash\npip install /path/to/lazy-state-machine/dist/lazy_state_machine-*.tar.gz\n```\n\nIf this were code I was intending on seriously releasing as an open source project, or using commercially, I would continue with the steps in TODO.md.\n\n## Development Tools\n\nI used a tool called cookiecutter to add tooling to this repo according to a predefined template.\nI chose the template [fpgmaas/cookiecutter-uv](https://github.com/fpgmaas/cookiecutter-uv) which\nuses the python package manager uv, to experiment with it.\n\nThe template provides the following options; the coverage I added.\n\n* `make install` - Install the dependencies (they are all development dependencies, no special libraries are needed to use the library)\n* `make check` - Linters (formatting, code smells, typing)\n* `make test` - Testing though pytest\n* `make coverage` - Testing through pytest with code coverage, generated as html in a folder `htmlcov`\n* `make build` - Create a distributable python package (wheel)\n* `make clean-build` - Clean the build files after running `make build`\n\n## Installation Requirements\n\nPlease note that if you don't have `uv` already installed, it can be installed with any of the following on Linux or MacOS:\n\n```bash\ncurl -LsSf https://astral.sh/uv/install.sh | sh\npip install uv\npipx install uv\n```\n\nOn windows it can be installed with:\n\n```powershell\npowershell -ExecutionPolicy ByPass -c \"irm https://astral.sh/uv/install.ps1 | iex\"\n```\n\nIf on windows, make can be installed via instructions on this page:\nhttps://gnuwin32.sourceforge.net/packages/make.htm","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcalebbell%2Flazy-state-machine","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fcalebbell%2Flazy-state-machine","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fcalebbell%2Flazy-state-machine/lists"}