pytransitions / transitions

A lightweight, object-oriented finite state machine implementation in Python with many extensions
MIT License
5.49k stars 524 forks source link

Serialize and deserialize the state machine to a dictionary #483

Closed thedrow closed 3 years ago

thedrow commented 3 years ago

If I want to serialize and deserialize the state machine and its current state(s) we need a way to transform the Machine object to a dict and initialize a Machine from a dict.

aleneum commented 3 years ago

That's what MarkupMachine is doing. It's used for Graphviz and communication in the transitions-gui project. There is a small example in the FAQs.

aleneum commented 3 years ago

Did you check the FAQ?

thedrow commented 3 years ago

Yes, I just did. Is there a way to mixin this class to the other variants?

aleneum commented 3 years ago

Since GraphMachine extends MarkupMachine (that's the only reason why I mentioned Graphviz) I'd say that you can combine MarkupMachine with all the other extensions. You can have a look at factory.py in extensions to see which combinations are currently tested.

thedrow commented 3 years ago

It's not clear from the README though.

thedrow commented 3 years ago

I'll close this for now.