Diese Referenz dokumentiert die Kommandozeilenschnittstelle, die Python-API, den REST-Microservice und die Validierungspipeline von pain001 v0.0.91. Jedes hier aufgeführte Flag, jeder Endpunkt und jedes Verhalten ist dem ausgelieferten Code entnommen, nicht dem Wunschdenken.
Pain001 unterstützt 13 ISO 20022-Nachrichtendefinitionen: pain.001.001.03 bis pain.001.001.13 (Customer Credit Transfer Initiation, elf Versionen) und pain.008.001.02 / pain.008.001.08 (Customer Direct Debit Initiation).
1. Kommandozeilenschnittstelle#
Das pain001-Programm gliedert seine Funktionalität in Subcommands. Wird es nur mit Generierungs-Flags aufgerufen, ruft es implizit generate auf, sodass bestehende Automatisierung weiter funktioniert.
| Unterbefehl | Zweck |
|---|---|
generate | Wandelt eine Datendatei in schemavalidiertes ISO 20022-XML um (Standardbefehl). |
validate | Validiert Eingabedaten, ohne XML zu schreiben. |
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] | Listet alle 13 unterstützten Nachrichtendefinitionen auf. |
inspect <type> [--format json] | Zeigt die mitgelieferte Vorlage, das Schema, Beispieldaten und die akzeptierten Eingabeformate für einen Nachrichtentyp an. |
init <type> [-o FILE] | Erzeugt eine CSV-Startvorlage für einen Nachrichtentyp. |
serve [--host] [--port] [--reload] | Startet den FastAPI-REST-Microservice (erfordert das Extra api). |
mcp | Startet den eingebauten Model-Context-Protocol-Server der Kernbibliothek über stdio (erfordert das Extra mcp); der vollständige Server wird als pain001-mcp ausgeliefert. |
plugins list / show / disable | Listet die gefundenen Loader-, Validator-, Scheme- und Writer-Plugins auf, zeigt eines an oder gibt aus, wie sich die Erkennung von Drittanbieter-Plugins abschalten lässt. |
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). |
Optionen von generate
| Option | Beschreibung |
|---|---|
-t, --xml-message-type <TYPE> | Nachrichtendefinition, z. B. pain.001.001.09. |
-d, --data <FILE> | Eingabedaten: .csv, .json, .jsonl, .db / .sqlite, .parquet oder PGP-verschlüsselt .gpg / .asc. |
-o, --output-dir <DIR> | Verzeichnis, in dem das generierte XML abgelegt wird. |
-m, --template <FILE> / -s, --schema <FILE> | Überschreibt die mitgelieferte Jinja2-Vorlage bzw. das XSD-Schema. |
-c, --config <FILE> | Lädt Standardwerte aus einem Konfigurationsprofil (--profile, --show-config). |
--dry-run (Alias --validate-only) | Validiert die Eingabe gegen das JSON-Schema, das XSD und das Scheme-Regelwerk, ohne Ausgabe zu schreiben. |
--scheme <NAME[,NAME]> | Erzwingt ein oder mehrere Scheme-Regelwerke, durch Kommas getrennt. pain001 plugins list nennt jedes installierte Regelwerk. |
--explain / --format json | Gibt mit --scheme für jeden Verstoß einen Behebungshinweis aus, als Text oder 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> | Speicherbegrenzte, blockweise Verarbeitung großer Stapel (standardmäßig 1,000 Transaktionen pro Block; jeder Block wird zu einer eigenen XML-Datei mit neu berechneten NbOfTxs und CtrlSum). |
--emit-metrics | Gibt maschinenlesbare Laufmetriken für Observability-Pipelines aus. |
--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. |
Die Exit-Codes sind CI-freundlich: 0 Erfolg, 1 Validierungsfehler, 2 Bedienfehler.
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#
# Generate a validated pain.001.001.09 file from CSV
Jedes generierte Dokument durchläuft drei Schichten, bevor es geschrieben wird:
- Eingabevalidierung: Jeder Datensatz wird gegen das JSON-Schema des Nachrichtentyps geprüft, mit Feld-Alias-Normalisierung und IBAN/BIC-Syntaxprüfungen.
- Scheme-Regelwerk (optional): die Regeln des Zahlungssystems, das Sie angeben, von SEPA (SCT, Instant, SDD Core, B2B) bis zu nationalen Systemen wie UK Faster Payments, CHAPS und Bacs, US-ACH und Überweisungen sowie Swift CBPR+;
pain001 plugins listnennt sie alle. - XSD-Validierung: Das gerenderte XML wird über
xmlschemagegen das offizielle ISO 20022-Schema validiert, bevor auch nur ein Byte auf die Festplatte geschrieben wird. Ist das optionale Extrafast(lxml) installiert, akzeptiert libxml2 gültige Dokumente schneller; ein Dokument, das es ablehnt, prüftxmlschemaerneut, und dessen Urteil ist endgültig.
Geldbeträge werden bei der XML-Generierung und Scheme-Validierung als decimal.Decimal behandelt (niemals als IEEE 754-Gleitkommazahlen), und die Kontrollsummen NbOfTxs / CtrlSum werden aus den validierten Datensätzen neu berechnet, statt der Eingabe zu vertrauen.
Über die pain.001-Generierung hinaus liefert die Kernbibliothek auch einen pain.002-Statusbericht-Parser und -Generator (damit Sie die Annahme- bzw. Ablehnungsantwort der Bank lesen können) und einen camt.053-Kontoauszug-Parser und -Generator für den Tagesabschluss-Abgleich, dazu einen VersionMapper, der Datensätze zwischen Nachrichtenversionen migriert.
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#
Alle Endpunkte sind unter /api/v1 eingebunden (mit einem unversionierten Alias /api):
| Methode & Pfad | Zweck |
|---|---|
GET /api/v1/health | Liveness-Probe. |
POST /api/v1/validate | Validiert Datensätze; liefert Fehler auf Feldebene zurück. |
POST /api/v1/generate | Synchrone XML-Generierung. |
POST /api/v1/generate/async | Stellt einen großen Stapel zur Hintergrundgenerierung in die Warteschlange. |
GET /api/v1/status/{job_id} | Fragt einen asynchronen Job ab. |
GET /api/v1/download/{job_id} | Lädt das fertige XML herunter. |
DELETE /api/v1/jobs/{job_id} | Räumt einen abgeschlossenen Job auf. |
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-Metriken. |
Interaktive Dokumentation wird unter /api/docs (Swagger UI), /api/redoc und /api/reference (Scalar) bereitgestellt, das OpenAPI-Dokument unter /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. Eingabenormalisierung#
Pain001 überführt Exporte aus der Praxis vor der Validierung in gültige Datensätze:
- Feld-Aliase: Gängige ERP-Spaltennamen werden auf kanonische Felder abgebildet (zum Beispiel
amount→payment_amount). - IBAN-/BIC-Normalisierung: Leerzeichen entfernt, Groß-/Kleinschreibung vereinheitlicht, dann geprüft (ISO 13616 mod-97 für IBANs, ISO 9362-Struktur für BICs).
- Datumsangaben: ISO 8601-
YYYY-MM-DD-Parsing für Ausführungsdaten. - Beträge: laufen durch
decimal.Decimal; fehlerhafte Beträge scheitern an der Validierung, statt stillschweigend gerundet zu werden. - Zeichensatz: Transliterationshelfer reduzieren Inhalte auf den von SWIFT und SEPA akzeptierten lateinischen ISO 20022-Zeichensatz.
- 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-Architektur#
Die Suite ist über vier Entry-Point-Gruppen erweiterbar: pain001.loaders, pain001.validators, pain001.schemes und pain001.writers. pain001-loader-xlsx registriert sich über diesen Mechanismus und wird bei der Installation automatisch erkannt; pain001-loader-mt101 ist eine eigenständige Parsing-Bibliothek, die direkt genutzt wird (sowie vom convert_mt101-Tool des MCP-Servers). Ein Notschalter (PAIN001_DISABLE_PLUGINS=1) deaktiviert die Erkennung von Drittanbieter-Plugins in abgeschotteten Umgebungen vollständig.
6. Qualitätsprüfungen#
Die Kernbibliothek wird gegen strenge, überprüfbare Schranken entwickelt: 100% Zeilen- und Zweigabdeckung, in der CI erzwungen (--cov-fail-under=100), striktes mypy-Typing, 100% Docstring-Abdeckung und Sicherheits-Linting (Bandit, pip-audit). Für jeden Release-Build wird eine CycloneDX-SBOM erzeugt.
Fahren Sie fort mit der Installationsanleitung, dem MCP-Server für KI-Agenten oder dem Zahlungsverkehrsglossar.
