Pain001 installation
Pain001 is a powerful Python library that enables you to create ISO 20022-compliant payment files directly from CSV or SQLite Data Files.
Get started
It takes just a few seconds to get up and running with Pain001. If you use pip, open your terminal and run the following command:
pip install pain001
Add the -U switch to update to the current version, if pain001
is already
installed. For example:
pip install -U pain001
If you do not have pip installed, you can download and install it from this page: https://pypi.org/project/pip/. Alternatively, you can use Anaconda to install pip.
How do I use Pain001?
It’s easy to use Pain001 to generate a payment initiation message from a CSV or SQLite Data file. After installation, you can run Pain001 directly from the command line.
Simply call the main module pain001 with the paths of your:
- XML template file containing the various parameters you want to pass from your Data file,
- XSD schema file to validate the generated XML file, and
- Data file (CSV or SQLite) containing the payment instructions that you want to submit.
Here’s how you would do that:
python3 -m pain001 \
<xml_message_type> \
<xml_template_file_path> \
<xsd_schema_file_path> \
<data_file_path>
Arguments
When running Pain001, you will need to specify four arguments:
-
An
xml_message_type
: This is the type of XML message you want to generate.The currently supported types are:
- pain.001.001.03
- pain.001.001.04
- pain.001.001.09
-
An
xml_template_file_path
: This is the path to the XML template file you are using that contains variables that will be replaced by the values in your Data file. -
An
xsd_schema_file_path
: This is the path to the XSD schema file you are using to validate the generated XML file. -
A
data_file_path
: This is the path to the CSV or SQLite Data file you want to convert to XML format.
Examples
The following examples demonstrate how to use Pain001 to generate a payment initiation message from a CSV file and a SQLite Data file.
Using a CSV Data File as the source
python3 -m pain001 \
pain.001.001.03 \
/path/to/your/template.xml \
/path/to/your/pain.001.001.03.xsd \
/path/to/your/template.csv
Using a SQLite Data File as the source
python3 -m pain001 \
pain.001.001.03 \
/path/to/your/template.xml \
/path/to/your/pain.001.001.03.xsd \
/path/to/your/template.db
Using the Source code
You can clone the source code and run the example code in your terminal/command-line. To check out the source code, clone the repository from GitHub:
git clone https://github.com/sebastienrousseau/pain001.git
Then, navigate to the pain001
directory and run the following command:
python3 -m pain001 \
pain.001.001.03 \
templates/pain.001.001.03/template.xml \
templates/pain.001.001.03/pain.001.001.03.xsd \
templates/pain.001.001.03/template.csv
This will generate a payment initiation message from the sample CSV Data file.
You can do the same with the sample SQLite Data file:
python3 -m pain001 \
pain.001.001.03 \
templates/pain.001.001.03/template.xml \
templates/pain.001.001.03/pain.001.001.03.xsd \
templates/pain.001.001.03/template.db
Note: The XML file that Pain001 generates will automatically be validated against the XSD template file before the new XML file is saved. If the validation fails, Pain001 will stop running and display an error message in your terminal.
Embedded in an Application
To embed Pain001 in a new or existing application, import the main function and use it in your code.
Here’s an example:
from pain001 import main
if __name__ == '__main__':
xml_message_type = 'pain.001.001.03'
xml_template_file_path = 'template.xml'
xsd_schema_file_path = 'schema.xsd'
data_file_path = 'data.csv'
main(
xml_message_type,
xml_template_file_path,
xsd_schema_file_path,
data_file_path
)
Validation
To validate the generated XML file against a given xsd schema, use the following method:
from pain001.core import validate_xml_against_xsd
xml_message_type = 'pain.001.001.03'
xml_file = 'generated.xml'
xsd_file = 'schema.xsd'
is_valid = validate_xml_against_xsd(
xml_message_type,
xml_file,
xsd_file
)
print(f"XML validation result: {is_valid}")