bankstatementparser-loader-mt942
SWIFT MT942 Interim Transaction Report loader that parses MT942 wire format into bankstatementparser Transaction objects.
Contents
Getting started
- Install: PyPI, source
- Requirements: toolchain floor, platforms
- Quick Start: parse a report in a few lines
The bankstatementparser-loader-mt942 ecosystem
- The bankstatementparser-loader-mt942 ecosystem: the core library, the other loaders and writers
Library reference
- Capabilities at a glance: the current surface by theme
- Ecosystem comparison: short matrix; full table at
docs/COMPARISON.md - Benchmarks: headline numbers; full table at
docs/BENCHMARKS.md - Features: tags, field mapping, summaries and errors
- Configuration: core options
- Examples: runnable example index
Operational
- When not to use bankstatementparser-loader-mt942: limitations
- Development: make targets, fuzzing, CI
- Security: guarantees and compliance
- Documentation: all reference docs
- Stability guarantees: SemVer axis, output stability, minimum toolchain discipline
- License
Install
As a Python library
pip install bankstatementparser-loader-mt942
That installs the loader and pulls in bankstatementparser (>= 0.0.35) automatically, which brings pandas and pydantic.
| Channel | Command | Notes |
|---|---|---|
| PyPI | pip install bankstatementparser-loader-mt942 |
Pulls in bankstatementparser >= 0.0.35 |
| Source | git clone https://github.com/sebastienrousseau/bankstatementparser-loader-mt942 && cd bankstatementparser-loader-mt942 && poetry install |
For development |
Verify the installation:
python -c "import bankstatementparser_loader_mt942 as m; print(m.__version__)"
# -> 0.0.36
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.mdsays when the floor moves. bankstatementparser0.0.35 or later, whoseTransactionmodel andBankStatementParserbase class the loader produces and extends.- No network access, native extensions or system packages of its own.
Quick Start
from bankstatementparser_loader_mt942 import load_mt942
mt942 = """:20:MT942REF001
:25:COBADEFFXXX/DE89370400440532013000
:28C:42/1
:34F:EURD0,00
:34F:EURC0,00
:13D:2506241200+0100
:61:2506240624C500,00NTRFINV-123//BANKREF1
:86:Incoming payment for invoice 123
:61:2506240624D200,50NTRFRENT//BANKREF2
:86:Monthly rent debit
:90D:1EUR200,50
:90C:1EUR500,00
-
"""
transactions = load_mt942(mt942)
for txn in transactions:
print(txn.value_date, txn.currency, txn.amount, txn.description)
# 2025-06-24 EUR 500.00 Incoming payment for invoice 123
# 2025-06-24 EUR -200.50 Monthly rent debit
Those are bankstatementparser.transaction_models.Transaction objects with source="mt942": debit lines carry a negative amount, credit lines a positive one, and amounts are exact Decimal values (SWIFT's comma decimal separator 500,00 becomes Decimal("500.00")).
To read from a file instead of a string:
from bankstatementparser_loader_mt942 import (
Mt942StatementParser,
load_mt942_file,
)
# Use as a BankStatementParser instance
parser = Mt942StatementParser("statement.mt942")
df = parser.parse()
# Or load directly to Transaction models
transactions = load_mt942_file("statement.mt942")
The bankstatementparser-loader-mt942 ecosystem
bankstatementparser-loader-mt942 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-mt942 |
This loader: MT942 text to Transaction objects and :90D: / :90C: roll-ups, with SWIFT envelopes and supplementary details handled |
Loading intraday SWIFT reports |
| Other loaders | BAI2, 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["MT942 file or str"] -->|load_mt942 / load_mt942_file| B["bankstatementparser-loader-mt942"]
B -->|list of Transaction, source=mt942| C["bankstatementparser pipeline"]
A -->|summarize_mt942| D["Mt942Summary"]
Capabilities at a glance
| Area | Capability | Status |
|---|---|---|
| Loading | load_mt942 (text) and load_mt942_file (path) to list[Transaction] |
Shipped |
| Summary | summarize_mt942 to an Mt942Summary with the :90D: / :90C: roll-ups and the :13D: stamp |
Shipped |
| Core integration | Mt942StatementParser, a BankStatementParser registered as the mt942 entry point in bankstatementparser.loaders |
Shipped |
| Wire format | SWIFT envelopes, multi-line :86:, supplementary details, amounts without decimals, CRLF or LF |
Shipped |
| Debit/credit marks | C, D, RC, RD, EC, ED, with an optional funds code |
Shipped |
| Several messages per payload | One result per concatenated MT942 message | Considered (roadmap) |
Ecosystem comparison
The core bankstatementparser also ships an MT942 parser (Mt942Parser); this loader handles more of what real files carry. Every cell comes from the two projects' source code.
| Project | SWIFT envelope | :90D: / :90C: summaries |
A malformed :61: line |
|---|---|---|---|
| bankstatementparser-loader-mt942 | Unwrapped | Parsed | Skipped |
bankstatementparser Mt942Parser |
Not handled | Not read | Raises |
See docs/COMPARISON.md for the evidence and complete matrix.
Benchmarks
benches/bench_load_mt942.py times load_mt942 and summarize_mt942 as a poll grows: transactions per report and reports per poll. Cost per transaction stays flat from 10 to 10,000 transactions, and a summary costs under a third of a full load.
| Scenario | Result | Environment |
|---|---|---|
load_mt942, 1 report x 1,000 transactions (87 KiB) |
14.67 ms | Apple M1 Pro, macOS 27.2.1, CPython 3.12.16 |
load_mt942, 50 reports x 200 transactions (861 KiB) |
148.67 ms | Apple M1 Pro, macOS 27.2.1, CPython 3.12.16 |
summarize_mt942, 50 reports x 200 transactions (861 KiB) |
39.64 ms | Apple M1 Pro, macOS 27.2.1, CPython 3.12.16 |
See docs/BENCHMARKS.md for methodology and full results.
Features
Supported tags
| Tag | Meaning | Cardinality |
|---|---|---|
:20: |
Transaction reference number | mandatory |
:25: |
Account identification (the account id) | mandatory |
:28C: |
Statement / sequence number | optional |
:34F: |
Floor limit indicator <CCY>[D|C]<amount> (provides the currency) |
one or two |
:13D: |
Date/time stamp YYMMDDHHMM±HHMM |
optional |
:61: |
Statement line (one per booked entry) | repeatable |
:86: |
Information to account owner (attaches to the preceding :61:) |
optional, per line |
:90D: |
Debit summary <count><CCY><amount> |
optional |
:90C: |
Credit summary <count><CCY><amount> |
optional |
Unrecognised tags (and the trailing - end-of-message marker) are
silently ignored, so future SWIFT additions do not break parsing.
A :61: line that does not match the statement-line grammar is
skipped rather than fatal, so one unrecognised row never aborts the
whole parse.
Real-world wire-format constructs
Genuine bank/SWIFT exports are messier than the tidy sample above. The
loader handles the following, pinned by a golden test over a real,
third-party fixture in tests/fixtures/real/ (its source, licensing
and provenance are in tests/fixtures/real/PROVENANCE.md):
- SWIFT message envelope. Messages wrapped in the header blocks
{1:...}{2:...}{3:...}and the text block{4:...-}are unwrapped before parsing; the envelope is never mistaken for content. - Amounts with no fractional digits. A SWIFT amount may end on the
decimal comma with nothing after it:
5000,→Decimal("5000"),0,→Decimal("0"). :34F:with an embedded D/C indicator.:34F:NZDC0,yields currencyNZDregardless of theC/Dletter.- Multi-line
:86:. Continuation lines that do not start with a:tag:head (e.g./BAI/…,/BENM/…,/ACNO/…) are appended to the:86:description, newlines preserved; CRLF and LF files give the same description. - Supplementary details after
:61:. A line immediately following a:61:(before any:86:), such as a bareTransferorwording/NBKT, is the SWIFT supplementary-details subfield. It is folded into the transaction'sdescription(supplementary text first, then the:86:content, joined by newlines) and never glued onto the statement-line tail, so the parsedtransaction_id/referencestay clean. A:61:with supplementary details but no following:86:keeps that text as its description.
Field mapping
Each :61: statement line becomes one Transaction:
Transaction field |
Source |
|---|---|
account_id |
:25: |
currency |
:34F: |
amount |
:61: amount as Decimal, negated for D, RC (reversal of credit) and ED (expected debit) lines; C, RD and EC stay positive |
value_date |
:61: value date (YYMMDD) |
booking_date |
:61: optional entry date (MMDD, inherits the value-date year) |
transaction_id |
the bank reference in the :61: tail (left of //) |
reference |
the customer reference in the :61: tail (right of //) |
description |
the following :86: free-form text |
source |
always "mt942" |
source_index |
the zero-based line index within the message |
The two-digit YY year uses the standard SWIFT sliding window: 00-79
map to 20YY, 80-99 to 19YY. An optional one-letter funds code
after the debit/credit mark is accepted and not stored.
Summaries
When you want the message metadata and the :90D:/:90C: roll-ups
rather than the individual transactions, call summarize_mt942:
from bankstatementparser_loader_mt942 import summarize_mt942
summary = summarize_mt942(mt942)
print(summary.reference) # MT942REF001
print(summary.currency) # EUR
print(summary.debit_count) # 1
print(summary.debit_sum) # Decimal("200.50")
print(summary.credit_sum) # Decimal("500.00")
print(summary.transaction_count) # 2
Mt942Summary is a frozen dataclass with reference, account_id,
currency, statement_datetime, debit_count, debit_sum,
credit_count, credit_sum, and transaction_count. Optional fields
(no :90x: / :13D: present) default to None.
Errors
A payload missing the mandatory :20: reference or :25: account
identification raises ValueError with a message naming the missing tag:
load_mt942(":25:ACC\n:61:250624C10,00NTRFX\n")
# ValueError: MT942 payload missing required :20: reference
A malformed :90D: / :90C: summary, an impossible date, or an amount
that is not a SWIFT 15d comma-decimal (digits with at most one comma,
at most 15 characters) also raises ValueError.
Configuration
The loader has no options, configuration file or environment variables: the tag set, the sign convention and the date window above are fixed, so the same report always loads the same way. Installing the package registers Mt942StatementParser under the mt942 name in the bankstatementparser.loaders entry-point group, which is how the core discovers it; nothing needs to be configured for that.
Examples
Two runnable examples live in examples/, each run in CI:
| Example | Demonstrates |
|---|---|
01_load_mt942.py |
Parse a small MT942 string into transactions |
02_summarize_mt942.py |
Read a file and print the Mt942Summary roll-ups |
python examples/01_load_mt942.py
When not to use bankstatementparser-loader-mt942
- You have a PDF or CSV statement. Use the core
bankstatementparserparsers directly; this loader is only for the SWIFT MT942 wire format. - You have MT940 (final statements with balances). MT940 is a different message; this loader handles the interim MT942 report. The
:61:/:86:grammar is shared, but MT942 has no:60F:/:62F:balances, and the loader never invents them. - You need bank-specific
:86:sub-field parsing (e.g. Deutsche Bank's?20/?30/?32GVC codes). The raw:86:value is preserved verbatim as the transactiondescription; downstream tooling can parse it if needed. - You need several messages from one payload kept apart. Concatenated MT942 messages load as one stream; splitting them is on the roadmap.
- Your MT942 is PGP / GPG encrypted. Decrypt upstream and pass the plaintext to the loader.
Development
git clone https://github.com/sebastienrousseau/bankstatementparser-loader-mt942.git
cd bankstatementparser-loader-mt942
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, score in tests/MUTATION.md) 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. CONTRIBUTING.md covers branches and commit signing.
Security
- Flat text, no XML. MT942 has no XML envelope, so the XXE / billion-laughs surface does not apply; the loader reads text and files you pass it and writes nothing, with no network and no code execution.
- Bounded parsing. Field regexes are anchored and bounded, so catastrophic backtracking is not a concern, and a malformed amount is refused with
ValueErrorrather than guessed at. - Fuzzing.
fuzz/fuzz_load_mt942.pydrivesload_mt942andsummarize_mt942with Atheris in CI, seeded with the repository's fixtures, and fails on any exception other thanValueError, on a malformedTransaction, and on a summary that disagrees with the load. - Supply chain. Dependencies are locked in
poetry.lock, CI installs hash-pinned exports of it, andpip-auditand 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
- User manual: sebastienrousseau.com/bankstatementparser-loader-mt942, built from
docs/with MkDocs - API reference: the manual's API page, generated from the docstrings
- Developer docs:
CONTRIBUTING.md,ARCHITECTURE.md,RELEASING.md - The suite:
docs/suite.md, with everybankstatementparserpackage - History:
ROADMAP.md,CHANGELOG.md - Specification: the SWIFT User Handbook MT942 Interim Transaction Report; the loader follows the common subset shipped by major EU and UK commercial banks
Stability guarantees
- Versioning. Releases stay on the
0.0.xline and step by exactly0.0.1, in lockstep with the rest of thebankstatementparsersuite. Under SemVer a0.0.xrelease may break anything; this project names each break in the CHANGELOG instead. - The breaking axis is the output: which
:61:lines produce aTransaction, the sign of each amount, how eachTransactionfield is filled, and theMt942Summaryfields. Changing any of them for a report 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_mt942,load_mt942_file,summarize_mt942,Mt942SummaryandMt942StatementParserkeep 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-mt942 0.0.36
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| bankstatementparser_loader_mt942-0.0.36.tar.gz | 30.1 kB | With provenance | Details for bankstatementparser_loader_mt942-0.0.36.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| bankstatementparser_loader_mt942-0.0.36-py3-none-any.whl | Python 3 | none | any | Details for bankstatementparser_loader_mt942-0.0.36-py3-none-any.whl |
Total release size: 55.0 kB
Release files / bankstatementparser_loader_mt942-0.0.36.tar.gz
| Download URL | bankstatementparser_loader_mt942-0.0.36.tar.gz |
|---|---|
| Size | 30.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a7e242f1200efd7171f2e77eee85e92f5ebea1a5f4cdd64ba7cf12ff4de74c52
|
|
BLAKE2b-256 checksum How to use checksums |
188876abf623da73bf8d90dfa1fd452b376210ea75e0338c015ad36a7d523a72
|
| 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 27, 2026.
Transparency logRelease files / bankstatementparser_loader_mt942-0.0.36-py3-none-any.whl
| Download URL | bankstatementparser_loader_mt942-0.0.36-py3-none-any.whl |
|---|---|
| Size | 24.9 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
00eb3381edac816f92b74a85a01a2e8fc3258cc6763b3111e1708471fa2712dd
|
|
BLAKE2b-256 checksum How to use checksums |
7a8e5822bf0149a8a558f16320a70ab610fcdec2dad85c612ead29d3aedf9644
|
| 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 27, 2026.
Transparency logSecurity for bankstatementparser-loader-mt942 0.0.36
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.
Attestation for bankstatementparser_loader_mt942-0.0.36.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 27, 2026.
Transparency logA 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.