Skip to main content

Finite State Machine

Project description

Finite State Machine

Version Supports Python 3.8+ License

Object-oriented finite state machine implementation using python

Table of Contents

Installation

Download source code and run the following commands to install and uninstall the package:

pip install .
pip uninstall fsm_finite_state_machine

Usage

There are 3 main classes in this package to be used:

  1. State - Contains the definition of the state machine state as a string key
  2. Transition - Contains the definition of a state machine transition, such as transition name, the source state and the destination state
  3. FSM - Is the definition of the Finite State Machine which must be instatiated with the following arguments:
  • model - The entity model which contains the state value, the state value setters and the transition triggers execution methods.
  • states - Its a dictionary of states that the state machine will use to operate
  • transitions - Contains the list of transitions definitions
  • currentStateValue - Corresponds to the initial state or current state values to be passed to the state machine

After defining the states and the transitions the state machine can be used by:

  1. Instantiating a state machine object;
  2. Triggering a state machine transition, so the machine knows to which state it will jump next. In this step it is also possible to pass arguments to be used by the transition trigger methods. These arguments are optional;
  3. And finally by executing the state machine itself, which will execute the transition trigger methods.

Code example:

fsm = FSM(model, STATES, TRANSITIONS, stateValue)
fsm.triggerTransition(transitionName, data1, data2, ...)
fsm.execute()

Examples

Check the following link: examples

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

fsm_finite_state_machine-0.1.0.tar.gz (4.6 kB view details)

Uploaded Source

File details

Details for the file fsm_finite_state_machine-0.1.0.tar.gz.

File metadata

File hashes

Hashes for fsm_finite_state_machine-0.1.0.tar.gz
Algorithm Hash digest
SHA256 91643372cdf3f8e142913751fb3968502628344989bb95c740745f63b3efff7e
MD5 9fb95d9ec1cf4daf3c904cce23f53722
BLAKE2b-256 e851bea5c98d9739cd41251bb8356a6b09ec1c71a239c5ce2a46f1e017be1478

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