Registry / testing / hypothesmith

hypothesmith

JSON →
library0.3.3pypypi✓ verified 84d ago

Hypothesis strategies for generating Python programs, similar to CSmith. Current version 0.3.3; release cadence is low, mostly bugfixes. Requires Python >= 3.8.

pip install hypothesmith
INSTALL
IMPORT
SIG · HYPOTHESMITH
H
hypothesmith
testingpythonv0.3.3
Install
3.1s avg
Import
14102ms
Disk
37MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.3.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 14.352s · 37.3MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 3.1s · import 13.852s · 38MB
37MB installed
● package 37MB
Code
Verified usage

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

from hypothesmith import from_grammar
from hypothesmith import from_grammar
import hypothesmith; hypothesmith.from_grammar
Common mistake: using module-level access instead of direct import; direct import is idiomatic.
from hypothesmith import from_grammar
from hypothesmith import from_grammar, __version__
from hypothesmith import version
Version is stored as __version__ not version.

Generate Python code strings from grammar rules; use with Hypothesis to fuzz parsers or interpreters.

from hypothesmith import from_grammar from hypothesis import given, strategies as st # Generate a simple expression using Python's grammar @given(from_grammar('<eval_input>', start='<eval_input>')) def test_parse(code): assert isinstance(code, str) assert len(code) > 0 test_parse()
Debug
Known issues
gotchaThe grammar strings use angle brackets around rule names (e.g., '<stmt>'), not just the rule name.
fix
Use '<stmt>' not 'stmt' when passing to from_grammar.
affects: all
deprecatedfrom_grammar() replaces the older from_node() API; from_node may be removed in future versions.
fix
Use from_grammar() instead of from_node().
affects: >=0.3.0
gotchaGenerated code may be syntactically correct but semantically invalid (e.g., referencing undefined names).
fix
Combine with Hypothesis strategies to generate valid names or use custom filters.
affects: all
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'hypothesmith'
hypothesmith not installed.
fix
Run 'pip install hypothesmith'.
hypothesis.errors.InvalidArgument: Expected a strategy, got ...
Incorrect import path; from_grammar returns a strategy but may be called incorrectly.
fix
Ensure you use 'from hypothesmith import from_grammar' and pass valid grammar rules.
AttributeError: module 'hypothesmith' has no attribute 'from_node'
Using an older API that was removed or renamed.
fix
Use 'from hypothesmith import from_grammar' instead of from_node.
Upgrade
Version history
0.3.3latest on PyPI · released Feb 16, 2024
Audit
Dependencies
hypothesisrequiredCore dependency for property-based testing strategies
Agent activity
6 hits · last 30 days
node
6
Resources
hypothesmith — pip install hypothesmith · libregistry