Documentation

Pfg Init

Reference docs for pydantic-fixturegen.

main

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.toml or pydantic-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 --force is provided.
  • Outputs:
  • [tool.pydantic_fixturegen] blocks appended to pyproject.toml (unless --no-pyproject).
  • Optional YAML config (pydantic-fixturegen.yaml or 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-path to change the destination.
  • --force: overwrite existing config blocks/files. Without it, init aborts when config already exists.
  • --seed: default seed to write (set -1 to omit the seed entirely).
  • --locale: default Faker locale.
  • --union-policy: one of first, 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 .gitkeep in 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
Writes fixturegen configuration into `pyproject.toml` and creates `tests/fixtures/.gitkeep`.

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
Emits only a YAML config plus a fixtures directory under `services/payments/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 --force is 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.
Edit this page