Registry / testing / gramforge

gramforge

JSON →
library1.0.9pypypi✓ verified 80d ago

gramforge is a Python library for efficient multi-language generation from context-free or context-sensitive grammars (CFG/CSG). It supports generating strings and structures from grammar definitions, suitable for tasks like fuzzing, test generation, and language prototyping. Current version is 1.0.9, with a stable release cadence.

pip install gramforge
INSTALL
IMPORT
SIG · GRAMFORGE
G
gramforge
testingpythonv1.0.9
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.

Constraint
from gramforge import Constraint
from gramforge import Grammar
Substitution
from gramforge import Substitution
from gramforge import Grammar
generate
from gramforge import generate
from gramforge import Grammar

Defines a grammar and generates a string from it.

from gramforge import Grammar, Generator # Define a simple grammar grammar = Grammar.from_string(''' S = 'Hello ' Name Name = 'world' | 'Alice' | 'Bob' ''') # Create a generator gen = Generator(grammar) # Generate a string result = gen.generate() print(result) # e.g., 'Hello world'
Debug
Known issues
gotchaGrammar syntax is custom and not compatible with common grammar formats (e.g., ANTLR, EBNF). Double-check the format for rules and terminals.
fix
Refer to the official documentation for grammar syntax (e.g., S = 'hello' Name).
affects: all
gotchaThe generator is not deterministic unless explicitly seeded. Repeated calls to generate() may yield different outputs.
fix
Use gen = Generator(grammar, seed=42) for reproducible output.
affects: all
gotchaGrammar.from_string() may raise ParseError for malformed rules. Always catch exceptions when processing dynamic grammars.
fix
Wrap in try-except: try: grammar = Grammar.from_string(rule) except Exception as e: print(e).
affects: all
Upgrade
Version history
1.0.9latest on PyPI · released Apr 9, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
19 hits · last 30 days
node
18
OpenAI (training)
1
Resources
gramforge — pip install gramforge · libregistry