Skip to main content

Python CI codecov PyPI

Lire en français


fsm-tools

A formal Python library for modelling automata in the Chomsky hierarchy.

Overview

fsm-tools provides a rigorous implementation of the four automaton families defined by Chomsky's grammar and language hierarchy:

Type Automaton Language family Status
0 TuringMachine Recursively enumerable ✅ v0.0.4
1 LinearBoundedAutomaton Context-sensitive ✅ v0.0.4
2 PushdownAutomaton Context-free ✅ v0.1.0
3 FiniteStateAutomaton Regular ✅ v0.2.0

Each class is a formal restriction of the one above it — inheriting its structure and constraining it further. The hierarchy is implemented as a strict inheritance chain:

Automaton
└── TuringMachine               (Type 0)
    └── LinearBoundedAutomaton  (Type 1)
        └── PushdownAutomaton   (Type 2)
            └── FiniteStateAutomaton  (Type 3)

Installation

pip install fsm-tools

Quick start

Turing Machine (Type 0)

from fsm_tools import TuringMachine

tm = TuringMachine(
    name="BinaryIncrement",
    chomsky="Recursively Enumerable",
    axes=1,
    blank_symbol="_",
    movement={"R": [1], "L": [-1]},
    register="q0",
    accept="qAccept",
    reject="qReject",
)

Pushdown Automaton (Type 2)

Recognition of the context-free language L = { aⁿbⁿ | n ≥ 1 }:

from fsm_tools import PushdownAutomaton

pda = PushdownAutomaton(
    name="anbn",
    stack_alphabet={"A"},
    bottom_symbol="Z",
)
pda.add_terminals("a", "b")
pda.set_register("q0")
pda.add_non_terminals("q1", "q2")

pda.add_transition("q0", "a", "Z", "q0", ["A", "Z"])
pda.add_transition("q0", "a", "A", "q0", ["A", "A"])
pda.add_transition("q0", "b", "A", "q1", [])
pda.add_transition("q1", "b", "A", "q1", [])
pda.add_transition("q1", "b", "Z", "q2", [])

pda.validate(["a", "b"])        # True
pda.validate(["a", "a", "b"])   # False

Extended hierarchy (pedagogical)

extended.py provides pedagogical variants that lift specific formal restrictions without changing the class of languages recognised — a direct illustration of the Church-Turing thesis:

Class Extends Adds Since
ExtendedTuringMachine TuringMachine n-dimensional, bidirectional tape v0.0.4
ExtendedLBA LinearBoundedAutomaton n-dimensional bounded tape v0.0.4
ExtendedPushdownAutomaton PushdownAutomaton Epsilon-transitions, epsilon-closure validate() v0.3.0
from fsm_tools import ExtendedPushdownAutomaton

# L = { aⁿbⁿ | n ≥ 0 } — the epsilon-transition covers n = 0, which the
# base PushdownAutomaton rejects unconditionally.
epda = ExtendedPushdownAutomaton(name="anbn-eps", stack_alphabet={"A"}, bottom_symbol="Z")
epda.add_terminals("a", "b")
epda.set_register("q0")
epda.add_non_terminals("q1", "q2")

epda.add_transition("q0", "a", "Z", "q0", ["A", "Z"])
epda.add_transition("q0", "a", "A", "q0", ["A", "A"])
epda.add_transition("q0", "b", "A", "q1", [])
epda.add_transition("q1", "b", "A", "q1", [])
epda.add_transition("q1", "b", "Z", "q2", [])
epda.add_transition("q0", None, "Z", "q2", ["Z"])   # epsilon: accept n = 0

epda.validate([])               # True
epda.validate(["a", "b"])       # True

Documentation

Full documentation is available at fsm-tools.readthedocs.io.

License

This project is licensed under the CeCILL-C license. The French version is the legally authoritative reference — see LICENSE.fr.

Metadata

Release files for fsm-tools 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for fsm-tools 0.3.0
File Size Uploaded Provenance Actions
fsm_tools-0.3.0.tar.gz 108.5 kB With provenance Details for fsm_tools-0.3.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for fsm-tools 0.3.0
File Interpreter ABI Platform Actions
fsm_tools-0.3.0-py3-none-any.whl Python 3 none any Details for fsm_tools-0.3.0-py3-none-any.whl

Total release size: 166.2 kB

Release files / fsm_tools-0.3.0.tar.gz

Download URL fsm_tools-0.3.0.tar.gz
Size 108.5 kB
Tags Source
SHA-256 checksum
How to use checksums
735974622bf6738c8c0ffb0936008ac05855089a00e800241df968aa21ad8644
BLAKE2b-256 checksum
How to use checksums
07ab90ac6815dbd5d753734428e8f7fe7f1850406d12b31b0b89b59d3343d9ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 6, 2026.

Transparency log

Release files / fsm_tools-0.3.0-py3-none-any.whl

Download URL fsm_tools-0.3.0-py3-none-any.whl
Size 57.7 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1745068ff7d364fc984036b13ec08293eb35eb1b662fee484288e3c8e330e2b0
BLAKE2b-256 checksum
How to use checksums
851625020148659061be9b9e27d37feee9019b2dca16979e9e6ae007ff7c8f7d
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 6, 2026.

Transparency log

Security for fsm-tools 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for fsm_tools-0.3.0.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Sep 6, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page