Referentie

Pain001 Technische Referentie: CLI, Python-API en REST

Elke vlag, elk endpoint en elk gedrag van pain001 v0.0.91, ontleend aan de uitgeleverde code en niet aan wensdenken.

Deze referentie documenteert de opdrachtregelinterface, de Python-API, de REST-microservice en de validatiepijplijn van pain001 v0.0.91. Elke vlag, elk endpoint en elk gedrag dat hier staat, is ontleend aan de uitgeleverde code, niet aan wensdenken.

Pain001 ondersteunt 13 ISO 20022-berichtdefinities: pain.001.001.03 tot en met pain.001.001.13 (Customer Credit Transfer Initiation, elf versies) en pain.008.001.02 / pain.008.001.08 (Customer Direct Debit Initiation).


1. Opdrachtregelinterface#

Het uitvoerbare bestand pain001 groepeert zijn functionaliteit in subcommando's. Roept u het alleen met generatievlaggen aan, dan wordt generate impliciet uitgevoerd, zodat bestaande automatisering blijft werken.

Subcommando Doel
generate Zet een gegevensbestand om in schemagevalideerde ISO 20022-XML (standaardcommando).
validate Valideer invoergegevens zonder XML te schrijven.
check <file>... [--scheme] [--format] Check pain.001 or pain.008 files you already have: the XSD of the message type each file declares, the message definition's cross-element rules, and any scheme profiles, policy or Schematron rulebook you name.
verify-signature <file>... --cert <PEM> Verify the XML-DSig signature on each file against the signer's certificate or public key; --trust-embedded-cert checks integrity only (requires the sign extra).
versions [--format json] Toon alle 13 ondersteunde berichtdefinities.
inspect <type> [--format json] Toont het meegeleverde sjabloon, het schema, voorbeeldgegevens en de geaccepteerde invoerformaten voor een berichttype.
init <type> [-o FILE] Genereer een CSV-startsjabloon voor een berichttype.
serve [--host] [--port] [--reload] Start de FastAPI REST-microservice (vereist de extra api).
mcp Start de ingebouwde Model Context Protocol-server van de kernbibliotheek via stdio (vereist de extra mcp); de volledige server wordt geleverd als pain001-mcp.
plugins list / show / disable Toont de gevonden loader-, validator-, scheme- en writer-plug-ins, laat er één zien, of geeft aan hoe u het vinden van plug-ins van derden uitschakelt.
face <file> [--face] [--bindings] [-o] [--loss-report] Project a pain.001 XML file into another standard's JSON shape, with a report of every element not carried.
upload [<file>] --sftp <url> Deliver a file atomically to an SFTP server you trust explicitly (requires the upload extra).

Opties voor generate

Vlag Beschrijving
-t, --xml-message-type <TYPE> Berichtdefinitie, bijv. pain.001.001.09.
-d, --data <FILE> Invoergegevens: .csv, .json, .jsonl, .db / .sqlite, .parquet, of met PGP versleutelde .gpg / .asc.
-o, --output-dir <DIR> Map waarin de gegenereerde XML terechtkomt.
-m, --template <FILE> / -s, --schema <FILE> Overschrijf het meegeleverde Jinja2-sjabloon of XSD-schema.
-c, --config <FILE> Laad standaardwaarden uit een configuratieprofiel (--profile, --show-config).
--dry-run (alias --validate-only) Valideer de invoer tegen het JSON Schema, het XSD en het scheme-rulebook zonder uitvoer te schrijven.
--scheme <NAME[,NAME]> Past een of meer scheme-regelboeken toe, gescheiden door komma's. pain001 plugins list noemt elk geïnstalleerd regelboek.
--explain / --format json Geeft met --scheme voor elke overtreding een hersteltip, als tekst of JSON.
--rules <FILE> Enforce a private YAML CEL policy before generation (requires the rules extra).
--schematron <PRESET or FILE> Apply Schematron business rules: the sepa, fednow or cbpr preset, or your own .sch file.
--decrypt-key <FILE> / --decrypt-passphrase-env <VAR> Import a GPG private key, and name the variable that holds its passphrase, for .gpg / .asc input (requires the gpg extra).
--streaming / --chunk-size <N> Geheugenbegrensde verwerking in chunks voor grote batches (standaard 1,000 transacties per chunk; elke chunk wordt een eigen XML-bestand met herberekende NbOfTxs en CtrlSum).
--emit-metrics Geef machineleesbare uitvoeringsmetrieken af voor observability-pijplijnen.
--envelop-bah Wrap generated payment XML into an ISO 20022 Business Application Header (head.001.001.03) and BizData (head.003.001.01) envelope.
--bah-sender <BIC/ID> Sender financial institution BIC or organisation identifier for BAH <Fr>.
--bah-receiver <BIC/ID> Receiver financial institution BIC or organisation identifier for BAH <To>.
--bah-msg-id <ID> Business Message Identifier for BAH <BizMsgIdr> (defaults to generated UUID).
--xml-sign-key <FILE> PEM private key (RSA, or EC P-256/P-384) for a W3C XML Digital Signature (XML-DSig); the algorithm follows the key.
--xml-sign-cert <FILE> Optional PEM X.509 certificate to embed in XML-DSig <ds:KeyInfo>.
--xml-sign-alg <ALG> rsa-sha256, rsa-pss-sha256, ecdsa-sha256 or ecdsa-sha384; by default an RSA key signs rsa-sha256.
--xml-sign-passphrase-env <VAR> Environment variable holding the passphrase for --xml-sign-key.
--list-templates / --show-template <TYPE> List the bundled templates, or show one template's metadata, and exit.

De exitcodes zijn CI-vriendelijk: 0 geslaagd, 1 validatiefout, 2 gebruiksfout.

XML signing and verify-signature need the sign extra (pip install "pain001[sign]", which installs cryptography and lxml).

Signatures: pain001 verify-signature

pain001 verify-signature checks the signature on files you received or wrote. Pass the signer's certificate or public key with --cert; that is the trust anchor. --trust-embedded-cert verifies with each file's own certificate instead, which proves the file is unchanged since it was signed but not who signed it. It exits 0 when every file verifies, 1 when any does not, and 2 when it cannot run; --format json prints one report per file. Verification uses exclusive C14N 1.0 and accepts only RSA-SHA256, RSA-PSS and ECDSA signatures with SHA-256 to SHA-512 digests over the whole document; the certificate's chain and validity dates are not checked.

Faces: pain001 face

A face projects a validated pain.001 document into another standard's JSON request body. --face uk_open_banking targets the Open Banking Read/Write API v4.0.1 domestic payment, --face berlin_group targets NextGenPSD2 v1.3.16 payment initiation, and --face iso_2018 renames every element to its ISO 20022 name in snake_case. A face refuses a document that lacks an element its target requires instead of inventing a value; --loss-report lists every source element it did not carry. Faces are outbound only.

Delivery: pain001 upload

pain001 upload sends a finished file to an SFTP server you name, and only after you have trusted its host key: from a known_hosts file (--known-hosts) or an OpenSSH SHA256 fingerprint you verified independently (--accept-host-key). --print-host-key shows the server's fingerprint without logging in. It logs in with a private key (--identity-file, with --passphrase-env), a password read from an environment variable (--password-env), or your SSH agent. The file is written under a temporary name and renamed on the server, so the receiving side never sees a partial file.


2. Python-API#

from pain001.core.core import process_files

# Generate a validated pain.001.001.09 file from CSV
process_files(
    xml_message_type="pain.001.001.09",
    xml_template_file_path="template.xml",
    xsd_schema_file_path="schema.xsd",
    data_file_path="payments.csv",
    output_path="out/payments.xml",
)

Elk gegenereerd document doorloopt drie lagen voordat het wordt weggeschreven:

  1. Invoervalidatie: elk record wordt gecontroleerd tegen het JSON Schema van het berichttype, met normalisatie van veldaliassen en syntaxiscontroles op IBAN en BIC.
  2. Scheme-rulebook (optioneel): de regels van het betaalsysteem dat u opgeeft, van SEPA (SCT, Instant, SDD Core, B2B) tot nationale systemen zoals UK Faster Payments, CHAPS en Bacs, Amerikaanse ACH en wires, en Swift CBPR+; pain001 plugins list noemt ze allemaal.
  3. XSD-validatie: de gerenderde XML wordt via xmlschema gevalideerd tegen het officiële ISO 20022-schema voordat er ook maar één byte naar schijf gaat. Met de optionele extra fast (lxml) geïnstalleerd accepteert libxml2 geldige documenten sneller; een document dat het afwijst, wordt opnieuw gecontroleerd door xmlschema, waarvan het oordeel definitief is.

Geldbedragen worden tijdens XML-generatie en scheme-validatie behandeld als decimal.Decimal (nooit als IEEE 754-floats), en de controletotalen NbOfTxs / CtrlSum worden herberekend uit de gevalideerde records in plaats van blind uit de invoer overgenomen.

Naast het genereren van pain.001 levert de kernbibliotheek ook een parser en generator voor pain.002-statusrapporten (zodat u het accepteer- of afwijsantwoord van de bank kunt lezen) en een parser en generator voor camt.053-afschriften voor de reconciliatie aan het eind van de dag, plus een VersionMapper die records tussen berichtversies migreert.

pain001.faces.project_face is the Python entry point for faces. sign_xml_document signs a document with XML-DSig, and verify_signature(signed_xml, trust_anchor=cert_pem) verifies one and returns a SignatureReport (valid, trust, algorithm, signer, reason); both need the sign extra. verify_xml_signature without a key or certificate still trusts the certificate inside the document, with a DeprecationWarning; pain001 0.0.91 refuses it.

Runnable, self-checking scripts for the public API and the CLI live in the library's examples/ directory.


3. REST-microservice#

pip install "pain001[api]"
pain001 serve --host 0.0.0.0 --port 8000

Alle endpoints hangen onder /api/v1 (met een ongeversioneerde alias /api):

Methode & pad Doel
GET /api/v1/health Liveness-probe.
POST /api/v1/validate Valideert records; geeft fouten op veldniveau terug.
POST /api/v1/generate Synchrone XML-generatie.
POST /api/v1/generate/async Zet een grote batch in de wachtrij voor generatie op de achtergrond.
GET /api/v1/status/{job_id} Vraag de status van een asynchrone taak op.
GET /api/v1/download/{job_id} Download de voltooide XML.
DELETE /api/v1/jobs/{job_id} Ruim een afgeronde taak op.
GET /api/v1/faces List the faces and the binding keys each accepts.
POST /api/v1/faces/{face} Project a pain.001 document sent as XML text; returns the payload and the loss report, or 422 with the reason the face refused it.
GET /metrics Prometheus-metrieken.

Interactieve documentatie wordt aangeboden op /api/docs (Swagger UI), /api/redoc en /api/reference (Scalar), met het OpenAPI-document op /openapi.json.

When the PAIN001_API_KEY environment variable is set, every endpoint except /health and /metrics requires it as a bearer token; when it is unset, the API is open. pain001 serve binds to 127.0.0.1 unless you pass --host.


4. Invoernormalisatie#

Pain001 vormt exports uit de praktijk om tot geldige records vóór de validatie:

  • Veldaliassen: gangbare ERP-kolomnamen worden op canonieke velden afgebeeld (bijvoorbeeld amount → payment_amount).
  • IBAN-/BIC-normalisatie: spaties verwijderd, hoofdlettergebruik genormaliseerd en daarna gecontroleerd (ISO 13616 mod-97 voor IBAN's, ISO 9362-structuur voor BIC's).
  • Datums: ISO 8601-parsing in de vorm YYYY-MM-DD voor uitvoeringsdatums.
  • Bedragen: verwerkt via decimal.Decimal; onjuist opgemaakte bedragen falen de validatie in plaats van stilzwijgend te worden afgerond.
  • Tekenset: transliteratiehulpmiddelen brengen de inhoud terug tot de Latijnse ISO 20022-tekenset die SWIFT en SEPA accepteren.
  • Formula cells: CSV cells that start with =, +, - or @ are kept as supplied by default, so phone numbers and references survive; load_csv_data(path, sanitize_formula=True) escapes them with a leading quote instead.

5. Plugin-architectuur#

De suite is uitbreidbaar via vier entry-pointgroepen: pain001.loaders, pain001.validators, pain001.schemes en pain001.writers. pain001-loader-xlsx registreert zich via dit mechanisme en wordt bij installatie automatisch gevonden; pain001-loader-mt101 is een zelfstandige parsingbibliotheek die rechtstreeks wordt gebruikt (en door de tool convert_mt101 van de MCP-server). Een noodschakelaar, PAIN001_DISABLE_PLUGINS=1, schakelt de detectie van plugins van derden volledig uit in afgeschermde omgevingen.


6. Kwaliteitspoorten#

De kernbibliotheek wordt ontwikkeld tegen strikte, verifieerbare poorten: 100% regel- en branchdekking, afgedwongen in CI (--cov-fail-under=100), strikte mypy-typing, 100% docstringdekking en security-linting (Bandit, pip-audit). Voor elke releasebuild wordt een CycloneDX-SBOM gegenereerd.

Ga verder met de installatiehandleiding, de MCP-server voor AI-agents of het betalingsglossarium.