Skip to main content

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 by
    transitions = machine.get_transitions(state)
    
  • Get a specific transition for a given state by
    transition = 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()
    destination_state = machine.progress(current_state, context)
    
    Note that if multiple transitions are possible it will result in an error

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 the states section
  • $state_key: a unique key for the state
  • state_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 return True

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.1.tar.gz (3.4 kB view details)

Uploaded Source

Built Distribution

genstates-0.1.1-py3-none-any.whl (3.9 kB view details)

Uploaded Python 3

File details

Details for the file genstates-0.1.1.tar.gz.

File metadata

  • Download URL: genstates-0.1.1.tar.gz
  • Upload date:
  • Size: 3.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.6 Linux/6.11.0-8-generic

File hashes

Hashes for genstates-0.1.1.tar.gz
Algorithm Hash digest
SHA256 8b9cc3474d554b9e26c89fcbda9d1f8c5e4432de6c30f2785cac4c988694f8f0
MD5 2e91928c8df9c43ab939c4f5334c4614
BLAKE2b-256 db5299232415891e2a4469ae08eeaa6877e487f1316449975f8d9cf792418901

See more details on using hashes here.

File details

Details for the file genstates-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: genstates-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 3.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.4 CPython/3.12.6 Linux/6.11.0-8-generic

File hashes

Hashes for genstates-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 9dbab46cbd92e32d522e9d4990a453caa919bd950ccff73ac7ac4863dad0e2ed
MD5 b2ed089862857a191eaad585f4881676
BLAKE2b-256 98a45b5d755119994e4791176ff7e5bfa43f916a53edef74101d03e15af6e9df

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page