BAI2 support¶
What the loader reads, how each 16 record 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_bai2 import (
Bai2StatementParser,
load_bai2,
load_bai2_file,
summarize_bai2,
Bai2Summary,
)
| Class / Function | Signature | Returns |
|---|---|---|
Bai2StatementParser |
Bai2StatementParser(path) |
BankStatementParser parser instance |
load_bai2 |
load_bai2(text: str) |
list[Transaction] |
load_bai2_file |
load_bai2_file(path) |
list[Transaction] |
summarize_bai2 |
summarize_bai2(text: str) |
Bai2Summary |
Bai2Summary is a dataclass with the fields file_id, group_count,
account_count, transaction_count, and currency.
Each produced Transaction is populated as follows:
Transaction field |
Source |
|---|---|
account_id |
03 Account Identifier: accountNumber |
currency |
03 currencyCode, falling back to the 02 group currency |
amount |
16 amount (cents / 100), signed per the convention below |
booking_date |
02 Group Header as-of date, when present |
description |
16 text plus any 88 continuations |
transaction_id |
16 bankRefNum, falling back to customerRefNum |
reference / category |
The raw 16 type code (category as bai2:<code>) |
source |
Always "bai2" |
Supported BAI2 subset¶
BAI2 records are comma-delimited fields ending with a / delimiter,
each beginning with a numeric type code. This loader implements a
documented, pragmatic subset:
| Record | Meaning | Handling |
|---|---|---|
01 |
File Header | Required first record. fileId captured for the summary. |
02 |
Group Header | Group currency and as-of date captured. |
03 |
Account Identifier | accountNumber + optional currencyCode captured; account currency overrides group currency. |
16 |
Transaction Detail | One transaction. The free-text field runs to end-of-record (commas included) and is kept verbatim; V/S funds-type subfields are accounted for when locating the references and text. |
88 |
Continuation | Appended verbatim (commas included) to the preceding 16 record's text. A 88 continuing an 03 summary, or one with no preceding 16, is dropped rather than mis-attached. The rare 88: colon form is tolerated. |
49 / 98 / 99 |
Account / Group / File trailers | Ignored: control totals are not validated. |
Any other (or unknown) leading type code is ignored so that vendor extensions do not abort the parse. Ignoring control-total trailers is a deliberate, documented choice: the goal is faithful transaction extraction, not file-level reconciliation.
Amount and sign convention¶
BAI2 amounts are unsigned integers in the account currency's minor
units (cents), with no decimal point. They are converted to
decimal.Decimal (never float) by dividing by 100.
An empty amount field is treated as 0, and a leading + or - is
tolerated; any other content (a decimal point, an exponent, letters,
NaN) raises ValueError.
Debit / credit direction is derived from the documented numeric ranges
of the 16 record's type code (this is the loader's chosen, documented
convention):
| Type-code range | Meaning | Behaviour |
|---|---|---|
100–399 |
Credit | amount kept positive |
400–699 |
Debit | amount made negative |
700–799 |
Loan detail | treated as a debit-side disbursement: amount made negative |
900–999 |
Custom / summary / status | no Transaction emitted: these non-detail status/summary codes are skipped (and any continuation attached to one is dropped with it) |
| anything else | Unknown (incl. non-numeric) | amount kept positive |
The raw BAI2 type code is always preserved on every emitted
Transaction in both category (as bai2:<code>) and reference, so
no information is lost.
A small, optional lookup of well-known type codes (for example 142
"ACH credit", 301 "Commercial deposit", 475 "Check paid", 501
"Wire transfer debit") enriches the description of a 16 record that
carries no free-text of its own; a record that already has text keeps
its own text unchanged.
Errors¶
load_bai2, load_bai2_file and summarize_bai2 raise ValueError
when the payload does not start with an 01 File Header, and the two
loading functions raise ValueError for a malformed 16 amount.
Anything else they do not model is skipped rather than guessed at.