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

Uploaded Source

Built Distribution

genstates-0.1.2-py3-none-any.whl (4.1 kB view details)

Uploaded Python 3

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

Hashes for genstates-0.1.2.tar.gz
Algorithm Hash digest
SHA256 8f39f6f8d519cbd6b5c287affcd45e0f7fef9f7626a790be8bbd25d8f9cff048
MD5 9d0dbd77afc9b12fbbcd21c5da195cf9
BLAKE2b-256 d486dc89ebfb379580b320ec936f23b8ff4928db31c175da31168c8cfd5f3777

See more details on using hashes here.

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

Hashes for genstates-0.1.2-py3-none-any.whl
Algorithm Hash digest
SHA256 41055a7f261e647d9a8a11e204f166e15ccc72bcf10ef85f4d370c6a7ef4c1c0
MD5 691612fe883b88ebee3f8da97afd2d67
BLAKE2b-256 046ef5076a2ad1321909800d69a518d917b487f51890e2f6fb3e07214c391f36

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