Declarative test data generator for Python.
Define constraints once in type annotations — generate both valid and minimal invalid test data automatically. No factories, no hardcoded fixtures, no drift when schema changes.
Conformly turns typed schemas into dictionaries for fixtures and validation tests. Use the same schema for happy-path payloads and targeted negative cases.
- Constraint-driven generation from type annotations and model metadata.
- Minimal invalid cases targeting one field and a selected violation.
- Schema as the single source of truth for test data.
- Dataclasses and TypedDicts, with optional Pydantic and attrs integrations.
- Nested models, collections, reproducible seeds, and field overrides.
Requires Python 3.12 or newer.
pip install conformly
# Optional integrations:
pip install 'conformly[pydantic]'
pip install 'conformly[attrs]'from dataclasses import dataclass
from typing import Annotated
from conformly import GreaterOrEqual, MaxLength, MinLength, V, case, path
@dataclass
class CreateUser:
username: Annotated[str, MinLength(3), MaxLength(32)]
age: Annotated[int, GreaterOrEqual(18)]
payload = case(CreateUser)
assert 3 <= len(payload["username"]) <= 32
assert payload["age"] >= 18
invalid = case(
CreateUser, valid=False, target=path("age").violate(V.BELOW_MIN)
)
assert invalid["age"] < 18
assert 3 <= len(invalid["username"]) <= 32Results are dictionaries, not model instances. Invalid generation targets one field; only the selected violation is guaranteed on that target. Defaults and overrides are trusted rather than validated. See the invalid generation contract.
Start with Getting started, browse the documentation index, or run the examples. The API reference lists parameters and defaults.
See CONTRIBUTING.md for setup and checks, and CHANGELOG.md for release notes and migration guidance.
MIT — see LICENSE.