Infraclass
Infraclass is a lightweight, zero-dependency inventory compiler. You describe your infrastructure as a hierarchy of YAML files — nodes, and reusable "classes" they inherit from — and infraclass merges them into one flat set of config values per node, decrypting any age-encrypted secrets along the way.
Infraclass has no knowledge of pyinfra, Ansible, or any other automation tool. It only produces data — a Python dict, or YAML on stdout. Feeding that data into whatever automation engine you use is a separate step you write yourself (see "Calling it from a script instead of the CLI" below).
Project Directory Structure
Rename your data directory to infraclass/ to align with the framework:
automation/
├── your_inventory_script.py # Your own integration script — see "Calling it from a script instead of the CLI"
└── infraclass/ # Your hierarchical data directory
├── classes/ # Reusable configuration blueprints
│ ├── components/
│ ├── platform/
│ │ └── init.yml # Standard shared properties & secrets
│ └── roles/
├── nodes/ # Machine-specific inventory targets
│ └── node1.example.com.yml
└── vault/
└── vault.age # Encrypted secrets store
Setup
Install the package
uv tool install infraclass
Point it at your age key
By default, infraclass looks for your decryption key at ~/.age/identity.age. Put your private key there, or tell infraclass to use a different path:
export INFRACLASS_AGE_KEY_FILE="$HOME/.age/identity.age"
Systemd / Credentials Directory Resolution
When running inside a systemd service (e.g. a CI/CD runner) that provides the vault key via LoadCredentialEncrypted, infraclass finds it automatically — no config changes needed. Key resolution (in infraclass/vault.py) checks, in order:
$CREDENTIALS_DIRECTORY(set by systemd), for a file matchingage-key*orage-pq-key*$INFRACLASS_AGE_KEY_FILE, if set- The default location,
~/.age/identity.age
Trying it out
From the command line
infraclass show node1.example.com
Prints that node's fully compiled configuration as YAML. This is the quickest way to sanity-check that a node compiles, and to see exactly what data it produces.
By default (or with --mask-secret-values, the same thing spelled out explicitly), the vault isn't decrypted at all — every !secret reference is shown as a <SECRET: id> placeholder, and no passphrase/Touch ID prompt appears. Add --reveal-secret-values to decrypt the vault and print the real secret values instead.
Vault/secret management lives under its own vault command — infraclass vault add, infraclass vault remove <id>, infraclass vault show <id>, infraclass vault audit, infraclass vault prune, infraclass vault re-encrypt. Run infraclass vault --help for the full list.
Calling it from a script instead of the CLI
If you need the compiled data inside a script rather than as YAML from the CLI, call compile_node_data directly:
import infraclass
node_data = infraclass.compile_node_data("node1.example.com", base_dir="infraclass")
node_data["parameters"] # merged config for this node, secrets decrypted
node_data["classes"] # every class this node inherited from
compile_node_data is a one-shot convenience wrapper — each call decrypts the vault and re-parses class files from scratch. If you're compiling many nodes in a loop, like pyinfra's inventory.py does when it builds the full host/group inventory, construct a Compiler once and call .compile() per node instead — it reuses the decrypted vault and parsed class files across every call:
import infraclass
compiler = infraclass.Compiler(base_dir="infraclass")
for node_data in (compiler.compile(name) for name in node_names):
... # build inventory entries from node_data
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file infraclass-1.1.2.tar.gz.
File metadata
- Download URL: infraclass-1.1.2.tar.gz
- Upload date:
- Size: 25.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4b71e5f48c8b0f5c8c4d1ba72c8ec2952482ff79426e7f8ee2865455fbd99c96
|
|
| MD5 |
2b0281a6403ef20e78635e7bfd250100
|
|
| BLAKE2b-256 |
8a21c6fbcc66cc4b911b7828f96361705890bd41049a3928bcceb475009e1f4c
|
File details
Details for the file infraclass-1.1.2-py3-none-any.whl.
File metadata
- Download URL: infraclass-1.1.2-py3-none-any.whl
- Upload date:
- Size: 21.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via:
twine/7.0.0 CPython/3.12.13
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
14f17323b5d4cb85aef88d2dfdfcd30d443ef407173e89bbcb46ee0393cb3928
|
|
| MD5 |
6e6c010c6daa457ff714b0bd0998b51b
|
|
| BLAKE2b-256 |
baeb0c062c108c480250d0c9588c19bfa8000f4caed824e3170b4ae5926715d1
|