Skip to main content

Basic Finite State Machine (FSM) tools.

Latest release 20220805: Initial PyPI release.

Class FSM

Base class for a finite state machine (FSM).

The allowed states and transitions are defined by the class attribute FSM_TRANSITIONS, a mapping of state->event->new_state.

Each instance has the following attributes:

  • fsm_state: the current state value.
  • fsm_history: an optional iterable of FSMTransitionEvent state transitions recorded by the fsm_event method. Usually this would be None (the default) or a list.

Method FSM.__init__(self, state, *, history=None, lock=None, transitions=None): Initialise the FSM from:

  • state: the initial state
  • history: an optional object to record state transition history, default None; if not None this should be an iterable object with a .append(entry) method such as a list.
  • lock: an optional mutex to control access; if presupplied and shared with the caller it should probably be an RLock; the default is a Lock, which is enough for FSM private use
  • transitions: optional state->event->state mapping; if provided, this will override the class FSM_TRANSITIONS mapping

Class FSMError(builtins.Exception, builtins.BaseException)

An exception associated with an FSM.

These have a .fsm attribute storing an (optional) FSM reference supplied at initialisation.

FSMSubType = ~FSMSubType

Type variable.

Usage::

T = TypeVar('T') # Can be anything A = TypeVar('A', str, bytes) # Must be str or bytes

Type variables exist primarily for the benefit of static type checkers. They serve as the parameters for generic types as well as for generic function definitions. See class Generic for more information on generic types. Generic functions work as follows:

def repeat(x: T, n: int) -> List[T]: '''Return a list containing n references to x.''' return [x]*n

def longest(x: A, y: A) -> A: '''Return the longest of two strings.''' return x if len(x) >= len(y) else y

The latter example's signature is essentially the overloading of (str, str) -> str and (bytes, bytes) -> bytes. Also note that if the arguments are instances of some subclass of str, the return type is still plain str.

At runtime, isinstance(x, T) and issubclass(C, T) will raise TypeError.

Type variables defined with covariant=True or contravariant=True can be used to declare covariant or contravariant generic types. See PEP 484 for more details. By default generic types are invariant in all type variables.

Type variables can be introspected. e.g.:

T.name == 'T' T.constraints == () T.covariant == False T.contravariant = False A.constraints == (str, bytes)

Note that only type variables defined in global scope can be pickled.

Class FSMTransitionEvent(builtins.tuple)

FSMTransitionEvent(old_state, new_state, event, when, extra)

Method FSMTransitionEvent.__new__(_cls, old_state, new_state, event, when, extra): Create new instance of FSMTransitionEvent(old_state, new_state, event, when, extra)

Release Log

Release 20220805: Initial PyPI release.

Metadata

Release files for cs-fsm 20220805

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for cs-fsm 20220805
File Size Uploaded
cs.fsm-20220805.tar.gz 6.5 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for cs-fsm 20220805
File Interpreter ABI Platform
cs.fsm-20220805-py3-none-any.whl Python 3 none any Details

Total release size: 12.6 kB

Release files / cs.fsm-20220805.tar.gz

Download URL cs.fsm-20220805.tar.gz
Size 6.5 kB
Tags Source
SHA-256 checksum
How to use checksums
1f89f542681680d8bad9edcf1c7f1111544b808d2308622a577b095f9ebebc54
BLAKE2b-256 checksum
How to use checksums
3d3669dc948086156c28566d3b9579bc05e699ccfd98ba99254a1e27ca98744f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.1 readme-renderer/30.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.8.2 keyring/23.3.0 rfc3986/1.5.0 colorama/0.4.4 CPython/3.9.13

Release files / cs.fsm-20220805-py3-none-any.whl

Download URL cs.fsm-20220805-py3-none-any.whl
Size 6.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1d8e7411b37e520aa4791b8486534d108c395b394f516286a1524d9b499e6243
BLAKE2b-256 checksum
How to use checksums
65aa7145fd9d2b705c3e40f30ae339c96b337bd53aec85efb248b74c6925cbfb
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/3.8.0 pkginfo/1.8.1 readme-renderer/30.0 requests/2.27.1 requests-toolbelt/0.9.1 urllib3/1.26.7 tqdm/4.62.3 importlib-metadata/4.8.2 keyring/23.3.0 rfc3986/1.5.0 colorama/0.4.4 CPython/3.9.13
Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page