python-Automat
Port variant py38
Summary Self-service finite-state machines (PY38)
Package version 20.2.0
Homepage https://github.com/glyph/Automat
Keywords python
Maintainer Python Automaton
License Not yet specified
Other variants py39
Ravenports Buildsheet | History
Ravensource Port Directory | History
Last modified 28 FEB 2021, 16:29:36 UTC
Port created 28 FEB 2021, 16:29:36 UTC
Subpackage Descriptions
single Automat ======= :alt: Documentation Status :alt: Build Status :alt: Coverage Status Self-service finite-state machines for the programmer on the go. ---------------------------------------------------------------- Automat is a library for concise, idiomatic Python expression of finite-state automata (particularly deterministic finite-state transducers). Read more here, or on [Read the Docs]\ , or watch the following videos for an overview and presentation Overview and presentation by **Glyph Lefkowitz** at the first talk of the first Pyninsula meetup, on February 21st, 2017: :alt: Glyph Lefkowitz - Automat - Pyninsula #0 Presentation by **Clinton Roy** at PyCon Australia, on August 6th 2017: :alt: Clinton Roy - State Machines - Pycon Australia 2017 Why use state machines? ^^^^^^^^^^^^^^^^^^^^^^^ Sometimes you have to create an object whose behavior varies with its state, but still wishes to present a consistent interface to its callers. For example, let's say you're writing the software for a coffee machine. It has a lid that can be opened or closed, a chamber for water, a chamber for coffee beans, and a button for "brew". There are a number of possible states for the coffee machine. It might or might not have water. It might or might not have beans. The lid might be open or closed. The "brew" button should only actually attempt to brew coffee in one of these configurations, and the "open lid" button should only work if the coffee is not, in fact, brewing. With diligence and attention to detail, you can implement this correctly using a collection of attributes on an object; has_water\ , has_beans\ , is_lid_open and so on. However, you have to keep all these attributes consistent. As the coffee maker becomes more complex - perhaps you add an additional chamber for flavorings so you can make hazelnut coffee, for example - you have to keep adding more and more checks and more and more reasoning about which combinations of states are allowed. Rather than adding tedious 'if' checks to every single method to make sure that each of these flags are exactly what you expect, you can use a state machine to ensure that if your code runs at all, it will be run with all the required values initialized, because they have to be called in the order you declare them. You can read about state machines and their advantages for Python programmers in considerably more detail [in this excellent series of articles from ClusterHQ]. What makes Automat different? ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ There are [dozens of libraries on PyPI implementing state machines]. So it behooves me to say why yet another one would be a good idea. Automat is designed around this principle: while organizing your code around state machines is a good idea, your callers don't, and shouldn't have to, care that you've done so. In Python, the "input" to a stateful system is a method call; the "output" may be a method call, if you need to invoke a side effect, or a return value, if you are just performing a computation in memory. Most other state-machine libraries require you to explicitly create an input object, provide that object to a generic "input" method, and then receive results, sometimes in terms of that library's interfaces and sometimes in terms of classes you define yourself. For example, a snippet of the coffee-machine example above might be implemented as follows in naive Python: .. code-block:: python
Configuration Switches (platform-specific settings discarded)
PY38 ON Build using Python 3.8 PY39 OFF Build using Python 3.9
Package Dependencies by Type
Build (only) python-pip:single:py38
autoselect-python:single:standard
Build and Runtime python38:single:standard
Runtime (only) python-attrs:single:py38
python-six:single:py38
Download groups
main mirror://PYPIWHL/dd/83/5f6f3c1a562674d65efc320257bdc0873ec53147835aeef7762fe7585273
Distribution File Information
b6feb6455337df834f6c9962d6ccf771515b7d939bca142b29c20c2376bc6111 31803 Automat-20.2.0-py2.py3-none-any.whl
Ports that require python-Automat:py38
python-Twisted:py38 Asynchronous networking framework (PY38)