/infrahub:infrahub-managing-transforms [transform-name] [format]from infrahub
Creates, modifies, and debugs Infrahub transforms that convert data into JSON, text, CSV, or device configs using Python or Jinja2 templates with YAML-driven tests.
Ships in infrahub. Installing the plugin adds it to Claude Code.
What the skill costs in Claude's context, stage by stage
Name and description: Claude knows it exists.
SKILL.md joins the conversation and stays.
Read when SKILL.md points to them.
Expert guidance for creating Infrahub transforms. Transforms convert Infrahub data into different formats -- JSON, text, CSV, device configs, or any text-based output -- using Python classes or Jinja2 templates.
Before writing a transform, look at the project with read-only tools:
.infrahub.yml if it exists..py files under a
transforms/ directory and .j2 files under a
templates/ directory.These steps contact the Infrahub server, so they come after the read-only look at the project:
infrahubctl command, detect the
project's Python environment as
../infrahub-common/rules/connectivity-python-environment.md
describes..gql
file, dry-run the query against the live schema on a
branch as
../infrahub-common/rules/deployment-gql-dry-run.md
describes..py file under transforms/, a .j2 file under templates/,
or a .gql file under queries/ that a transform in .infrahub.yml uses,
even when the request does not mention transforms| Priority | Category | Prefix | Description |
|---|---|---|---|
| CRITICAL | Types | types- | Python vs Jinja2 choice |
| CRITICAL | Python | python- | InfrahubTransform class |
| CRITICAL | Jinja2 | jinja2- | Template syntax, filters |
| HIGH | Hybrid | hybrid- | Python + Jinja2 combined |
| HIGH | Artifacts | artifacts- | Output files, targets |
| HIGH | API Ref | api- | Class attrs, methods |
| MEDIUM | Patterns | patterns- | Utilities, CSV, shared |
| HIGH | Testing | testing- | Resources Testing Framework, transform/render commands |
A transform reads schema-shaped data and produces a file. Misalignment between the transform and the schema fails late — at artifact-render time, when someone is waiting for the output.
| If the transform... | The schema (or .infrahub.yml) must... | See |
|---|---|---|
Will feed an artifact_definitions entry | The target node must inherit_from: CoreArtifactTarget so the artifact pipeline can attach to it | ../infrahub-managing-schemas/rules/extension-artifact-target.md |
| Reads attributes from a node | Define those attributes with their full __value access path in GraphQL — silent empty strings come from accessing the node, not the value | ../infrahub-managing-schemas/rules/attribute-defaults-and-types.md |
| Picks a template per device by platform/role | The schema must expose that platform/role as a real attribute or relationship — string-matching on display_label is brittle | ../infrahub-managing-schemas/rules/display-human-friendly-id.md |
Is referenced from artifact_definitions.transformation | The transform's registered name must match the transformation: field exactly — mismatch produces "transformation not found" at render time | rules/artifacts-definitions.md |
| Uses Jinja2 (not Python) | Register under jinja2_transforms with a top-level query: field — python_transforms binds query on the class, the two keys are not interchangeable | rules/api-reference.md |
| Is a Python transform | Carry a watch: block naming every first-party module it imports — sibling modules included, since imports are never followed. Without the key, Infrahub cannot trust the dependency list and re-renders the artifacts on every commit | rules/artifacts-watch-dependencies.md |
| Reads a data file at runtime, or includes a template by variable name | Name those paths in watch.files — detection cannot see a path that exists only as a string, so the artifacts go stale on a change with no error raised | rules/artifacts-watch-dependencies.md |
| Has its artifacts regenerated by a caller (catalog page, CI job, orchestrator) | That caller must poll CoreArtifact until each artifact is body-ready — the POST only queues the regen, and the node exists before its content does | rules/artifacts-async-regen-polling.md |
If the transform body is string formatting — f-strings,
concatenation, conditional sections — Jinja2 expresses
the same output in fewer lines, renders directly in
the proposed-change UI, and lives under
jinja2_transforms in .infrahub.yml instead of
python_transforms. Walk this ladder before reaching
for InfrahubTransform:
| Signal | Cheaper layer | See rule |
|---|---|---|
Transform body is return f"..." or "\n".join([...]) built from query results | Jinja2 template file | yagni-python-transform-that-could-be-jinja2 |
| Transform copies query data verbatim without computation | The GraphQL query alone — no transform needed | Ladder step 1 (drop the requirement); judgment call, no rule |
Conditionals are if x: out += ...; else: out += ... and nothing else | Jinja2 {% if %} blocks | yagni-python-transform-that-could-be-jinja2 |
Use Python when the transform parses, computes, or reshapes — IP/subnet math, hashing, ordered aggregation, structural JSON re-shaping. See rules/python-transform.md for the legitimate cases.
When the transform reads objects through the SDK, type those calls with
generated protocol classes rather than string kinds — client.filters(NetworkLink, ...),
not kind="NetworkLink" — so schema drift breaks attribute reads on the
returned objects at type-check time. Field names passed to create() are not
type-checked. See
protocols-adopt-typed-kinds.
Two types of transforms:
| Type | Output | Entry Point |
|---|---|---|
| Python | Whatever the artifact's content_type asks for: a dict only under application/json or application/yaml, a str for the other six | InfrahubTransform.transform() |
| Jinja2 | Text | .j2 template file |
from infrahub_sdk.transforms import InfrahubTransform
class MyTransform(InfrahubTransform):
query = "my_query"
# Returns a dict, so the artifact definition has to declare
# content_type: application/json (or application/yaml). Under any
# other content type this dict is stored as str(dict), with no
# error. See rules/artifacts-definitions.md.
async def transform(self, data: dict) -> dict:
device = data["DcimDevice"]["edges"][0]["node"]
return {"hostname": device["name"]["value"]}
Follow these steps when creating a transform:
.gql file
that fetches the data to transform. Read
../infrahub-common/graphql-queries.md
for query patterns.InfrahubTransform and implement transform().
Read rules/python-transform.md.
For Jinja2, create a .j2 template. Read
rules/jinja2-template.md.
For hybrid, read
rules/hybrid-python-jinja2.md.python_transforms or jinja2_transforms. See
rules/api-reference.md.
Then declare the transform's dependencies with
watch.files: read the entry point's imports and
runtime file reads, and name every first-party path
they resolve to. A Python transform should always
carry the key — files: [] when it genuinely has no
dependency beyond its own file. Read
rules/artifacts-watch-dependencies.md,
which also covers reviewing an existing watch block
for entries that are missing, stale, or wrong.infrahubctl transform or
infrahubctl render to validate. See
rules/testing-commands.md.content_type values and how each
serialises the transform's return value. Authority on
which return type a content type accepts.infrahub.yml registration shapes,
filter env overviewdocs.infrahub.app
on a genuine gap (e.g. deleting nodes)examples.md (opens in a new tab)reference.md (opens in a new tab)rules/_sections.md (opens in a new tab)rules/_template.md (opens in a new tab)rules/api-reference.md (opens in a new tab)rules/artifacts-async-regen-polling.md (opens in a new tab)rules/artifacts-definitions.md (opens in a new tab)rules/artifacts-watch-dependencies.md (opens in a new tab)rules/hybrid-python-jinja2.md (opens in a new tab)rules/jinja2-template.md (opens in a new tab)rules/patterns-common.md (opens in a new tab)rules/python-transform.md (opens in a new tab)rules/queries-union-fragments.md (opens in a new tab)rules/testing-commands.md (opens in a new tab)rules/testing-resource-framework.md (opens in a new tab)rules/types-overview.md (opens in a new tab)What SKILL.md sets; muted values are Claude Code's defaults
infrahub@opsmill is listed by opsmill/claude-marketplace — review the source before installing
npx claudepluginhub opsmill/claude-marketplace --plugin infrahub18 skills in this plugin
/infrahub-analyzing-dataAnalyzes and correlates live Infrahub data via the MCP server — answers operational questions, detects drift, and investigates impact. TRIGGER when: querying infrastructure data, checking compliance, investigating change impact, producing ad-hoc reports. DO NOT TRIGGER when: writing automated checks, building transforms, designing schemas, populating data files, planning an Infrahub version upgrade (use infrahub-planning-upgrades). ALWAYS pass the user's question verbatim as args — this skill runs in a forked context and cannot see the parent conversation. Invoking without args will fail./infrahub-analyzing-diagnosticsAnalyze an already-collected infrahub-collect diagnostic bundle — traceback and failure triage across service logs, incident correlation, and known-issue matching against opsmill/infrahub GitHub issues. TRIGGER when: the user says they collected a diagnostic bundle, gives you a bundle path, or pastes bundle contents — and asks what's wrong, wants the logs or tracebacks analyzed, asks "what does this bundle say", wants errors triaged/correlated, or asks whether a crash is a known issue. DO NOT TRIGGER when: no bundle exists yet — collect one first (use infrahub-collecting-diagnostics), filing the issue itself (use infrahub-reporting-issues), or querying live data (use infrahub-analyzing-data).Other plugins' skills for the same job