Skip to main content

Computed attributes

The computed attributes feature enables the dynamic calculation of attribute values based on user-defined logic. Currently, Infrahub supports two main types of computed attributes: Jinja2 and Python.

Jinja2 computed attributes

Users can input a concise Jinja2 template directly within the schema definition. Any change to any field used to compute the value will automatically update it.

See the guide for instructions on creating Jinja2 computed attribute in Infrahub.

Limitations

  • Jinja2 computed attributes cannot reference relationships with cardinality many.
  • Only direct relationships can be used (i.e., a relationship of a relationship is not accessible).
  • Only URL and Text attribute kinds are supported at the moment.

Python computed attributes

Python computed attributes leverage Infrahub's Python transform feature. Users can define which transformation to apply directly within the schema. The computation of the value is delegated to workers as asynchronous tasks, which may cause the value to take a few seconds to update.

Python scripts do not have the limitations of Jinja2 computed attributes and can include more complex logic, including relationships with cardinality many and nested relationships.

See the guide for instructions on creating Python computed attribute in Infrahub.

Limitations

  • Python computed attributes cannot be used on mandatory attribute.
  • Complex scripts can impact system performance.
  • Only URL and Text attribute kinds are supported at the moment.

Choosing Between Jinja2 and Python

Computed attribute kindMandatory attributesRelationship limitationsComplexity Handling
Jinja2CompatibleNo use of many cardinality; direct onlyStraightforward operations
PythonNot compatibleNo limitationsHandles complex logic

See the guide for instructions on creating computed attribute in Infrahub.