$ show HypothesisWorks/hypothesis
Hypothesis is a mature property-based testing library for Python. The core runtime, exposed via @given in hypothesis/src/hypothesis/__init__.py, executes each decorated test many times with inputs drawn from composable SearchStrategy objects (integers, floats, text, regex, collections, datetimes, plus extras generating numpy arrays, pandas DataFrame/Series, Django models/forms, lark grammars, and more). All randomness flows through a formal choice IR (hypothesis/internal/conjecture/choice.py) into a pluggable PrimitiveProvider; the default conjecture engine (engine.py) maintains a DataTree of previously seen choice prefixes to avoid redundant exploration and detect flaky tests, and when a failure is found a cascade of shrinking passes (shrinker.py plus the shrinking/ package) reduces it to a minimal counterexample. An example database layer (in-memory, directory-based, and GitHub-artifact backends) persists and replays failures across runs, and an observability subsystem emits structured JSONL metadata per test case. The package also ships application surfaces beyond the library API: a pytest plugin (statistics, health checks, capture, deadline reporting), a CLI (a ghostwriter that auto-generates property tests from signatures/docstrings, plus codemods and failure-patching commands), and a stateful-testing framework (RuleBasedStateMachine, Bundle, @rule/@invariant). A PyO3 Rust extension (hypothesis/rust) accelerates float encoding, and the provider abstraction is validated by an embedded conformance test suite so third-party backends (e.g., CrossHair symbolic execution) can drive generation. Internal subsystems are unusually well-factored — filter predicates are rewritten into tighter strategy constraints via AST analysis, lambda sources are recovered from bytecode, and Unicode character ranges are modelled as interval sets — making several modules reusable outside the project. This is a developer-tool library with CLI and pytest entry points, not a runtime service; the repo also includes its own build/release tooling, a Pelican website, docs, and a very large self-testing suite with enforced 100% branch coverage.
The LLM identified 5 files worth highlighting for reuse:
Collection of small dependency-free utilities. find_integer() is an exponential-probe-then-binary-search over a monotonic predicate, used as the backbone of the collection shrinker; LazySequenceCopy provides O(1) undoable mutable views over sequences; IntList is a compact auto-upgrading integer sequence. Each function is pure, typed, and self-contained enough to drop directly into a new project.
GenericCache is a pluggable cache abstraction with new_entry/on_access/on_evict hooks and pinning; LRUCache, LRUReusedCache, and LFUCache are built as thin policy layers over it. A useful extraction for any codebase needing cache eviction semantics beyond functools.lru_cache, such as value-reuse-aware or score-based eviction.
Immutable, compact representation of a set of Unicode code points as sorted disjoint intervals, with union/difference/intersection, index-based lookup, and character iteration. Pure standard library; directly reusable for any range-set problem (character classes, numeric ranges, time ranges) and notably well-documented in behavior via its test suite.
Registers Python Random instances, numpy Generators, and other PRNGs into a global manager, and provides deterministic_PRNG() as a context manager that seeds and restores every registered PRNG. Self-contained and ready to reuse in test harnesses or simulations that require reproducible random state.
Defines the formal IR for all random choices in the engine — integers with zigzag ordering, floats, strings, bytes, booleans — as a constrained, JSON-serialisable ChoiceNode tree with bijective choice_to_index/choice_from_index mappings and child-count computation. This IR is what makes replay, shrinking, and multi-backend provider conformance possible, and is an instructive model for designing a serialisable input space for any fuzzing or property-testing tool.