No project description provided
This project has been archived.
The maintainers of this project have marked this project as archived. No new releases are expected.
Project description
[!WARNING]
This is a work in progress and is not ready for production use yet. The API and implementation are subject to changes on minor versions.
See the Roadmap for planned features and the Contributing section for ways to contribute.
StateForward
StateForward Python: Simplifying Complexity, One State at a Time.
Explore the docs
View Demo
·
Report Bug
·
Request Feature
Table of Contents
About StateForward Python
StateForward Python is where code complexity meets simplicity. This library is your ally in evolving spaghetti code into elegant, robust state machines. Say goodbye to the dense forest of if-else statements and welcome a world where adding features doesn’t mean unraveling a complex knot.
With StateForward Python, you’re building on solid ground. Your code becomes a clear map of states and transitions, making it easily extendable and a joy to maintain. It's about writing software that grows with grace, ensuring that your project's future is as structured and reliable as its present.
Getting Started
This is an example of how you may give instructions on setting up your project locally. To get a local copy up and running follow these simple example steps.
Installation
Pip
- Install the package
pip install stateforward
Manually
- Clone the repo
git clone https://github.com/stateforward/stateforward_python.git
- Initialize virtual environment
poetry shell
- Install dev dependencies
poetry install
Usage
import stateforward as sf
import asyncio
class OnEvent(sf.Event):
pass
class OffEvent(sf.Event):
pass
class LightSwitch(sf.AsyncStateMachine):
class On(sf.State):
@sf.decorators.behavior
async def entry(self, event: OnEvent):
print("Light on entry")
@sf.decorators.behavior
async def exit(self, event: OffEvent):
print("Light on exit")
class Off(sf.State):
@sf.decorators.behavior
async def entry(self, event: OnEvent):
print("Light off entry")
@sf.decorators.behavior
async def exit(self, event: OffEvent):
print("Light off exit")
initial = sf.initial(Off)
transitions = sf.collection(
sf.transition(OnEvent, source=Off, target=On),
sf.transition(OffEvent, source=On, target=Off),
)
async def main():
# instantiate a light switch
light_switch = LightSwitch()
# start the interpreter and wait for it to be settled
await light_switch.__interpreter__.start()
# output the current states of the state machine
print(light_switch.state)
# dispatch a OnEvent to the state machine
await sf.send(OnEvent(), light_switch)
# output the current states of the state machine
print(light_switch.state)
# dispatch a OffEvent to the state machine
await sf.send(OffEvent(), light_switch)
print(light_switch.state)
asyncio.run(main())
For more examples, please refer to the Documentation
Contributing
Contributions are what make the open source community such an amazing place to learn, inspire, and create. Any contributions you make are greatly appreciated.
If you have a suggestion that would make this better, please fork the repo and create a pull request. You can also simply open an issue with the tag "enhancement". Don't forget to give the project a star! Thanks again!
- Fork the Project
- Create your Feature Branch (
git checkout -b feature/AmazingFeature) - Commit your Changes (
git commit -m 'Add some AmazingFeature') - Push to the Branch (
git push origin feature/AmazingFeature) - Open a Pull Request
License
Distributed under the MIT License. See LICENSE.txt for more information.
Contact
Your Name - @twitter_handle - email@email_client.com
Project Link: https://github.com/github_username/repo_name
Acknowledgments
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file stateforward-0.2.7.tar.gz.
File metadata
- Download URL: stateforward-0.2.7.tar.gz
- Upload date:
- Size: 47.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.5 Darwin/23.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
40da08c00f98618e127c038d4f8b8493835100ef2c3833847743484364c7d515
|
|
| MD5 |
f4ea6aa1fbe0888b7a9c7a748de50b97
|
|
| BLAKE2b-256 |
1ca8ea32d675bf52e8e4de02da7682e961651352e9b769136c4552e55fcf97f1
|
File details
Details for the file stateforward-0.2.7-py3-none-any.whl.
File metadata
- Download URL: stateforward-0.2.7-py3-none-any.whl
- Upload date:
- Size: 62.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.7.1 CPython/3.11.5 Darwin/23.2.0
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f3b4b7eb77f42eb34e7481bb2cb7d0b3b126d810b9b6a66a03bd90b2acd43832
|
|
| MD5 |
11ffebb7e95fe425671fb2fef9ff2403
|
|
| BLAKE2b-256 |
3daf7d9f79a3168108be6cd0060b4699082f76b93eba51c65c88714b03ba9d22
|