ProjectsCase Study

Author ยท 2025

pydantic-fixturegen

An open-source Python tool for generating reproducible test data from Pydantic models, dataclasses and TypedDicts.

Open-source Python tool

PythonPydanticTesting

Model discovery, seeded generation and output formats.

The problem

Test data becomes difficult to maintain when models change and fixtures are assembled by hand. I built pydantic-fixturegen to generate structured data from Python model definitions.

What it provides

The tool exposes a CLI and Python API for generating JSON, pytest fixtures and datasets. Seeds and generation settings make the process repeatable within the documented environment, while providers allow custom generation behavior.

Engineering focus

The implementation separates model discovery, value generation and output formats. This makes it possible to extend the tool without rewriting each emitter. The documentation includes configuration, examples and the limitations of its model-import restrictions.

Reproducible use

For a model file owned by your project, the documented CLI can generate JSON with an explicit seed:

Snippetbash
pfg gen json models.py --include models.User --n 2 --seed 7 \
  --freeze-seeds --out 'out/{model}.json'

Keep the Python version, dependencies, model definitions and generation settings fixed when comparing output. Model imports can execute Python code; import restrictions are not a proven boundary for arbitrary hostile code.