pain001.xml package#

Submodules#

pain001.xml.create_common_elements module#

This module includes functions for creating XML documents in compliance with different versions of the pain.001 schema as defined in ISO 20022. These functions take a list of dictionaries containing the data to populate the XML document, as well as a dictionary that maps the column names in the data to the XML element names. The functions return the root element of the XML tree.

For more information on the ISO 20022 pain.001 schema, refer to the official ISO 20022 message definitions website:

pain001.xml.create_common_elements.create_common_elements(parent: Element, row: dict[str, Any], mapping: dict[str, str]) None[source]#

Creates common XML elements, specifically “PmtInfId” and “PmtMtd”, in the XML tree. This function uses data from the input Data files, which could either be CSV or SQLite data files.

Parameters:
  • parent (xml.etree.ElementTree.Element) – The parent element in the XML tree where the new elements will be added.

  • row (list of str) – A list of strings where each string represents a value from a single row in the Data file.

  • mapping (dict of {str: str}) – A dictionary mapping XML tags to corresponding Data file column names. For example, if “PmtInfId” maps to “PaymentInfoID”, the element “PmtInfId” will be created with the data from the “PaymentInfoID” column.

Returns:

This function modifies the XML tree in-place and does not return any value.

Return type:

None

pain001.xml.create_root_element module#

Module for creating XML payment initiation message documents compliant with the ISO 20022 standard. The generated XML documents include essential namespaces and schema locations.

Note: This module does not include additional security features for XML parsing. It is advisable to consider measures to prevent XML vulnerabilities when using it.

pain001.xml.create_root_element.create_root_element(message_type: str) Element[source]#

Creates the root Element for a payment initiation XML document based on the specified message type. The function sets the required namespaces and schema locations.

Parameters:
  • message_type (str)

  • type (Specifies the message)

  • example (for)

  • is ("pain.001.001.09". This)

  • attributes. (used to construct the namespace and schema location)

Returns:

The root Element node for the XML document, configured with the necessary namespaces and schema location attributes.

Return type:

et.Element

Examples

>>> create_root_element("pain.001.001.09")
<Element 'Document' at 0x7f8c0a309db0>

pain001.xml.create_xml_element module#

pain001.xml.create_xml_element.create_xml_element(parent: Element, tag: str, text: str | None = None, attributes: dict[str, str] | None = None) Element[source]#

Create and append an XML element with the specified tag, text, and attributes to a given parent element in the XML tree. The new element becomes a child of the parent element.

Parameters:
  • parent (xml.etree.ElementTree.Element) – The parent XML element to which the new element will be appended.

  • tag (str) – The name of the XML tag for the new element.

  • text (str, optional) – The text content to be inserted into the new XML element. Defaults to None.

  • attributes (dict of {str: str}, optional) – A dictionary containing the attribute names and their corresponding values to be set in the new XML element. Defaults to None.

Returns:

The newly created and appended XML element.

Return type:

xml.etree.ElementTree.Element

pain001.xml.create_xml_v3 module#

This module contains the function create_xml_v3, which constructs an XML tree for the ISO 20022 pain.001.001.03 schema.

The function takes in a root ElementTree element and a list of dictionaries containing the required data. It then uses Jinja2 templating to dynamically generate the XML content based on the given data. The function ultimately returns the root element of the modified XML tree.

pain001.xml.create_xml_v3.create_xml_v3(root: Element, data: list[dict[str, Any]]) Element[source]#

Constructs an XML tree based on the pain.001.001.03 schema and appends it to the provided root element. This function uses the Jinja2 templating engine to generate the XML content.

Parameters:
  • root (xml.etree.ElementTree.Element) – The root element of the XML tree to which the new elements will be appended.

  • data (list of dict) – A list of dictionaries, where each dictionary contains the data to be added to the XML document. The first dictionary usually contains common attributes that are used throughout the XML, while the subsequent dictionaries contain transaction-specific attributes.

Returns:

The updated root element of the XML tree.

Return type:

xml.etree.ElementTree.Element

pain001.xml.create_xml_v4 module#

This module contains the function create_xml_v4, which constructs an XML tree following the ISO 20022 pain.001.001.04 schema.

The function takes in a root ElementTree element and a list of dictionaries containing the required data. It then uses Jinja2 templating to dynamically generate the XML content based on the given data. The function ultimately returns the root element of the modified XML tree.

pain001.xml.create_xml_v4.create_xml_v4(root: Element, data: list[dict[str, Any]]) Element[source]#

Create an XML tree adhering to the pain.001.001.04 schema.

Parameters:
  • root (ET.Element) – The root element of the XML tree.

  • data (list) – A list of dictionaries containing data to populate the XML

  • document.

Returns:

The root element of the modified XML tree.

Return type:

ET.Element

pain001.xml.create_xml_v5 module#

This module contains the function create_xml_v5, which constructs an XML tree following the ISO 20022 pain.001.001.05 schema.

The function takes in a root ElementTree element and a list of dictionaries containing the required data. It then uses Jinja2 templating to dynamically generate the XML content based on the given data. The function ultimately returns the root element of the modified XML tree.

pain001.xml.create_xml_v5.create_xml_v5(root: Element, data: list[dict[str, Any]]) Element[source]#

Create the XML tree for the pain.001.001.05 schema.

Parameters:
  • root (ElementTree.Element) – The root element of the XML tree.

  • data (list) – A list of dictionaries containing the data to be added

  • document. (to the XML)

Returns:

The root element of the XML tree.

pain001.xml.create_xml_v6 module#

This module contains the function create_xml_v6, which constructs an XML tree following the ISO 20022 pain.001.001.06 schema.

The function takes in a root ElementTree element and a list of dictionaries containing the required data. It then uses Jinja2 templating to dynamically generate the XML content based on the given data. The function ultimately returns the root element of the modified XML tree.

pain001.xml.create_xml_v6.create_xml_v6(root: Element, data: list[dict[str, Any]]) Element[source]#

Create XML tree for pain.001.001.06 schema.

Parameters:
  • root (ElementTree.Element) – Root element of XML tree.

  • data (list) – List of dicts with data.

Returns:

Root element of updated XML tree.

Return type:

ElementTree.Element

pain001.xml.create_xml_v7 module#

This module contains the function create_xml_v7, which constructs an XML tree following the ISO 20022 pain.001.001.07 schema.

The function takes in a root ElementTree element and a list of dictionaries containing the required data. It then uses Jinja2 templating to dynamically generate the XML content based on the given data. The function ultimately returns the root element of the modified XML tree.

pain001.xml.create_xml_v7.create_xml_v7(root: Element, data: list[dict[str, Any]]) Element[source]#

Create XML tree for pain.001.001.07 schema.

Parameters:
  • root (ElementTree.Element) – Root element of XML tree.

  • data (list) – List of dicts with data.

Returns:

Root element of updated XML tree.

Return type:

ElementTree.Element

pain001.xml.create_xml_v8 module#

This module contains the function create_xml_v8, which constructs an XML tree following the ISO 20022 pain.001.001.08 schema.

The function takes in a root ElementTree element and a list of dictionaries containing the required data. It then uses Jinja2 templating to dynamically generate the XML content based on the given data. The function ultimately returns the root element of the modified XML tree.

pain001.xml.create_xml_v8.create_xml_v8(root: Element, data: list[dict[str, Any]]) Element[source]#

Create XML tree for pain.001.001.08 schema.

Parameters:
  • root (ElementTree.Element) – Root element of XML tree.

  • data (list) – List of dicts with data.

Returns:

Root element of updated XML tree.

Return type:

ElementTree.Element

pain001.xml.create_xml_v9 module#

This module contains the function create_xml_v9, which constructs an XML tree following the ISO 20022 pain.001.001.09 schema.

The function takes in a root ElementTree element and a list of dictionaries containing the required data. It then uses Jinja2 templating to dynamically generate the XML content based on the given data. The function ultimately returns the root element of the modified XML tree.

pain001.xml.create_xml_v9.create_xml_v9(root: Element, data: list[dict[str, Any]]) Element[source]#

Create the XML tree for the pain.001.001.09 schema.

Parameters:
  • root (ET.Element) – The root element of the XML tree.

  • data (list) – A list of dictionaries containing the data to be added

  • document. (to the XML)

Returns:

The root element of the XML tree.

pain001.xml.create_xml_v10 module#

This module contains the function create_xml_v10, which constructs an XML tree following the ISO 20022 pain.001.001.10 schema.

The function takes in a root ElementTree element and a list of dictionaries containing the required data. It then uses Jinja2 templating to dynamically generate the XML content based on the given data. The function ultimately returns the root element of the modified XML tree.

pain001.xml.create_xml_v10.create_xml_v10(root: Element, data: list[dict[str, Any]]) Element[source]#

Create the XML tree for the pain.001.001.10 schema.

Parameters:
  • root (ET.Element) – The root element of the XML tree.

  • data (list) – A list of dictionaries containing the data to be added

  • document. (to the XML)

Returns:

The root element of the XML tree.

pain001.xml.create_xml_v11 module#

This module contains the function create_xml_v11, which constructs an XML tree following the ISO 20022 pain.001.001.11 schema.

The function takes in a root ElementTree element and a list of dictionaries containing the required data. It then uses Jinja2 templating to dynamically generate the XML content based on the given data. The function ultimately returns the root element of the modified XML tree.

pain001.xml.create_xml_v11.create_xml_v11(root: Element, data: list[dict[str, Any]]) Element[source]#

Create the XML tree for the pain.001.001.11 schema.

Parameters:
  • root (ET.Element) – The root element of the XML tree.

  • data (list) – A list of dictionaries containing the data to be added

  • document. (to the XML)

Returns:

The root element of the XML tree.

pain001.xml.generate_updated_xml_file_path module#

pain001.xml.generate_updated_xml_file_path.generate_updated_xml_file_path(xml_file_path: str, payment_initiation_message_type: str) str[source]#

Generates the file path for an updated XML file.

Given the original XML file path and payment message type, this function constructs the file path for an updated version of the XML file with the provided message type in the filename.

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

  • payment_initiation_message_type (str) – The payment message type (e.g. ‘pain.001.001.04’).

Returns:

The file path to the updated XML file.

Return type:

str

pain001.xml.generate_xml module#

pain001.xml.generate_xml.generate_xml(data: list[dict[str, Any]], payment_initiation_message_type: str, xml_file_path: str, xsd_file_path: str) None[source]#

Generates an ISO 20022 pain.001 XML file from input data.

This function writes XML to a file. For in-memory XML generation (serverless/API use cases), use generate_xml_string() instead.

Parameters:
  • data – List of dictionaries containing payment data

  • payment_initiation_message_type – String indicating message type

  • "pain.001.001.03 (such as)

  • pain.001.001.04

  • pain.001.001.05

:param : :param pain.001.001.06: :param pain.001.001.07: :param pain.001.001.08: :param etc.”: :param xml_file_path: Path to write generated XML file to :param xsd_file_path: Path to XML schema file for validation

Returns:

None

Raises:
  • ValueError – If message type is invalid or data is empty.

  • RuntimeError – If XML validation fails.

pain001.xml.generate_xml.generate_xml_string(data: list[dict[str, Any]], payment_initiation_message_type: str, xml_template_path: str, xsd_schema_path: str) str[source]#

Generate ISO 20022 pain.001 XML content as a string (in-memory).

This function is ideal for serverless architectures, REST APIs, and microservices where XML needs to be returned without writing to disk.

Parameters:
  • data – List of dictionaries containing payment data.

  • payment_initiation_message_type – Message type (e.g., “pain.001.001.03”).

  • xml_template_path – Path to the Jinja2 XML template file.

  • xsd_schema_path – Path to XSD schema file for validation.

Returns:

The generated and validated XML content.

Return type:

str

Raises:
  • ValueError – If message type is invalid or data is empty.

  • RuntimeError – If XML validation fails against XSD schema.

Examples

>>> data = [{"id": "MSG001", "date": "2026-01-15", ...}]
>>> xml_str = generate_xml_string(
...     data,
...     "pain.001.001.03",
...     "templates/pain.001.001.03/template.xml",
...     "templates/pain.001.001.03/pain.001.001.03.xsd"
... )  
>>> xml_str.startswith('<?xml')
True

pain001.xml.register_namespaces module#

pain001.xml.register_namespaces.register_namespaces(payment_initiation_message_type: str) None[source]#

This function registers the namespaces for the payment initiation message type.

Parameters:
  • payment_initiation_message_type (str)

  • type. (The payment initiation message)

Returns:

None.

pain001.xml.validate_via_xsd module#

pain001.xml.validate_via_xsd.validate_via_xsd(xml_file_path: str, xsd_file_path: str) bool[source]#

Validates an XML file against an XSD schema.

Parameters:
  • xml_file_path (str) – Path to the XML file to validate.

  • xsd_file_path (str) – Path to the XSD schema file.

Returns:

True if the XML file is valid, False otherwise.

Return type:

bool

pain001.xml.validate_via_xsd.validate_xml_string_via_xsd(xml_content: str, xsd_file_path: str) bool[source]#

Validates an XML string against an XSD schema.

This function is ideal for serverless/API architectures where XML is generated in-memory without writing to disk.

Parameters:
  • xml_content (str) – XML content as a string.

  • xsd_file_path (str) – Path to the XSD schema file.

Returns:

True if the XML content is valid, False otherwise.

Return type:

bool

Examples

>>> xml_str = '<?xml version="1.0"?><Document></Document>'
>>> xsd_path = "schema.xsd"
>>> validate_xml_string_via_xsd(xml_str, xsd_path)  
True

pain001.xml.write_xml_to_file module#

This module contains a utility function for writing XML content to a file. The XML content is pretty-formatted with proper indentation for better readability.

pain001.xml.write_xml_to_file.indent_xml(elem: Element, level: int = 0) None[source]#

Add indentation to XML elements in-place for pretty printing.

This is a fast, memory-efficient way to format XML without re-parsing.

Parameters:
  • elem (xml.etree.ElementTree.Element) – The element to indent.

  • level (int) – The current indentation level.

pain001.xml.write_xml_to_file.write_xml_to_file(xml_file_path: str, root: Element) None[source]#

Write the XML tree to a file, with pretty formatting (indentation).

This optimized version uses in-place indentation instead of minidom, providing ~70% faster performance and ~50% memory reduction.

Parameters:
  • xml_file_path (str) – The file path where the XML content will be written.

  • root (xml.etree.ElementTree.Element) – The root element of the XML tree.

Returns:

The function writes the XML content to a file and does not return any value.

Return type:

None

Module contents#