이 레퍼런스는 pain001 v0.0.90의 명령줄 인터페이스, Python API, REST 마이크로서비스, 검증 파이프라인을 설명합니다. 여기에 기재된 모든 플래그와 엔드포인트, 동작은 희망 사항이 아니라 실제로 출시된 코드에서 가져온 것입니다.
Pain001은 13개의 ISO 20022 메시지 정의를 지원합니다. pain.001.001.03부터 pain.001.001.13까지(고객 자금이체 개시, 11개 버전)와 pain.008.001.02 / pain.008.001.08(고객 자동이체 개시)입니다.
1. 명령줄 인터페이스#
pain001 실행 파일은 기능을 하위 명령으로 묶어 제공합니다. 생성 관련 플래그만 지정해 실행하면 generate가 암묵적으로 호출되므로 기존 자동화는 그대로 동작합니다.
| 하위 명령 | 용도 |
|---|---|
generate | 데이터 파일을 스키마 검증을 마친 ISO 20022 XML로 변환합니다(기본 명령). |
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] | FastAPI REST 마이크로서비스를 실행합니다(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건의 거래이며, 각 청크는 NbOfTxs와 CtrlSum을 다시 계산한 별도의 XML 파일이 됩니다). |
--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은 디스크에 단 1바이트라도 기록되기 전에
xmlschema를 통해 공식 ISO 20022 스키마에 대해 검증됩니다. 선택 사항인fast추가 구성(lxml)을 설치하면 libxml2가 유효한 문서를 더 빨리 승인합니다. libxml2가 거부한 문서는xmlschema이(가) 다시 검사하며, 그 판정이 최종입니다.
금액은 XML 생성과 스킴 검증 과정에서 IEEE 754 부동소수점이 아니라 decimal.Decimal로 처리되며, 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.90 refuses it.
Runnable, self-checking scripts for the public API and the CLI live in the library's examples/ directory.
3. REST 마이크로서비스#
모든 엔드포인트는 /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 정규화: 공백을 제거하고 대소문자를 통일한 뒤 검사합니다(IBAN은 ISO 13616 mod-97, BIC은 ISO 9362 구조).
- 날짜: 실행일을 ISO 8601
YYYY-MM-DD형식으로 구문 분석합니다. - 금액:
decimal.Decimal을 거쳐 처리되며, 형식이 잘못된 금액은 조용히 반올림되지 않고 검증에 실패합니다. - 문자 집합: 음역 도우미가 내용을 SWIFT와 SEPA가 허용하는 ISO 20022 라틴 문자 집합으로 줄여 줍니다.
- 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. 플러그인 아키텍처#
이 제품군은 네 개의 엔트리 포인트 그룹을 통해 확장할 수 있습니다: pain001.loaders, pain001.validators, pain001.schemes, pain001.writers. pain001-loader-xlsx는 이 메커니즘으로 등록되어 설치 시 자동으로 탐지됩니다. pain001-loader-mt101은 직접 사용하는 독립형 파싱 라이브러리이며, MCP 서버의 convert_mt101 도구도 이를 사용합니다. 차단 스위치인 PAIN001_DISABLE_PLUGINS=1은 통제된 환경에서 서드파티 플러그인 탐지를 완전히 비활성화합니다.
6. 품질 게이트#
코어 라이브러리는 엄격하고 검증 가능한 게이트를 기준으로 개발됩니다. CI에서 강제되는 100% 라인 및 분기 커버리지(--cov-fail-under=100), 엄격한 mypy 타이핑, 100% 독스트링 커버리지, 보안 린팅(Bandit, pip-audit)이 적용됩니다. 모든 릴리스 빌드마다 CycloneDX SBOM이 생성됩니다.
이어서 설치 가이드, AI 에이전트를 위한 MCP 서버, 또는 지급 용어집을 살펴보세요.
