pfig
A tiny, strict DSL for declarative object configuration
Downloads & Community Adoption
Health & Engineering Analysis (5 Pillars)
1. Governance & Community200 / 200 ▾
2. PEP Metadata & Packaging200 / 200 ▾
3. Security & Supply Chain200 / 200 ▾
4. Documentation, SEO & Ecosystem155 / 200 ▾
5. Engineering, CI & Quality165 / 200 ▾
Official Documentation & Usage Guide — pfig
Show full original documentation (English README) ▾
A tiny, strict DSL for declarative Python object configuration
pfig separates what you build (algorithm) from how you run it (environment). Built for ML workflows.
Quick Start
pip install pfig
If the package is not yet on PyPI, install from GitHub:
pip install git+https://github.com/pfig-dev/pfig.git
# config.pfig
import torch
from train import Model, Trainer
include "./consts.pfig" as consts
external device
model = Model(hidden_size=@consts/hidden_size)
trainer = Trainer(model=@model, epochs=@consts/epochs, device=@device)
__entrypoint__ = @trainer.fit
pfig run config.pfig --set device=cuda
Security
pfig configs are trusted inputs, not a sandboxed data format. Running pfig validate, pfig run, or loading a bundle/replay snapshot can import Python modules, instantiate objects, clone git repositories, and install dependencies from lock files. Only run configs, bundles, and snapshots from sources you trust.
Core Syntax
| Syntax | Description |
|---|---|
name = value |
Literal binding |
provider = Class(args) |
Lazy provider recipe |
@name |
Shared instance (memoized) |
@name() |
Fresh instance |
@provider.attr[.attr...] |
Attribute or bound method |
include "./file.pfig" as alias |
Include with namespace |
override alias/name = value |
Override included binding |
external name |
Runtime environment parameter |
__entrypoint__ |
What to execute |
Key Features
- Providers: Lazy recipes with
@name(shared) and@name()(fresh) instances - Includes: Modular configs with explicit filesystem paths:
include "./base.pfig" as base. Copy/vendor shared configs into your project; no Python-package config discovery. - Externals: Runtime environment separation
- Overrides: Config layering with
override base/param = value - Snapshots: Best-effort reproducibility with config bundles, Git patches, and environment capture
- CLI: Validate, run, diff, fmt, bundle, replay, view, diff-view, and install-rules
Formatting
pfig fmt rewrites .pfig files to a canonical style — 4-space indent, 100-char lines, black-style magic trailing comma, sorted imports within blank-line groups. Comments are preserved.
pfig fmt config.pfig # format in place
pfig fmt path/to/configs/ # recurse into a directory
pfig fmt --check config.pfig # exit non-zero if it would change
pfig fmt --diff config.pfig # show a unified diff
pfig fmt - # read stdin, write stdout
Editor Language Server
The pfig LSP server is included as an optional extra. For VS Code, Neovim, or local editor integration, install it from the pfig repo and run it as a module:
python -m pip install "pfig[lsp] @ git+https://github.com/pfig-dev/pfig.git"
python -m pfig.lsp
For private GitHub installs, configure git and GitHub authentication for
https://github.com/ before the first install.
The server supports diagnostics, go-to-definition, hover, completion, signature help, and semantic tokens for provider/value highlighting.
Graph Viewer
The graph visualizer is available as the optional vis extra and can run in a browser:
python -m pip install "pfig[vis]"
pfig view config.pfig --mode reachable
pfig diff-view base.pfig proposed.pfig
It serves a local React viewer backed by the same graph view model used by the
language server. Use --mode all to show every binding instead of only bindings
reachable from __entrypoint__. In standalone CLI views, clicking a reference
zooms to its graph node, opening its file in Overview and revealing the binding
if it was folded. Editor-integrated views use source navigation: VS Code's
webview or a Neovim --reveal-url callback.
The editable frontend source lives in webview/. The packaged runtime serves
the built files from pfig/vis/assets/, so frontend changes should be rebuilt
before committing:
cd webview
npm ci
npm run test
npm run build
Documentation
📚 Full Documentation - Complete guide, API reference, and examples
- Getting Started - Quick start guide and tutorials
- Reference - API reference, syntax, and CLI documentation
- Developer Guide - Contributing guide and development docs
Editor / AI agent support:
- AI agent rules: Run
pfig install-rules <agent>in your project to install rules that teach AI coding agents how to write.pfigfiles and pfig-friendly Python. Supported targets:cursor— writes.cursor/rules/*.mdc(per-file rules withglobs:for conditional loading)claude— writes.claude/rules/*.md(per-file rules withpaths:for conditional loading)codex— writes a single concatenatedAGENTS.mdat the repo root
- VS Code syntax highlighting: See the vscode-pfig repository for installation instructions.
pfig: Explicit wiring, zero magic
Community
License
pfig is licensed under Apache-2.0. The bundled graph viewer includes components under other licenses; see the third-party notices.
Honorable mentions
pfig originated during work at Ocado Group plc and is now personally maintained. Ocado Group plc is gratefully acknowledged for supporting the open-sourcing of the project.
