Skip to main content

Transform Manager

The Transform Manager produces data transforms that convert Infrahub data into other formats — device configurations, JSON exports, CSV reports, and more. Transforms can be implemented as Python classes, Jinja2 templates, or a hybrid of both. The skill generates the transform code, GraphQL query, optional Jinja2 templates, and .infrahub.yml registration.

When to use

  • Generating device configuration files from Infrahub data
  • Exporting infrastructure data to JSON, CSV, or other formats
  • Producing human-readable reports from graph data
  • Any scenario where Infrahub data needs to be rendered into a different representation

Transform types

Python transform

Use when the output requires logic: conditional rendering, calculations, data reshaping.

  • Implements InfrahubTransform class with a transform() method
  • Returns a dict for JSON output or a str for text output

Jinja2 transform

Use when the output is primarily a template with variable substitution: device configs, structured text files.

  • Template file receives the GraphQL query response in a data variable
  • Supports netutils filters for network-specific operations (IP address manipulation, interface normalization)

Hybrid (Python + Jinja2)

Use when data needs preprocessing before rendering.

  • Python class prepares and reshapes the data, Jinja2 template handles rendering
  • Supports platform-specific templates (e.g., different configs per vendor) using FileSystemLoader

What it produces

  • GraphQL query file (.gql) — fetches the data the transform needs
  • Python transform class and/or Jinja2 template file(s)
  • .infrahub.yml entry under python_transforms or jinja2_transforms
  • artifact_definitions entry if the transform produces versioned artifacts

Example prompts

  • "Create a Jinja2 transform that produces Cisco IOS configuration for each device, pulling interface and BGP data from Infrahub"
  • "Write a Python transform that exports all IP addresses to a CSV file"
  • "Build a hybrid transform that generates vendor-specific configs — Cisco IOS for routers, Juniper JunOS for switches"

Key rules enforced

  • Return type — Python transform must return dict for JSON output or str for text; wrong return type causes rendering failure
  • data variable — Jinja2 templates always receive the GraphQL response as data; accessing the wrong key is a common mistake
  • Artifact definitions — if the transform output should be stored as a versioned artifact in Infrahub, an artifact_definitions entry is required in .infrahub.yml; the skill generates this when appropriate
  • netutils availabilitynetutils filters are available in Jinja2 templates; the skill uses them where appropriate for IP and interface operations

Running transforms

Transforms run as part of the artifact generation pipeline or on demand:

infrahubctl transform run <transform-name>