Registry / devops / pyformlang

pyformlang

JSON →
library1.0.11pypypi✓ verified 86d ago

A Python framework for formal grammars, automata theory, and formal language processing. Current version is 1.0.11. Release cadence is irregular, primarily maintenance updates.

pip install pyformlang
INSTALL
IMPORT
SIG · PYFORMLANG
P
pyformlang
devopspythonv1.0.11
harness data pending
Install & Compatibility
Where this runs

No compatibility data collected yet for this library.

Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

cfg
from pyformlang.cfg import CFG
import cfg
CFG is inside pyformlang.cfg, not a top-level module.
rsa
from pyformlang.rsa import RecursiveStateAutomaton
from pyformlang import RecursiveStateAutomaton
RecursiveStateAutomaton lives in pyformlang.rsa.
regular_expression
from pyformlang.regular_expression import Regex
import regex
Not the standard 'regex' library; use pyformlang's Regex class.

Create a context-free grammar and check if a string is generated.

from pyformlang.cfg import CFG cfg = CFG.from_text(""" S -> A B A -> 'a' B -> 'b' """) print(cfg) print(cfg.contains("ab"))
Debug
Known issues
breakingIn version 1.0, the API was overhauled. Many classes (e.g., `FiniteAutomaton`, `CFG`) moved to submodules. Old code importing from `pyformlang.fa` or `pyformlang.cfg` directly may break.
fix
Update imports: `from pyformlang.finite_automaton import DeterministicFiniteAutomaton`.
affects: >=0.5, <1.0
deprecatedThe `pyformlang.regular_expression` module's `Regex` constructor no longer accepts a string with implicit concatenation; use explicit operators.
fix
Use `Regex('a b')` with spaces or explicit '.' for concatenation.
affects: >=1.0.0
gotchaCFG emptiness check (`cfg.is_empty()`) may return `True` for grammars that generate the empty language even if they look non-empty due to cycles. Always check reachable and productive symbols first.
fix
Use `cfg.get_reachable_symbols()` and `cfg.get_productive_symbols()` before calling `is_empty()`.
affects: all
Errors
Common errors & fixes
AttributeError: module 'pyformlang' has no attribute 'cfg'
Importing `pyformlang.cfg` directly without the submodule import.
fix
Use `from pyformlang.cfg import CFG` instead of `import pyformlang.cfg`.
OSError: [WinError 126] The specified module could not be found
Missing C++ runtime on Windows due to compiled extensions.
fix
Install Microsoft Visual C++ Redistributable for Visual Studio 2015-2022.
Upgrade
Version history
1.0.11latest on PyPI · released Mar 18, 2025
Audit
Dependencies

No dependency data recorded yet.

Agent activity
4 hits · last 30 days
node
4
Resources
pyformlang — pip install pyformlang · libregistry