Developer Reference

API & SDK Reference

Complete programming interfaces, types, and error handling for Rust, Python, and CLI pipelines.

Bank Statement Parser exposes deterministic, zero-allocation interfaces across both native Rust and PyO3-powered Python bindings. Every function executes strictly in-process with zero network telemetry, complete memory safety, and mathematical balance verification.

01

Rust Core Library Interface (lib.rs)

Integrate the native Rust crate directly into your backend services for maximum CPU throughput, sub-millisecond document parsing, and zero heap duplication:

rust — crate interface
use bankstatementparser::{Parser, Statement, Transaction};
use std::path::Path;
 
# Configure thread-safe parser with dialect auto-detection
let parser = Parser::builder()
    .detect_dialects(true)
    .strict_balance_validation(true)
    .build();
 
# Parse byte stream directly from memory or disk
let statement: Statement = parser.parse_file(Path::new("statement.pdf"))?;
 
# Access verified balance invariants and transactions
println!("Account IBAN: {}", statement.account_id);
println!("Closing Balance: {} {}", statement.closing_balance, statement.currency);
for tx in statement.transactions {
    println!("{} | {:>10.2} | {}", tx.date, tx.amount, tx.description);
}

Core data types provided by the native crate:

Type / Symbol Signature Description
Parser struct Parser Thread-safe parser engine supporting zero-copy byte slice and file ingestion.
ParserBuilder struct ParserBuilder Configures parallel threads, balance invariants, and dialect heuristics.
Statement struct Statement Normalized document model containing account ID, balances, currency, and transactions.
Transaction struct Transaction Individual ledger item with booking date, value date, signed amount, and narrative.
StatementFormat enum StatementFormat Output target variants: Json, Csv, Ofx, Qif, and Camt053.
02

Python SDK Interface (PyO3)

Pre-compiled binary wheels for Linux, macOS, and Windows provide native Rust speed directly inside Python data science, pandas, and web application workflows:

python — sdk quickstart
from bankstatementparser import (
    BankStatementParser, CamtParser, Bai2Parser, Mt940Parser,
    ParquetStreamWriter, reconcile_payments_and_statements,
)
 
# 1. Parse statement into strongly-typed Transaction models
parser = BankStatementParser()
statement = parser.parse_file("statement.pdf")
 
# 2. Stream transactions directly to Apache Parquet
with ParquetStreamWriter("transactions.parquet") as writer:
    writer.write_batch(statement.transactions)
 
# 3. Inspect verified balance proof
print(f"Closing Balance: {statement.closing_balance} {statement.currency}")
for tx in statement.transactions:
    print(f"{tx.date} | {tx.amount:>10.2f} | {tx.description}")

Core parsers and analytical tools exported by the module:

Symbol Type / Signature Purpose & Description
BankStatementParser Class Primary document engine for PDF layout extraction, OCR fallback, and multi-format routing.
Bai2Parser Class Dedicated state machine parser for BAI2 corporate cash management files.
CamtParser Class High-speed XML parser for ISO 20022 CAMT.052, CAMT.053, and CAMT.054 statements.
Pain001Parser Class Parser for ISO 20022 PAIN.001 customer credit transfer payment instructions.
Mt940Parser / Mt942Parser Class SWIFT MT940 end-of-day and MT942 intraday tag-based message parsers.
ParquetStreamWriter ContextManager Streams batches of transactions directly to Apache Parquet with Snappy/Zstd compression.
reconcile_payments_and_statements Function Two-way automated reconciliation matching payment orders against statement postings.
inspect_pdf_forensics Function Audits PDF statements for font discrepancies, metadata modifications, and tampering findings.
analyze_statement_transactions Function Computes cash flow summaries, average daily balances, NSF fees, and recurring cadences.
03

Deterministic Error Handling & Diagnostics

All processing pipelines isolate corrupt documents, unsupported regional dialects, and balance arithmetic discrepancies into typed error exceptions without panics or unhandled crashes:

python — error handling
from bankstatementparser import parse_statement
from bankstatementparser.exceptions import (
    BalanceMismatchError,
    UnsupportedDialectError,
    CorruptedDocumentError,
)
 
try:
    statement = parse_statement("statement.pdf")
except BalanceMismatchError as exc:
    # Arithmetic discrepancy: opening + sum(credits) - sum(debits) != closing
    print(f"Audit failed: expected delta {exc.expected_delta}, found {exc.actual_delta}")
except UnsupportedDialectError as exc:
    # Document signature unrecognized
    print(f"Unsupported bank layout: {exc.detected_signature}")
except CorruptedDocumentError as exc:
    print(f"Malformed file stream: {exc.details}")
04

Zero-Telemetry Execution Guarantees

Bank Statement Parser makes zero outbound network calls, transmits no analytical telemetry, and requires no external SaaS API keys. Sensitive financial documents and banking statements remain strictly confined within your own compute environment.

Air-gapped high-throughput financial document engineering architecture
Air-gapped execution architecture: banking statements are tokenized and validated entirely within local memory with zero external telemetry.