Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/frodsan/chappie
Minimal Finite State Machine
https://github.com/frodsan/chappie
minimalist python state-machine
Last synced: 19 days ago
JSON representation
Minimal Finite State Machine
- Host: GitHub
- URL: https://github.com/frodsan/chappie
- Owner: frodsan
- License: mit
- Created: 2016-05-31T10:36:42.000Z (over 8 years ago)
- Default Branch: master
- Last Pushed: 2016-06-01T15:12:53.000Z (over 8 years ago)
- Last Synced: 2024-12-10T03:53:18.177Z (about 1 month ago)
- Topics: minimalist, python, state-machine
- Language: Python
- Homepage:
- Size: 1.95 KB
- Stars: 1
- Watchers: 1
- Forks: 0
- Open Issues: 0
-
Metadata Files:
- Readme: README.md
- License: LICENSE
Awesome Lists containing this project
README
chappie
=======A minimal Finite State Machine library.
Ported from [soveran/micromachine](https://github.com/soveran/micromachine).
Installation
------------```
$ pip install chappie
```Usage
-----```python
from chappie import Machine# Setting an initial state
machine = Machine.new("new")# Define the possible transitions
machine.when("confirm", {"new": "confirmed"})
machine.when("ignore", {"new": "ignored"})
machine.when("reset", {"confirmed": "new", "ignored": "new"})# Trigger events
machine.trigger("confirm") # => True
machine.state # => "confirmed"machine.trigger("ignore") # => False
machine.state # => "confirmed"machine.trigger("reset") # => True
machine.state # => "new"# Includes support for callbacks
def on_ignore
print("Don't laugh, I'm being cool")def on_any
print("I'm consciousness. I'm alive. I'm Chappie")machine.on("ignored", on_ignore)
machine.on("any", on_any)machine.trigger("ignore")
# => "Don't laugh, I'm being cool"
# => "I'm consciousness. I'm alive. I'm Chappie"machine.state
# => "ignored"
```License
-------Released under the [MIT License](http://www.opensource.org/licenses/MIT).