Skip to content

Tags: fgmacedo/python-statemachine

Tags

v2.5.0

Toggle v2.5.0's commit message
typo: Fix package email metadata

latest

Toggle latest's commit message
typo: Fix package email metadata

v2.4.0

Toggle v2.4.0's commit message
*November 5, 2024*

This release introduces powerful new features for the `StateMachine`
library: {ref}`Condition expressions` and explicit definition of
{ref}`Events`. These updates make it easier to define complex transition
conditions and enhance performance, especially in workflows with nested
or recursive event structures.

StateMachine 2.4.0 supports Python 3.7, 3.8, 3.9, 3.10, 3.11, 3.12, and
3.13.

This release introduces support for conditionals with Boolean algebra.
You can now use expressions like `or`, `and`, and `not` directly within
transition conditions, simplifying the definition of complex state
transitions. This allows for more flexible and readable condition setups
in your state machine configurations.

Example (with a spoiler of the next highlight):

```py
>>> from statemachine import StateMachine, State, Event

>>> class AnyConditionSM(StateMachine):
...     start = State(initial=True)
...     end = State(final=True)
...
...     submit = Event(
...         start.to(end, cond="used_money or used_credit"),
...         name="finish order",
...     )
...
...     used_money: bool = False
...     used_credit: bool = False

>>> sm = AnyConditionSM()
>>> sm.submit()
Traceback (most recent call last):
TransitionNotAllowed: Can't finish order when in Start.

>>> sm.used_credit = True
>>> sm.submit()
>>> sm.current_state.id
'end'

```

```{seealso}
See {ref}`Condition expressions` for more details or take a look at the
{ref}`sphx_glr_auto_examples_lor_machine.py` example.
```

Now you can explicit declare {ref}`Events` using the {ref}`event` class.
This allows custom naming, translations, and also helps your IDE to know
that events are callable.

```py
>>> from statemachine import StateMachine, State, Event

>>> class StartMachine(StateMachine):
...     created = State(initial=True)
...     started = State(final=True)
...
...     start = Event(created.to(started), name="Launch the machine")
...
>>> [e.id for e in StartMachine.events]
['start']
>>> [e.name for e in StartMachine.events]
['Launch the machine']
>>> StartMachine.start.name
'Launch the machine'

```

```{seealso}
See {ref}`Events` for more details.
```

We removed a note from the docs saying to avoid recursion loops. Since
the {ref}`StateMachine 2.0.0` release we've turned the RTC model enabled
by default, allowing nested events to occour as all events are put on an
internal queue before being executed.

```{seealso}
See {ref}`sphx_glr_auto_examples_recursive_event_machine.py` for an
example of an infinite loop state machine declaration using `after`
action callback to call the same event over and over again.

```

- Fixes
  [#484](#484)
issue where nested events inside loops could leak memory by incorrectly
  referencing previous `event_data` when queuing the next event. This
fix improves performance and stability in event-heavy workflows.

v2.3.6

Toggle v2.3.6's commit message
*September 11, 2024*

- Fixes
  [#474](#474)
install with extra was not working to install `pydot`.
- Fixes
  [#480](#480)
error when trying to trigger an event inside the initial callback.

v2.3.5

Toggle v2.3.5's commit message
*September 9, 2024*

Added Python 3.13 on the test matrix. StateMachine 2.3.5 supports Python
3.7, 3.8, 3.9, 3.10, 3.11, 3.12 and 3.13.

- Fixes
  [#469](#469)
compatibility with pydot 3.0.0+.
- Fixes
  [#473](#473)
property support for type checking.

v2.3.4

Toggle v2.3.4's commit message
*July 11, 2024*

- Fixes
  [#465](#465)
regression that caused exception when registering a listener with
unbounded callbacks.

v2.3.3

Toggle v2.3.3's commit message
*July 3, 2024*

- Fixes
  [#457](#457)
regression that caused backwards incomplatible changes when using Enums.
Thanks [@hperrey](https://github.com/hperrey)!

Deprecations that will be removed on the next major release:

- The `States.from_enum(..., use_enum_instance=True)` will be the
  default.

```{seealso}
See {ref}`States from Enum types` for more details.
```

v2.3.2

Toggle v2.3.2's commit message
*July 01, 2024*

Observers are now rebranded to {ref}`listeners`. With expanted support
for adding listeners when
instantiating a state machine. This allows covering more use cases. We
also improved the async support.

v2.3.1

Toggle v2.3.1's commit message
*June 10, 2024*

- Fixes
  [#443](#443)
regression that caused `RuntimeError` when running SM with threads.
Thanks [@gwidion](https://x.com/gwidion)!

v2.3.0

Toggle v2.3.0's commit message
*June 7, 2024*

This release has a high expected feature, we're adding [asynchronous
support](../async.md), and enhancing overall functionality. In fact, the
approach we took was to go all the way down changing the internals of
the library to be fully async, keeping only the current external API as
a thin sync/async adapter.

StateMachine 2.3.0 supports Python 3.7, 3.8, 3.9, 3.10, 3.11 and 3.12.

We've fixed a bug on the package declaration that was preventing users
from Python 3.7 to install the latest version.

This release introduces native coroutine support using asyncio, enabling
seamless integration with asynchronous code.

Now you can send and await for events, and also write async
{ref}`Actions`, {ref}`Conditions` and {ref}`Validators`.

```{seealso}
See {ref}`sphx_glr_auto_examples_air_conditioner_machine.py` for an
example of
async code with a state machine.
```

```py
>>> class AsyncStateMachine(StateMachine):
...     initial = State('Initial', initial=True)
...     final = State('Final', final=True)
...
...     advance = initial.to(final)

>>> async def run_sm():
...     sm = AsyncStateMachine()
...     await sm.advance()
...     print(sm.current_state)

>>> asyncio.run(run_sm())
Final

```