No project description provided
Project description
GenStates
GenStates is an implentation of state machine, with genruler as the rule engine.
Usage
from genstates import Machine
import yaml
with open('schema.yaml') as file_schema:
machine = Machine(yaml.safe_load(file_schema))
Fetching states
- Get initial state by
machine.initial
- Get any state by
machine.states[$key]
where$key
is the key for the state
Fetching transitions
- Get all possible transitions for a given
state
bytransitions = machine.get_transitions(state)
- Get a specific transition for a given
state
bytransition = machine.get_transition(state, transition_key)
Progressing from one state to another
- If you have a known transition, pass in a context dictionary that the rule understands
transition.check_condition(context)
- If you are not sure about the destination, use
.progress()
Note that if multiple transitions are possible it will result in an errordestination_state = machine.progress(current_state, context)
Schema
Assuming you are storing the transition as a YAML
machine:
initial_state: $initial_state
states:
$state_key: # can have many states
name: $state_name
transitions: # can have many transitions
$transition_key:
name: $transition_name
destination: $transition_destination
rule: $transition_rule
where:
$initial_state
: a state key value, must be defined in thestates
section$state_key
: a unique key for the statestate_name
: a descriptive name for the state$transition_key
: a unique key for the transition$transition_destination
: a state key value, must be defined in the states section, pointing back to the same state is allowed$transition_name
: a descriptive name for the transition$transition_rule
: a rule that has to returnTrue
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
genstates-0.1.2.tar.gz
(3.7 kB
view details)
Built Distribution
File details
Details for the file genstates-0.1.2.tar.gz
.
File metadata
- Download URL: genstates-0.1.2.tar.gz
- Upload date:
- Size: 3.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.11.0-8-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 8f39f6f8d519cbd6b5c287affcd45e0f7fef9f7626a790be8bbd25d8f9cff048 |
|
MD5 | 9d0dbd77afc9b12fbbcd21c5da195cf9 |
|
BLAKE2b-256 | d486dc89ebfb379580b320ec936f23b8ff4928db31c175da31168c8cfd5f3777 |
File details
Details for the file genstates-0.1.2-py3-none-any.whl
.
File metadata
- Download URL: genstates-0.1.2-py3-none-any.whl
- Upload date:
- Size: 4.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.4 CPython/3.12.7 Linux/6.11.0-8-generic
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 41055a7f261e647d9a8a11e204f166e15ccc72bcf10ef85f4d370c6a7ef4c1c0 |
|
MD5 | 691612fe883b88ebee3f8da97afd2d67 |
|
BLAKE2b-256 | 046ef5076a2ad1321909800d69a518d917b487f51890e2f6fb3e07214c391f36 |