pain001 package#

Subpackages#

Module contents#

The Python pain001 module.

exception pain001.DataSourceError[source]#

Bases: Pain001Error

Raised when data source access fails.

This exception indicates issues with: - File not found (CSV, SQLite) - Database connection errors - Corrupted data files - Unsupported file formats - Empty data sources

Example

>>> try:
...     load_payment_data("payments.csv")
... except DataSourceError as e:
...     # Data access error - check file exists
...     log.error(f"Cannot access data source: {e}")
exception pain001.PaymentValidationError(message: str, field: str | None = None)[source]#

Bases: Pain001Error

Raised when payment data validation fails.

This exception indicates issues with input data such as: - Invalid IBAN format - Invalid BIC/SWIFT code - Invalid amount (negative, too large, wrong format) - Missing required fields (debtor name, creditor account, etc.) - Invalid date formats

Example

>>> try:
...     validate_payment_data(data)
... except PaymentValidationError as e:
...     # User-facing error - show validation message
...     return {"error": str(e), "field": e.field}
pain001.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.main(xml_message_type: str | None, xml_template_file_path: str | None, xsd_schema_file_path: str | None, data_file_path: str | None, dry_run: bool = False) None[source]#

Main entry point for python -m pain001.

Parameters:
  • xml_message_type – ISO 20022 message type (e.g., ‘pain.001.001.03’).

  • xml_template_file_path – Path to Jinja2 XML template file.

  • xsd_schema_file_path – Path to XSD schema for validation.

  • data_file_path – Path to CSV or SQLite data file.

  • dry_run – If True, validate inputs without generating XML.

Exits:

0 on success, 1 on validation or processing error.

pain001.process_files(xml_message_type: str, xml_template_file_path: str, xsd_schema_file_path: str, data_file_path: str | list[dict[str, Any]] | dict[str, Any]) None[source]#

Generate an ISO 20022 payment message from various data sources.

Parameters:
  • xml_message_type – XML message type (e.g., ‘pain.001.001.03’).

  • xml_template_file_path – Path to the XML template file.

  • xsd_schema_file_path – Path to the XSD schema file.

  • data_file_path – File path (CSV/DB/JSON/Parquet) or Python data (list/dict).

Raises:
  • ValueError – If the XML message type is not supported or data is invalid.

  • FileNotFoundError – If required files do not exist.