Skip to main content
Archived

This project has been archived by its maintainers, and is no longer receiving any updates.

Contributors Forks Stargazers Issues LinkedIn


Logo

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.

(back to top)

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

  1. Install the package
    pip install stateforward
    

Manually

  1. Clone the repo
    git clone https://github.com/stateforward/stateforward_python.git
    
  2. Initialize virtual environment
    poetry shell 
    
  3. Install dev dependencies
    poetry install
    

(back to top)

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

(back to top)

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!

  1. Fork the Project
  2. Create your Feature Branch (git checkout -b feature/AmazingFeature)
  3. Commit your Changes (git commit -m 'Add some AmazingFeature')
  4. Push to the Branch (git push origin feature/AmazingFeature)
  5. Open a Pull Request

(back to top)

License

Distributed under the MIT License. See LICENSE.txt for more information.

(back to top)

Contact

Your Name - @twitter_handle - email@email_client.com

Project Link: https://github.com/github_username/repo_name

(back to top)

Acknowledgments

(back to top)

Metadata

Release files for stateforward 0.2.95

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for stateforward 0.2.95
File Size Uploaded Provenance
stateforward-0.2.95.tar.gz 112.6 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for stateforward 0.2.95
File Interpreter ABI Platform
stateforward-0.2.95-py3-none-any.whl Python 3 none any Details

Total release size: 245.6 kB

Release files / stateforward-0.2.95.tar.gz

Download URL stateforward-0.2.95.tar.gz
Size 112.6 kB
Tags Source
SHA-256 checksum
How to use checksums
4b2b8566df68363a082f90100f8dbc1bb2a0d3150fbcfd464ebc4f08406a84c7
BLAKE2b-256 checksum
How to use checksums
640be4bcb5c28842d551bd9f5e555ffd29e3616d7e6d392c164f08661211ca4f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.5 Darwin/23.2.0

Release files / stateforward-0.2.95-py3-none-any.whl

Download URL stateforward-0.2.95-py3-none-any.whl
Size 133.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
7b007342b9604c4c09622897b40b4610f4ba3446568a050a6fc41004848504ed
BLAKE2b-256 checksum
How to use checksums
21ef41d4e9ce21a2afe2340936821c6e44c301b83d86d40002e9d9e5b838348d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.7.1 CPython/3.11.5 Darwin/23.2.0

Security for stateforward 0.2.95

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page