A more intuitive way to create finite automata diagrams.
Project description
finiteautomata
Craft beautiful, minimalistic finite automata diagrams with intuitiive Python syntax and a purpose-built rendering engine.
Features
- Define start, accept, and intermediate states with chainable calls.
- Render with an automata-first layout engine: orthogonal connectors, grouped transitions, and modern styling.
- Export to SVG, PNG, and interactive HTML in one call.
- Customize the look & feel through theming and spacing controls.
Installation
pip install finiteautomata
or:
pip install finiteautomata[cairo]
if you want to use PNG support.
Quickstart
from finiteautomata import FiniteAutomata
fsm = FiniteAutomata()
fsm.start('q0').accept('q2')
fsm.transition('q0', 'a', 'q1')
fsm.transition('q1', 'a', 'q1') # self-loop
fsm.transition('q1', 'b', 'q1')
fsm.transition('q1', 'a', 'q2')
fsm.draw('demo') # writes demo.svg by default
Rendering multiple formats
fsm.configure_renderer(formats=('svg', 'html', 'png'))
# supply a theme for this render only.
from finiteautomata import RendererTheme
noir = RendererTheme(
background_color="#0f172a",
state_fill="#1e293b",
state_border="#e2e8f0",
accept_state_border="#38bdf8",
transition_color="#38bdf8",
transition_text_color="#38bdf8",
state_text_color="#e2e8f0",
start_indicator_color="#38bdf8",
)
outputs = fsm.draw('demo', view=True, theme=noir)
print(outputs) # {'svg': 'demo.svg', 'html': 'demo.html', 'png': 'demo.png'}
API Reference
-
state(state: str)
Adds a state to the automaton and returns the instance for chaining. -
start(state: str)
Sets (and implicitly creates) the starting state. -
accept(state: str)
Marks a state as accepting. Accept states are rendered with a dual ring. -
transition(from_state: str, symbol: str, to_state: str)
Adds a transition. Multiple transitions between the same pair are automatically grouped, and self-loops are supported out of the box. -
configure_renderer(...)
Adjust default export formats, theming, and layout spacing. -
draw(filename: str = 'fsm', *, format: Optional[str] = None, formats: Optional[Iterable[str]] = None, view: bool = False, theme: Optional[RendererTheme] = None)
Renders the automaton.formatsoverrides the configured default (e.g.('svg', 'html')). Useview=Trueto open the first generated artifact automatically.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distributions
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file finiteautomata-1.2.0-py3-none-any.whl.
File metadata
- Download URL: finiteautomata-1.2.0-py3-none-any.whl
- Upload date:
- Size: 8.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.11.4
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6265c353a4755ff5ff83f9e01306cf0d121ca1cb8ec7e16433cb7585f9c0b283
|
|
| MD5 |
2f8d4c2119f8a9fd676cdc0baf85dbf0
|
|
| BLAKE2b-256 |
0f9c8632c8bc2abd4709396723c4c872dd5b92e6e80496b89c690578b1def4e8
|