# Buildsheet autogenerated by ravenadm tool -- Do not edit. NAMEBASE= python-transitions VERSION= 0.9.2 KEYWORDS= python VARIANTS= v12 v13 SDESC[v12]= Extensible state machine implementation (3.12) SDESC[v13]= Extensible state machine implementation (3.13) HOMEPAGE= https://github.com/pytransitions/transitions CONTACT= Python_Automaton[python@ironwolf.systems] DOWNLOAD_GROUPS= main SITES[main]= PYPIWHL/ec/47/852f96b115425618382472ea06860069da5bb078bdec3e4449f185a40e07 DISTFILE[1]= transitions-0.9.2-py2.py3-none-any.whl:main DIST_SUBDIR= python-src DF_INDEX= 1 SPKGS[v12]= single SPKGS[v13]= single OPTIONS_AVAILABLE= PY312 PY313 OPTIONS_STANDARD= none VOPTS[v12]= PY312=ON PY313=OFF VOPTS[v13]= PY312=OFF PY313=ON DISTNAME= transitions-0.9.2.dist-info GENERATED= yes [PY312].RUN_DEPENDS_ON= python-six:single:v12 [PY312].USES_ON= python:v12,wheel [PY313].RUN_DEPENDS_ON= python-six:single:v13 [PY313].USES_ON= python:v13,wheel [FILE:3186:descriptions/desc.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() [FILE:128:distinfo] f7b40c9b4a93869f36c4d1c33809aeb18cdeeb065fd1adba018ee39c3db216f3 111773 python-src/transitions-0.9.2-py2.py3-none-any.whl