Skip to main content

bankstatementparser-loader-bai2 logo

bankstatementparser-loader-bai2

BAI2 (Bank Administration Institute, version 2) cash-management loader that parses BAI2 files into bankstatementparser Transaction objects.

Build Registry Docs OpenSSF Scorecard License: Apache-2.0 OR MIT Python 3.10+

A terminal printing bankstatementparser-loader-bai2 0.0.37, the repository's multi-group BAI2 fixture, then the 01_load_transactions.py and 02_summarize_file.py examples loading signed transactions and a file summary


Contents

Getting started

The bankstatementparser-loader-bai2 ecosystem

Library reference

Operational


Install

As a Python library

pip install bankstatementparser-loader-bai2

That installs the loader and bankstatementparser >= 0.0.36, which brings pandas and pydantic.

Channel Command Notes
PyPI pip install bankstatementparser-loader-bai2 Pulls in bankstatementparser >= 0.0.36
Source git clone https://github.com/sebastienrousseau/bankstatementparser-loader-bai2 && cd bankstatementparser-loader-bai2 && poetry install For development

Verify the installation:

python -c "import bankstatementparser_loader_bai2 as b; print(b.__version__)"
# -> 0.0.37

An isolated virtual environment keeps the loader's dependencies apart:

python -m venv venv
source venv/bin/activate        # macOS/Linux
venv\Scripts\activate           # Windows
python -m pip install -U bankstatementparser-loader-bai2

Requirements

  • Python 3.10 or later. CI tests CPython 3.10, 3.11, 3.12, 3.13 and 3.14 on Linux, macOS and Windows; docs/POLICIES.md says when the floor moves.
  • bankstatementparser 0.0.36 or later, whose Transaction model and BankStatementParser base class the loader produces and extends.
  • No network access, native extensions or system packages of its own.

Quick Start

from bankstatementparser_loader_bai2 import load_bai2_file

transactions = load_bai2_file("statement.bai")
for txn in transactions:
    print(txn.account_id, txn.currency, txn.amount, txn.description)

Or parse an in-memory payload:

from bankstatementparser_loader_bai2 import load_bai2

payload = (
    "01,SENDER,RECEIVER,260601,1200,FILE001,,,/\n"
    "02,RCVR,ORIG,1,260601,1200,USD,/\n"
    "03,0123456789,USD,010,150000,1,,/\n"
    "16,165,150000,Z,BANKREF1,CUSTREF1,Incoming wire payment/\n"
    "88,from ACME Corp invoice 42/\n"
    "16,475,2500,Z,BANKREF2,,ATM withdrawal/\n"
    "49,152500,2/\n"
    "98,152500,1,4/\n"
    "99,152500,1,6/\n"
)

for txn in load_bai2(payload):
    print(txn.amount, txn.category, txn.description)
# 1500 bai2:165 Incoming wire payment from ACME Corp invoice 42
# -25 bai2:475 ATM withdrawal

Both return a flat list of bankstatementparser.transaction_models.Transaction objects with source="bai2", ready for the rest of a bankstatementparser pipeline.


The bankstatementparser-loader-bai2 ecosystem

bankstatementparser-loader-bai2 is one of the input loaders of the bankstatementparser suite, whose packages ship one version together. The full table is in The suite.

Component Purpose Use case
bankstatementparser The parser core: CAMT, pain.001, CSV, OFX, QFX, MT940, MT942, BAI2 and PDF statements, and the Transaction model Parsing statements from Python or the CLI
bankstatementparser-loader-bai2 This loader: BAI2 text to Transaction objects, with 88 continuations, funds-type subfields and a documented sign convention Loading BAI2 files from US banks
Other loaders MT942, CFONB 120, CAMT.054, SEPA pain.002 / pain.008 and BACS Standard 18 Formats beyond the core
Writers and transport XLSX, QIF, OFX and SWIFT writers; EBICS retrieval Exporting transactions and fetching statements
bankstatementparser-mcp, bankstatementparser-lsp Agent tools and editor diagnostics over the core AI agents and MT940 editing
flowchart LR
    A["BAI2 file or str"] -->|load_bai2 / load_bai2_file| B["bankstatementparser-loader-bai2"]
    B -->|list of Transaction, source=bai2| C["bankstatementparser pipeline"]
    A -->|summarize_bai2| D["Bai2Summary"]

Capabilities at a glance

Area Capability Status
Loading load_bai2 (text) and load_bai2_file (path) to list[Transaction] Shipped
Summary summarize_bai2 to a Bai2Summary without building transactions Shipped
Core integration Bai2StatementParser, a BankStatementParser registered as the bai2 entry point in bankstatementparser.loaders Shipped
Records 01, 02, 03, 16, 88; 49/98/99 trailers ignored Shipped
Robustness CRLF, blank lines, trailing spaces, optional trailing /, V/S funds-type subfields Shipped
Control totals Validating the 49/98/99 sums Not in this loader

Ecosystem comparison

The core bankstatementparser also ships a BAI2 parser (Bai2Parser); this loader handles more of the 16 record layout. Every cell comes from the projects' own source code.

Project 88 continuations Commas in 16 text Funds-type subfields
bankstatementparser-loader-bai2 Appended to the 16 text Kept V and S
bankstatementparser Bai2Parser Ignored Split on Not handled
bai2 (Ministry of Justice) Merged into the record Kept Parsed

See docs/COMPARISON.md for the evidence and complete matrix.


Benchmarks

benches/bench_load_bai2.py times load_bai2 and summarize_bai2 as a file grows along both axes a real bank-day file grows: transactions per account and accounts per file. Cost per transaction stays flat from 10 to 10,000 transactions, and a summary costs about a third of a full load.

Scenario Result Environment
load_bai2, 1 account x 1,000 transactions (66 KiB) 4.35 ms Apple M1 Pro, macOS 27.2.1, CPython 3.12.16
load_bai2, 50 accounts x 200 transactions (648 KiB) 46.82 ms Apple M1 Pro, macOS 27.2.1, CPython 3.12.16
summarize_bai2, 50 accounts x 200 transactions (648 KiB) 12.24 ms Apple M1 Pro, macOS 27.2.1, CPython 3.12.16

See docs/BENCHMARKS.md for methodology and full results.


Features

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.


Configuration

The loader has no options, configuration file or environment variables: the record subset and the sign convention above are fixed, so the same file always loads the same way. Installing the package registers Bai2StatementParser under the bai2 name in the bankstatementparser.loaders entry-point group, which is how the core discovers it; nothing needs to be configured for that.


Examples

examples/ holds three runnable scripts, each run in CI against an inline sample, so no data files are needed:

Example Demonstrates
01_load_transactions.py load_bai2 on a multi-record payload: the sign convention and an 88 continuation
02_summarize_file.py summarize_bai2, then load_bai2_file reading the payload back from disk
03_full_tour.py Every public symbol against one payload covering 01/02/03/16/88/49/98/99
python examples/01_load_transactions.py

When not to use bankstatementparser-loader-bai2

  • You have ISO 20022 camt.053 or SWIFT MT940, not BAI2. Those are different formats with their own parsers in the core and the suite.
  • You need control-total reconciliation. This loader extracts transactions and deliberately ignores the 49/98/99 trailers; if you must validate file sums, do so before or after loading.
  • You need the full BAI2 specification. This is a documented subset focused on transaction extraction, not an exhaustive BAI2 parser, and it does not write BAI2.
  • You need balances. The 03 summary amounts and status codes are not turned into balance records.

Development

git clone https://github.com/sebastienrousseau/bankstatementparser-loader-bai2.git
cd bankstatementparser-loader-bai2
poetry install
make check

make check runs the local gates: ruff and black, mypy --strict, the complexity baseline (scripts/check_complexity.py), pytest with a 100% line + branch coverage floor, interrogate at 100% docstring coverage, and the examples. Other targets: make fuzz (Atheris, 60 s, Linux x86_64 with Python 3.12+), make docs (the MkDocs manual, --strict), make mutation (mutmut) and make demo (re-renders the GIF above with VHS from .github/demo.tape). CI adds the OS by Python matrix, the fuzz run, CodeQL, pip-audit on the locked requirements and the Docs Lint gates. Documentation and example regression tests (tests/test_docs_accuracy.py, tests/test_regression_docs.py, tests/test_regression_examples.py) execute every documented snippet and every examples/*.py script.

Current state (v0.0.37): 100% line + branch coverage against a 100% enforced floor, mypy --strict clean, interrogate 100%, and a mutation-tested loader (455/481 mutants killed; the 26 survivors are documented equivalent mutants, see tests/MUTATION.md). CONTRIBUTING.md covers branches and commit signing.


Security

  • Read-only. The loader only reads text and files you pass it; it writes nothing.
  • No XML, no network, no code execution. Parsing is a pure string-to-dataclass transformation.
  • Decimal arithmetic is used throughout, avoiding float rounding surprises in financial amounts, and a malformed amount is refused rather than guessed at.
  • Fuzzing. fuzz/fuzz_load_bai2.py drives load_bai2 and summarize_bai2 with Atheris in CI, seeded with the repository's fixtures, and fails on any exception other than ValueError and on any malformed Transaction.
  • Supply chain. Dependencies are locked in poetry.lock, CI installs hash-pinned exports of it, and pip-audit and CodeQL run on every change. Releases publish to PyPI through OIDC trusted publishing and carry cosign signatures, SLSA provenance and SBOMs; every workflow action is pinned by commit SHA except the SLSA generator, which must be referenced by tag.

Report vulnerabilities according to SECURITY.md.


Documentation


Stability guarantees

  • Versioning. Releases stay on the 0.0.x line and step by exactly 0.0.1, in lockstep with the rest of the bankstatementparser suite. Under SemVer a 0.0.x release may break anything; this project names each break in the CHANGELOG instead.
  • The breaking axis is the output: which records produce a Transaction, the sign of each amount, and how each Transaction field is filled. Changing any of them for a file that loaded before is a breaking change and is called out in the CHANGELOG, even when no Python signature moves.
  • Output stability. The loader is deterministic: the same payload gives the same transactions in the same order.
  • Python API. load_bai2, load_bai2_file, summarize_bai2, Bai2Summary and Bai2StatementParser keep their names and fields; names starting with _ are internal.
  • Minimum toolchain. Python 3.10 is the floor; it moves only in a release, for the whole suite at once, with the reason in the CHANGELOG (docs/POLICIES.md).

License

Dual-licensed under Apache License, Version 2.0 or MIT, at your option (SPDX-License-Identifier: Apache-2.0 OR MIT). Built on the core bankstatementparser library. Any contribution submitted for inclusion in the work shall be dual-licensed as above, without additional terms or conditions.

Metadata

Release files for bankstatementparser-loader-bai2 0.0.37

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for bankstatementparser-loader-bai2 0.0.37
File Size Uploaded Provenance Actions
bankstatementparser_loader_bai2-0.0.37.tar.gz 30.0 kB With provenance Details for bankstatementparser_loader_bai2-0.0.37.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for bankstatementparser-loader-bai2 0.0.37
File Interpreter ABI Platform Actions
bankstatementparser_loader_bai2-0.0.37-py3-none-any.whl Python 3 none any Details for bankstatementparser_loader_bai2-0.0.37-py3-none-any.whl

Total release size: 54.8 kB

Release files / bankstatementparser_loader_bai2-0.0.37.tar.gz

Download URL bankstatementparser_loader_bai2-0.0.37.tar.gz
Size 30.0 kB
Tags Source
SHA-256 checksum
How to use checksums
e4983c104a1977029cb9ffc20c039e35af8b6895ee061d37dd179a05c3179087
BLAKE2b-256 checksum
How to use checksums
80c38eb1c4b81f5789756421d10e9f96c7d796de04a1695f35ee0879728b939b
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Release files / bankstatementparser_loader_bai2-0.0.37-py3-none-any.whl

Download URL bankstatementparser_loader_bai2-0.0.37-py3-none-any.whl
Size 24.8 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a8139053604efd05825f2a168d7d56264f5f6a3714b528a91c4c9019d4411963
BLAKE2b-256 checksum
How to use checksums
1a8f53008d19d4e07df3f4987ce5ff0bdf04533bbcc4b98873e78865ac17d8d6
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

Security for bankstatementparser-loader-bai2 0.0.37

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for bankstatementparser_loader_bai2-0.0.37.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 29, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page