เอกสารอ้างอิงนี้อธิบายอินเทอร์เฟซบรรทัดคำสั่ง Python API ไมโครเซอร์วิส REST และไปป์ไลน์การตรวจสอบความถูกต้องของ pain001 v0.0.91 ทุกแฟล็ก ทุก endpoint และทุกพฤติกรรมที่ระบุไว้ที่นี่นำมาจากโค้ดที่เผยแพร่จริง ไม่ใช่จากความคาดหวัง
Pain001 รองรับนิยามข้อความ ISO 20022 จำนวน 13 รายการ ได้แก่ pain.001.001.03 ถึง pain.001.001.13 (Customer Credit Transfer Initiation จำนวนสิบเอ็ดเวอร์ชัน) และ pain.008.001.02 / pain.008.001.08 (Customer Direct Debit Initiation)
1. อินเทอร์เฟซบรรทัดคำสั่ง#
ไฟล์ปฏิบัติการ pain001 จัดกลุ่มความสามารถไว้เป็นคำสั่งย่อย หากเรียกใช้ด้วยแฟล็กสำหรับการสร้างไฟล์เพียงอย่างเดียว ระบบจะเรียก generate โดยปริยาย ระบบอัตโนมัติที่มีอยู่เดิมจึงทำงานได้ต่อไป
| คำสั่งย่อย | วัตถุประสงค์ |
|---|---|
generate | แปลงไฟล์ข้อมูลเป็น XML ตามมาตรฐาน ISO 20022 ที่ผ่านการตรวจสอบกับสกีมา (คำสั่งเริ่มต้น) |
validate | ตรวจสอบความถูกต้องของข้อมูลนำเข้าโดยไม่เขียนไฟล์ XML |
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] | แสดงรายการนิยามข้อความที่รองรับทั้ง 13 รายการ |
inspect <type> [--format json] | แสดงเทมเพลตที่มาพร้อมกัน สคีมา ข้อมูลตัวอย่าง และรูปแบบข้อมูลนำเข้าที่รองรับสำหรับประเภทข้อความหนึ่ง |
init <type> [-o FILE] | สร้างเทมเพลต CSV ตั้งต้นสำหรับข้อความแต่ละประเภท |
serve [--host] [--port] [--reload] | เริ่มไมโครเซอร์วิส REST ที่พัฒนาด้วย FastAPI (ต้องติดตั้งส่วนเสริม api) |
mcp | เริ่มเซิร์ฟเวอร์ Model Context Protocol ที่มีในไลบรารีหลักผ่าน stdio (ต้องใช้ส่วนเสริม mcp) ส่วนเซิร์ฟเวอร์ฉบับเต็มเผยแพร่ในชื่อ pain001-mcp |
plugins list / show / disable | แสดงรายการปลั๊กอินตัวโหลด ตัวตรวจสอบ สคีม และตัวเขียนที่ค้นพบ แสดงปลั๊กอินหนึ่งตัว หรือบอกวิธีปิดการค้นหาปลั๊กอินจากบุคคลที่สาม |
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). |
ตัวเลือกของ generate
| แฟล็ก | คำอธิบาย |
|---|---|
-t, --xml-message-type <TYPE> | นิยามข้อความ เช่น pain.001.001.09 |
-d, --data <FILE> | ข้อมูลนำเข้า: .csv, .json, .jsonl, .db / .sqlite, .parquet หรือไฟล์ที่เข้ารหัสด้วย PGP .gpg / .asc |
-o, --output-dir <DIR> | ไดเรกทอรีที่จัดเก็บไฟล์ XML ที่สร้างขึ้น |
-m, --template <FILE> / -s, --schema <FILE> | แทนที่เทมเพลต Jinja2 หรือสกีมา XSD ที่มาพร้อมในตัว |
-c, --config <FILE> | โหลดค่าเริ่มต้นจากโปรไฟล์การตั้งค่า (--profile, --show-config) |
--dry-run (ชื่อเรียกอื่น --validate-only) | ตรวจสอบข้อมูลนำเข้ากับ JSON Schema, XSD และกฎเกณฑ์ของสกีม โดยไม่เขียนไฟล์ผลลัพธ์ |
--scheme <NAME[,NAME]> | บังคับใช้กฎสคีมหนึ่งชุดขึ้นไป คั่นด้วยจุลภาค pain001 plugins list จะแสดงชื่อกฎทุกชุดที่ติดตั้งไว้ |
--explain / --format json | เมื่อใช้ร่วมกับ --scheme จะพิมพ์คำแนะนำการแก้ไขสำหรับการละเมิดแต่ละรายการ เป็นข้อความหรือ 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> | การประมวลผลเป็นก้อนโดยจำกัดการใช้หน่วยความจำสำหรับชุดข้อมูลขนาดใหญ่ (ค่าเริ่มต้น 1,000 รายการต่อก้อน แต่ละก้อนจะกลายเป็นไฟล์ XML ของตนเอง พร้อมคำนวณ NbOfTxs และ CtrlSum ขึ้นใหม่) |
--emit-metrics | ส่งออกเมตริกการทำงานในรูปแบบที่เครื่องอ่านได้สำหรับไปป์ไลน์การสังเกตการณ์ระบบ |
--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. |
รหัสสถานะการออกออกแบบมาให้ใช้กับ CI ได้: 0 สำเร็จ, 1 การตรวจสอบไม่ผ่าน, 2 ใช้คำสั่งไม่ถูกต้อง
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
เอกสารทุกฉบับที่สร้างขึ้นต้องผ่านการตรวจสามชั้นก่อนถูกเขียนลงไฟล์:
- การตรวจสอบข้อมูลนำเข้า: แต่ละระเบียนจะถูกตรวจกับ JSON Schema ของข้อความประเภทนั้น พร้อมการปรับชื่อฟิลด์พ้องให้เป็นมาตรฐานและการตรวจรูปแบบ IBAN/BIC
- กฎเกณฑ์ของสกีม (ไม่บังคับ): กฎของระบบการชำระเงินที่คุณระบุ ตั้งแต่ SEPA (SCT, Instant, SDD Core, B2B) ไปจนถึงระบบระดับประเทศ เช่น UK Faster Payments, CHAPS และ Bacs, ACH และการโอนเงินของสหรัฐฯ และ Swift CBPR+ โดย
pain001 plugins listจะแสดงชื่อทั้งหมด - การตรวจสอบด้วย XSD: XML ที่สร้างขึ้นจะถูกตรวจกับสกีมา ISO 20022 อย่างเป็นทางการผ่าน
xmlschemaก่อนที่จะเขียนข้อมูลแม้แต่ไบต์เดียวลงดิสก์ เมื่อติดตั้งส่วนเสริมfast(lxml) ซึ่งเป็นตัวเลือก libxml2 จะยอมรับเอกสารที่ถูกต้องได้เร็วขึ้น เอกสารที่ libxml2 ปฏิเสธจะถูกตรวจซ้ำโดยxmlschemaและผลการตรวจนั้นถือเป็นที่สิ้นสุด
ระหว่างการสร้าง XML และการตรวจสอบตามกฎของสกีม จำนวนเงินจะถูกจัดการเป็น decimal.Decimal เสมอ (ไม่ใช่เลขทศนิยมแบบ IEEE 754) และยอดควบคุม NbOfTxs / CtrlSum จะถูกคำนวณขึ้นใหม่จากระเบียนที่ผ่านการตรวจสอบ แทนที่จะเชื่อค่าที่มากับข้อมูลนำเข้า
นอกเหนือจากการสร้าง pain.001 ไลบรารีหลักยังมีตัวอ่านและตัวสร้างรายงานสถานะ pain.002 (เพื่อให้คุณอ่านคำตอบรับหรือปฏิเสธจากธนาคารได้) และตัวอ่านและตัวสร้างรายการเดินบัญชี camt.053 สำหรับการกระทบยอดสิ้นวัน พร้อมทั้ง VersionMapper ที่ย้ายระเบียนข้ามเวอร์ชันของข้อความ
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#
endpoint ทั้งหมดอยู่ภายใต้ /api/v1 (พร้อมชื่อเรียกอื่นที่ไม่ระบุเวอร์ชันคือ /api):
| เมธอดและเส้นทาง | วัตถุประสงค์ |
|---|---|
GET /api/v1/health | การตรวจสอบว่าระบบยังทำงานอยู่ |
POST /api/v1/validate | ตรวจสอบระเบียน แล้วคืนค่าข้อผิดพลาดในระดับฟิลด์ |
POST /api/v1/generate | การสร้าง XML แบบซิงโครนัส |
POST /api/v1/generate/async | จัดคิวชุดข้อมูลขนาดใหญ่เพื่อสร้างไฟล์เบื้องหลัง |
GET /api/v1/status/{job_id} | ตรวจสอบสถานะงานแบบอะซิงโครนัส |
GET /api/v1/download/{job_id} | ดาวน์โหลดไฟล์ XML ที่เสร็จสมบูรณ์ |
DELETE /api/v1/jobs/{job_id} | ล้างงานที่เสร็จสิ้นแล้ว |
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 |
เอกสารเชิงโต้ตอบให้บริการที่ /api/docs (Swagger UI), /api/redoc และ /api/reference (Scalar) ส่วนเอกสาร OpenAPI อยู่ที่ /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. การปรับข้อมูลนำเข้าให้เป็นมาตรฐาน#
ก่อนการตรวจสอบ Pain001 จะปรับข้อมูลที่ส่งออกจากระบบงานจริงให้กลายเป็นระเบียนที่ถูกต้อง:
- ชื่อฟิลด์พ้อง: ชื่อคอลัมน์ที่พบบ่อยในระบบ ERP จะถูกจับคู่กับฟิลด์มาตรฐาน (ตัวอย่างเช่น
amount→payment_amount) - การปรับ IBAN / BIC ให้เป็นมาตรฐาน: ตัดช่องว่างออก ปรับตัวพิมพ์ให้สม่ำเสมอ แล้วจึงตรวจสอบ (mod-97 ตาม ISO 13616 สำหรับ IBAN และโครงสร้างตาม ISO 9362 สำหรับ BIC)
- วันที่: อ่านค่าวันที่ดำเนินการตามรูปแบบ ISO 8601
YYYY-MM-DD - จำนวนเงิน: ประมวลผลผ่าน
decimal.Decimalจำนวนเงินที่รูปแบบไม่ถูกต้องจะไม่ผ่านการตรวจสอบ แทนที่จะถูกปัดเศษอย่างเงียบ ๆ - ชุดอักขระ: ตัวช่วยถอดอักษรจะลดทอนเนื้อหาให้อยู่ในชุดอักขระละตินของ ISO 20022 ที่ SWIFT และ SEPA ยอมรับ
- 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. สถาปัตยกรรมปลั๊กอิน#
ชุดเครื่องมือนี้ขยายความสามารถได้ผ่านกลุ่ม entry point สี่กลุ่ม ได้แก่ pain001.loaders, pain001.validators, pain001.schemes และ pain001.writers โดย pain001-loader-xlsx ลงทะเบียนผ่านกลไกนี้และถูกค้นพบโดยอัตโนมัติเมื่อติดตั้ง ส่วน pain001-loader-mt101 เป็นไลบรารีอ่านข้อมูลแบบเอกเทศที่เรียกใช้ได้โดยตรง (และถูกเรียกใช้โดยเครื่องมือ convert_mt101 ของเซิร์ฟเวอร์ MCP ด้วย) นอกจากนี้ยังมีสวิตช์ปิดการทำงาน PAIN001_DISABLE_PLUGINS=1 ซึ่งปิดการค้นหาปลั๊กอินจากบุคคลที่สามทั้งหมดในสภาพแวดล้อมที่ควบคุมเข้มงวด
6. เกณฑ์คุณภาพ#
ไลบรารีหลักพัฒนาภายใต้เกณฑ์ที่เข้มงวดและตรวจสอบยืนยันได้ ได้แก่ ความครอบคลุมของโค้ดระดับบรรทัดและระดับสาขา 100% ที่บังคับใช้ใน CI (--cov-fail-under=100), การกำหนดชนิดข้อมูลแบบเข้มงวดด้วย mypy, ความครอบคลุมของ docstring 100% และการตรวจความปลอดภัยของโค้ด (Bandit, pip-audit) พร้อมทั้งสร้าง SBOM รูปแบบ CycloneDX สำหรับทุกบิลด์ที่เผยแพร่
อ่านต่อได้ที่ คู่มือการติดตั้ง, เซิร์ฟเวอร์ MCP สำหรับเอเจนต์ AI หรืออภิธานศัพท์การชำระเงิน
