Movatterモバイル変換


[0]ホーム

URL:


Skip to content

Navigation Menu

Sign in
Appearance settings

Search code, repositories, users, issues, pull requests...

Provide feedback

We read every piece of feedback, and take your input very seriously.

Saved searches

Use saved searches to filter your results more quickly

Sign up
Appearance settings

Versatile and flexible Python State Machine library

License

NotificationsYou must be signed in to change notification settings

pgularski/pysm

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

pysm - Python State Machine

Versatile and flexible Python State Machine library.

https://travis-ci.org/pgularski/pysm.svg?branch=masterhttps://coveralls.io/repos/github/pgularski/pysm/badge.svg?branch=masterhttps://api.codacy.com/project/badge/Grade/6f18f01639c242a0b83280a52245539dCode HealthDocumentation Status

Implement simple and complex state machines

It can do simple things like this:

https://cloud.githubusercontent.com/assets/3026621/15031178/bf5efb2a-124e-11e6-9748-0b5a5be60a30.png

Or somewhat more complex like that:

https://cloud.githubusercontent.com/assets/3026621/15031148/ad955f06-124e-11e6-865e-c7e3340f14cb.png

Python State Machine

The State Patternsolves many problems, untangles the code and saves one's sanity.Yet.., it's a bit rigid and doesn't scale. The goal of this library is to giveyou a close to the State Pattern simplicity with much more flexibility. And,if needed, the full state machine functionality, includingFSM,HSM,PDA and other tasty things.

Goals

  • Provide a State Pattern-like behavior with more flexibility (seeDocumentation forexamples)
  • Be explicit and don't add any magic code to objects that use pysm
  • Handle directly any kind of event or input (not only strings) - parsingstrings is cool again!
  • Keep it simple, even for someone who's not very familiar with the FSMterminology

Features

  • Finite State Machine (FSM)
  • Hierarchical State Machine (HSM) with Internal/External/Local transitions
  • Pushdown Automaton (PDA)
  • Transition callbacks - action, before, after
  • State hooks - enter, exit, and other event handlers
  • Entry and exit actions are associated with states, not transitions
  • Events may be anything as long as they're hashable
  • States history and transition to previous states
  • Conditional transitions (if/elif/else-like logic)
  • Explicit behaviour (no method or attribute is added to the object containing a state machine)
  • No need to extend a class with State Machine class (composition over inheritance)
  • Fast (even with hundreds of transition rules)
  • Not too many pythonisms, so that it's easily portable to other languages (ie.JavaScript).
  • Micropython support

Installation

Install pysm fromPyPI:

pip install pysm

or clone theGithub pysm repository:

git clone https://github.com/pgularski/pysmcd pysmpython setup.py install

Documentation

Read the docs for API documentation and examples -http://pysm.readthedocs.io/

See Unit Tests to see it working and extensively tested.

Micropython support

The library works with pyboards!:

import upipupip.install('upysm')

Links


[8]ページ先頭

©2009-2025 Movatter.jp