Reference

altinn package

altinn.file module

This module contains the main function for running the Altinn application.

class FileInfo(file_path)

Bases: object

This class represents file information handling.

Parameters:

file_path (str)

filename()

Get the name of the XML file.

Returns:

The name of the XML file.

Return type:

str

pretty_print()

Print formatted version of an XML file.

Return type:

None

print()

Print unformatted version of an XML file.

Return type:

None

validate()

Validate the XML file.

Return type:

bool

main()

Placeholder function for the main function.

This function is called when the altinn package is run as a script.

Return type:

None

altinn.flatten module

For flattening Altinn3 xml-files for Dynarev-base in Oracle.

This module contains the functions for flattening the Altinn3 xml-files that should be loaded into our on-prem Oracle database for Dynarev-base. These generic functions currently supports xml files that do not contain kodelister. It requires the user to specify how to recode old fieldnames of Altinn2 to the new names of Altinn3. This is done in a separate file.

create_isee_filename(file_path)

Creates a filename based on the contents of an XML file and the provided file path.

Parameters:

file_path (str) – The path to the XML file.

Return type:

str | None

Returns:

The generated filename if successful, otherwise None.

isee_transform(file_path, mapping=None, tag_list=None, checkbox_vars=None, unique_code=False)

Transforms a XML to ISEE-format using xmltodict.

Transforms the XML to ISEE-format by using xmltodict to transform the XML to a dictionary. Traverses/scans the key/values in dictionary for lists, dicts and simple values. Stores the results in a list of dictionaries, that converts to a DataFrame

Parameters:
  • file_path (str) – The path to the XML file.

  • mapping (dict[str, str] | None) – The mapping dictionary to map variable names in the ‘feltnavn’ column. The default value is an empty dictionary (if mapping is not needed).

  • tag_list (list[str] | None) – A list containing the tags in the XML that will be flatten The default value is [‘SkjemaData’]

  • checkbox_vars (list[str] | None) – Optional list of str for elements from xml containing KLASS codes.

  • unique_code (bool) – Bool for if you are using unique codes from Klass or not.

Returns:

A transformed DataFrame which aligns with the ISEE dynarev format.

Return type:

pandas.DataFrame

Raises:
  • ValueError – If reqired keys in InterInfo is missing.

  • ValueError – If invalid gcs-file or xml-file.

xml_transform(file_path)

Transforms a XML to a pd.Dataframe using xmltodict.

Transforms the XML to a dataframe, using xmltodict to transform the XML to a dictionary. Traverses/scans the key/values in dictionary for lists, dicts and simple values. Stores the results in a list of dictionaries, that converts to a DataFrame

Parameters:

file_path (str) – The path to the XML file.

Returns:

A transformed DataFrame that contains all values from the XML

Return type:

pandas.DataFrame

Raises:

ValueError – If invalid gcs-file or xml-file.

altinn.parser module

This module contains the main function for running the Altinn application.

class ParseSingleXml(file_path)

Bases: object

This class represents an Altinn application.

Parameters:

file_path (str)

get_root_from_dapla()

Read in XML-file from GCP-buckets on Dapla.

Returns:

The root Element of the parsed XML file.

Return type:

Element

get_root_from_filesystem()

Read in XML-file from classical filesystem.

Returns:

The root Element of the parsed XML file.

Return type:

Element

to_dataframe()

Parse single XML file to a pandas DataFrame.

Returns:

A DataFrame representation of the XML file.

Return type:

pd.DataFrame

traverse_xml(element, column_counter=1, data=None)

Recursively traverse an XML element and extract data.

Parameters:
  • element (Element) – The XML element to traverse.

  • column_counter (int) – The counter for generating unique column names.

  • data (dict or None) – The dictionary to store the extracted data.

Returns:

The dictionary containing the extracted data.

Return type:

dict

main()

Placeholder function for the main function.

This function is called when the altinn package is run as a script.

Return type:

None

altinn.utils module

Utilities for working with Altinn-data in Python.

is_gcs(file_path)

Check whether the given file path is a Google Cloud Storage path.

Parameters:

file_path (str) – The file path to check.

Returns:

True if the file path is a Google Cloud Storage path, False otherwise.

Return type:

bool

is_valid_xml(file_path)

Check whether the file is valid XML.

Parameters:

file_path (str) – The path to the XML file.

Returns:

True if the XML is valid, False otherwise.

Return type:

bool