Documentation
Pfg Init
Reference docs for pydantic-fixturegen.
pfg init
Capabilities
pfg init scaffolds configuration (pyproject + optional YAML) and recommended directories for new projects. It writes deterministic defaults (seed, locale, JSON settings, pytest emitter style/scope) and can create a fixtures directory with a .gitkeep file so version control stays tidy.
Typical use cases
- Bootstrap a repo with fixturegen defaults before wiring CI.
- Move configuration from ad-hoc scripts into
pyproject.tomlorpydantic-fixturegen.yaml. - Standardize pytest fixture style/scope across teams.
Inputs & outputs
- Directory argument: project root to scaffold (defaults to
.). The command resolves the path, creates directories as needed, and can overwrite existing config when--forceis provided. - Outputs:
[tool.pydantic_fixturegen]blocks appended topyproject.toml(unless--no-pyproject).- Optional YAML config (
pydantic-fixturegen.yamlor a custom path with--yaml-path). - Fixture directory (defaults to
tests/fixtures) with optional.gitkeep.
Flag reference
--pyproject/--no-pyproject: toggle pyproject edits (default on).--yaml/--no-yaml: also emit YAML config. Use--yaml-pathto change the destination.--force: overwrite existing config blocks/files. Without it, init aborts when config already exists.--seed: default seed to write (set-1to omit the seed entirely).--locale: default Faker locale.--union-policy: one offirst,weighted, etc.--enum-policy:first,random, etc.--json-indent,--json-orjson: JSON emitter defaults.--pytest-style,--pytest-scope: defaults for the pytest emitter.--fixtures-dir: directory to create for generated fixtures.--gitkeep/--no-gitkeep: whether to drop an empty.gitkeepin the fixtures directory.
Example workflows
Minimal pyproject scaffold
pfg init . \
--seed 42 --locale en_US \
--union-policy weighted --enum-policy random \
--pytest-style functions --pytest-scope module
Sample output
[init] writing pyproject.toml (sections: tool.pydantic_fixturegen*)
[init] created tests/fixtures/.gitkeep
Scaffold complete.
YAML-only setup in a monorepo
pfg init services/payments --no-pyproject --yaml --yaml-path config/pfg.yaml --fixtures-dir tests/pfg
Sample output
[init] writing services/payments/config/pfg.yaml
[init] created services/payments/tests/pfg/.gitkeep
Operational notes
- The CLI removes existing
[tool.pydantic_fixturegen.*]sections before writing new content unless--forceis omitted (in which case it aborts to avoid data loss). - Config snippets include a header with the fixturegen version (“Generated by pydantic-fixturegen X.Y.Z via
pfg init”) for auditability. - All emitted files use Unix line endings and ASCII-safe content, so cross-platform diffs remain clean.