PAIN.002 and PAIN.008 support¶
What the loader reads from a SEPA PAIN.002 status report and a PAIN.008
Direct Debit collection, how each becomes a Transaction, and how
amounts are signed. This page is the README's Features section,
included verbatim so the two cannot drift.
Public API¶
from bankstatementparser_loader_sepa import (
SepaMessageSummary,
SepaStatementParser,
load_sepa,
load_sepa_file,
summarize_sepa,
)
| Class / Function | Signature | Returns |
|---|---|---|
load_sepa |
load_sepa(xml_content): a str or bytes |
list[Transaction] |
load_sepa_file |
load_sepa_file(path): a str or os.PathLike |
list[Transaction] |
summarize_sepa |
summarize_sepa(xml_content): a str or bytes |
SepaMessageSummary |
SepaStatementParser |
SepaStatementParser(file_name) |
BankStatementParser with parse() (DataFrame), to_transactions() and get_summary() (dict) |
SepaMessageSummary is a frozen dataclass with the fields message_type (PAIN.002, PAIN.008, or the root element's name when neither is found), message_id (MsgId), creation_date (CreDtTm), account_id and currency (the first transaction's, EUR when there is none), item_count and total_amount (the sum of absolute amounts).
Message detection¶
Elements are matched by local name, so the namespace and the message version do not matter. The first CstmrPmtStsRpt or CstmrDrctDbtInitn element decides the type. Without either, the loader falls back to PAIN.002 or PAIN.008 only when a TxInfAndSts or PmtInf element carries text of its own (not only child elements); otherwise the message gives no transactions and message_type is the root element's name.
PAIN.008: one transaction per DrctDbtTxInf¶
Transaction field |
Source |
|---|---|
account_id |
The PmtInf block's CdtrAcct (IBAN, else Id), else the transaction's first IBAN or Id, else SEPA_DD |
currency |
The InstdAmt Ccy attribute, else EUR |
amount |
InstdAmt, positive |
booking_date, value_date |
The block's ReqdColltnDt |
description |
SEPA Direct Debit - <first Nm>, followed by the Ustrd (else Strd) remittance text in parentheses when there is one |
reference |
EndToEndId, else MndtId |
category |
pain008:direct_debit |
PAIN.002: one transaction per TxInfAndSts¶
Transaction field |
Source |
|---|---|
account_id |
The status's first IBAN, else Id, else none |
currency |
The amount's Ccy attribute, else EUR |
amount |
The first OrgnlTxAmt, InstdAmt or Amt, negative when TxSts is RJCT |
booking_date, value_date |
AccptncDtTm, when present |
description |
SEPA Status: <TxSts>, followed by the first Cd (else AddtlInf) in parentheses when there is one |
reference |
OrgnlEndToEndId, else OrgnlTxId, else StsId, else the message's MsgId |
category |
pain002:<TxSts> |
A status with no TxSts is read as RJCT.
Amounts¶
An amount is ISO 20022's plain decimal: ASCII digits with an optional fraction, converted to decimal.Decimal, never float. Anything else (an empty element, a sign, an exponent, NaN, Infinity, other scripts' digits) reads as 0.00, as does a transaction with no amount element.
Errors¶
load_sepa, load_sepa_file and summarize_sepa raise xml.etree.ElementTree.ParseError when the payload is not well-formed XML or declares an encoding the parser cannot use, and a defusedxml.DefusedXmlException (a ValueError) when it declares an entity, internal or external. Missing or unreadable elements never raise: they take the defaults above. load_sepa_file also raises OSError when the file cannot be read.