Questions tagged [pytransitions]

Transitions is a lightweight, object-oriented state machine implementation in Python with many extensions.

Transitions is a flexible state machine library compatible with Python 2.7+ and Python 3+. It features extensions such as hierarchical/nested states, state diagrams, state decorators (e.g. Error states or Timeouts), thread-safe and asynchronous machines.

Resources

49 questions
4
votes
1 answer

pytransitions/transitions: Is there any better way to store the history of visited state?

I recently spotted a lightweight, object-oriented state machine implementation in Python called transitions (https://github.com/pytransitions/transitions). So I'm trying to play a bit with these state machines and especially with the…
nghia
  • 43
  • 1
  • 5
3
votes
2 answers

How to define enum of Trigger for `transitions` state machine?

As an unrelated followup to this answer, which isuses the following working code: from transitions import Machine from transitions import EventData from typing import Callable from enum import Enum, auto class Observer: def…
Gulzar
  • 23,452
  • 27
  • 113
  • 201
3
votes
1 answer

No suggestions for triggers when using Pytransitions

Trying to use transitions package as per examples provided here https://github.com/pytransitions/transitions For some reason, neither of the two approaches shown below provide typing suggestions for registered evaporate() trigger (at least in…
2
votes
1 answer

Non deterministic state machine using PyTransitions?

I am using pytransitions and have come across the need to have several states which are unrelated with others, and would make much sense to model using a non deterministic state machine, which is mathematically equivalent. I would like something…
Gulzar
  • 23,452
  • 27
  • 113
  • 201
2
votes
1 answer

How to pass parameters to on_enter callbacks in `transitions` library?

I want to use transitions, and need a rather trivial feature I could not find in the docs, and was wondering if it was implemented: I want to define a on_enter callback on some state, but pass a parameter to that callback. At least to know from…
Gulzar
  • 23,452
  • 27
  • 113
  • 201
2
votes
2 answers

Pytransitions: Is it possible to change what model attribute the machine injects in the model?

I'm retrofitting the pytransitions state machine into an existing model, which happens to already have a column (the model also happens to be a SQLAlchemy model) that is named status. I noticed that the transitions library injects a state field,…
CatarinaPBressan
  • 132
  • 2
  • 13
1
vote
1 answer

Adding and triggering a transition within on_enter state callback

I want to store a previous state A when entering state B using a state history. Later 'on_enter' of another state X, add a transition X->A, trigger it and return to state A. A -> B (store A) -> C -> X (add transition from X to A) -> A from…
romath
  • 13
  • 2
1
vote
1 answer

Is there a way to decorate graphviz (dot/svg) ouput from pytransitions for dynamically created nodes

Consider the "Custom styling" example in cell 11 in this link from the pytransitions github pages. (tweeked code below) I would like to add a reset event. When Reset is triggered from most (but not all) other states the model returns to a known…
Jay M
  • 3,736
  • 1
  • 24
  • 33
1
vote
0 answers

state is not a registered state pytransitions

i am using pytransitions for first time and faced this problem, i am trying to do some states and test it from transitions import Machine class TelegramBot(object): states = ['asleep', 'wait_for_size', …
1
vote
0 answers

Conditional transitions in nested machines

I'm using conditional transitioning in the nested machine. Unfortunately, the condition method has no access to the class attribute self._error. So I have to pass the attribute to the triggering method. This solution work, but I have to take care to…
Jan Krejci
  • 85
  • 8
1
vote
1 answer

Deeper nested transitions

I'm trying to use the hierarchical machine with three nesting levels called main -> nested -> deeper. I would expect, the state machines to be executed one after the other and then the states are remapped back to the first machine. So I would expect…
Jan Krejci
  • 85
  • 8
1
vote
1 answer

How to generate outputs from PyTransitions FSM?

I am using PyTransitions to generate a simple FSM, configuring it using a yml file. An example could be something like this: initial: A states: - A - B - C transitions: - {trigger: "AtoC", source: "A", dest: "C"} - {trigger: "CtoB",…
Mtk59
  • 121
  • 2
1
vote
2 answers

Is it possible to block execution of a trigger if the transition isn't valid?

It appears the trigger methods still run then raise the MachineError exception afterwards when transition is not valid from current state. Is there a way to block the execution of a trigger so that a call to the trigger on the model will simply…
1
vote
2 answers

Handling multiple objects in pytransitions

https://github.com/pytransitions/transitions I was trying with the batman = NarcolepticSuperhero("Batman") example in the documentation. But let's say if we have 100 batmans to handle, My approach is to create a list of every batman object and track…
1
vote
1 answer

TypeError while triggering transition from other thread

I have Controller instantiated in the main thread, spawning its own worker thread, which is processing events from other controllers. The Controller instantiates ProductionMachine, which is the main state machine and it has nested machines…
Jan Krejci
  • 85
  • 8
1
2 3 4