python-transitions
Port variant py310
Summary Extensible state machine implementation (3.10)
Package version 0.9.0
Homepage https://github.com/pytransitions/transitions
Keywords python
Maintainer Python Automaton
License Not yet specified
Other variants v11
Ravenports Buildsheet | History
Ravensource Port Directory | History
Last modified 23 JAN 2023, 06:04:31 UTC
Port created 07 JAN 2023, 04:18:24 UTC
Subpackage Descriptions
single ## Quickstart They say [a good example is worth] 100 pages of API documentation, a million directives, or a thousand words. Well, "they" probably lie... but here's an example anyway: ```python from transitions import Machine import random class NarcolepticSuperhero(object): # Define some states. Most of the time, narcoleptic superheroes are just like # everyone else. Except for... states = ['asleep', 'hanging out', 'hungry', 'sweaty', 'saving the world'] def __init__(self, name): # No anonymous superheroes on my watch! Every narcoleptic superhero gets # a name. Any name at all. SleepyMan. SlumberGirl. You get the idea. self.name = name # What have we accomplished today? self.kittens_rescued = 0 # Initialize the state machine self.machine = Machine(model=self, states=NarcolepticSuperhero.states, initial='asleep') # Add some transitions. We could also define these using a static list of # dictionaries, as we did with states above, and then pass the list to # the Machine initializer as the transitions= argument. # At some point, every superhero must rise and shine. self.machine.add_transition(trigger='wake_up', source='asleep', dest='hanging out') # Superheroes need to keep in shape. self.machine.add_transition('work_out', 'hanging out', 'hungry') # Those calories won't replenish themselves! self.machine.add_transition('eat', 'hungry', 'hanging out') # Superheroes are always on call. ALWAYS. But they're not always # dressed in work-appropriate clothing. self.machine.add_transition('distress_call', '*', 'saving the world', before='change_into_super_secret_costume') # When they get off work, they're all sweaty and disgusting. But before # they do anything else, they have to meticulously log their latest # escapades. Because the legal department says so. self.machine.add_transition('complete_mission', 'saving the world', 'sweaty', after='update_journal') # Sweat is a disorder that can be remedied with water. # Unless you've had a particularly long day, in which case... bed time! self.machine.add_transition('clean_up', 'sweaty', 'asleep', conditions=['is_exhausted']) self.machine.add_transition('clean_up', 'sweaty', 'hanging out') # Our NarcolepticSuperhero can fall asleep at pretty much any time. self.machine.add_transition('nap', '*', 'asleep') def update_journal(self): """ Dear Diary, today I saved Mr. Whiskers. Again. """ self.kittens_rescued += 1 @property def is_exhausted(self): """ Basically a coin toss. """ return random.random() < 0.5 def change_into_super_secret_costume(self): print("Beauty, eh?") ``` There, now you've baked a state machine into `NarcolepticSuperhero`. Let's take him/her/it out for a spin... ```python >>> batman = NarcolepticSuperhero("Batman") >>> batman.state 'asleep' >>> batman.wake_up() >>> batman.state 'hanging out' >>> batman.nap()
Configuration Switches (platform-specific settings discarded)
PY310 ON Build using Python 3.10 PY311 OFF Build using Python 3.11
Package Dependencies by Type
Build (only) python-pip:single:py310
autoselect-python:single:standard
Build and Runtime python310:single:standard
Runtime (only) python-six:single:py310
Download groups
main mirror://PYPIWHL/ee/35/77e8f975da682e14e1581ae0f47f4e3beed29871794f26ce7c9d4dd32b14
Distribution File Information
5687ee8c6a3200830e44f988d16b0045f53293f7a873002d7bff70852331a078 97706 transitions-0.9.0-py2.py3-none-any.whl
Ports that require python-transitions:py310
python-junos-eznc:py310 Junos 'EZ' automation for non-programmers (3.10)