VTL Toolkit

The VTL Toolkit provides a set of methods to help the user in the SDMX-VTL interconnection. Currently, it includes functionality to generate VTL scripts and validate the SDMX-VTL objects.

Generate VTL script

pysdmx.toolkit.vtl.generate_vtl_script(transformation_scheme, model_validation=False, prettyprint=False)

Generates the VTL script from a TransformationScheme.

This method iterates over the TransformationScheme object and its referred RulesetSchemes and UserDefinedOperatorSchemes to generate the VTL script as string

The model_validation feature checks if the model object is valid by parsing the VTL code inside the definitions.

The prettyprint feature formats the VTL script in a user-friendly way.

Important

The prettyprint and model_validation features require the pysdmx[vtl] extra.

Parameters:
  • transformation_scheme (TransformationScheme) – A TransformationScheme object.

  • model_validation (bool) – A boolean value to check if the model object is valid. if True, the model object is validated.

  • prettyprint (bool) – A boolean value to check if the generated script is returned formatted.

Return type:

str

Returns:

A string containing the full VTL Transformation Scheme script.

Validate VTL objects

pysdmx.toolkit.vtl.model_validations(model_obj)

Validation checks for VTL objects.

This method performs validation checks on VTLScheme objects , such as TransformationScheme, RulesetScheme, UserDefinedOperatorScheme, etc. or its items, like Ruleset, Transformation, UserDefinedOperator, etc.

It raises an Invalid exception if the model object is not valid.

The model validation checks on items:

  • Ruleset validation

    • A single RulesetDefinition (define …) is valid in a Ruleset

    • Ruleset type matches the definition (hierarchical or datapoint)

    • Ruleset scope matches the signature (variable or valuedomain)

  • User Defined Operator validation

    • A single OperatorDefinition (define operator …) is valid in a User Defined Operator

  • Transformation validation

    • Checks if the transformation is valid

    • Checks a single assignment is present in the expression

The model validation checks on VTLScheme:

  • RulesetScheme validation

    • Checks if it contains at least one Ruleset

    • Checks if all items in the scheme are Ruleset

  • UserDefinedOperatorScheme validation

    • Checks if it contains at least one UserDefinedOperator

    • Checks if all items in the scheme are UserDefinedOperator

  • TransformationScheme validation

    • Checks if it contains at least one Transformation

    • Checks if all items in the scheme are Transformation

    • Checks the referenced RulesetSchemes (if any) and UserDefinedOperatorSchemes (if any)

Parameters:

model_obj (Union[VtlScheme, Item]) – A VTLScheme or Item object.

Raises:

Invalid – Invalid model object if the model object is not valid.

Return type:

None