Skip to main content

bankstatementparser-loader-mt942 logo

bankstatementparser-loader-mt942

A SWIFT MT942 interim transaction report loader plugin that parses MT942 files into bankstatementparser Transaction objects.

PyPI version Python versions PyPI downloads Tests License


Contents

Overview

bankstatementparser-loader-mt942 is a small, focused companion to the bankstatementparser library. It does one thing well: parse the SWIFT MT942 Interim Transaction Report grammar and hand back the same Transaction objects the core PDF/CSV parsers produce. Every transaction is stamped with source="mt942" so you can tell where it came from.

MT942 is an interim statement. Unlike MT940 it carries no :60F: opening or :62F: closing balance — it reports a floor limit, an optional date/time stamp, the statement lines accumulated so far, and debit/credit summaries. This loader models that structure faithfully and never invents balances that are not present in the source.

Install

bankstatementparser-loader-mt942 runs on macOS, Linux, and Windows and requires Python 3.10+ and pip. It pulls in bankstatementparser (>= 0.0.18) automatically.

pip install bankstatementparser-loader-mt942

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 — debit lines carry a negative amount, credit lines a positive one, and amounts are exact Decimal values (SWIFT's comma decimal separator 500,00 is converted to 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")

Supported Fields

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 — this follows Postel's law: be liberal in what you accept. A malformed :61: statement line is skipped rather than fatal, so one bad 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/, whose source, licensing, and provenance are documented 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 currency NZD regardless of the C/D letter.
  • 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.
  • Supplementary details after :61:. A line immediately following a :61: (before any :86:), such as a bare Transfer or wording/NBKT, is the SWIFT supplementary-details subfield. It is folded into the transaction's description (supplementary text first, then the :86: content, joined by newlines) and never glued onto the statement-line tail — so the parsed transaction_id / reference stay 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, negated for debit (D) lines, as Decimal
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.

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

Examples

Two runnable examples live in examples/:

Both are exercised in CI on every commit.

When not to use this loader

  • You have a PDF or CSV statement. Use the core bankstatementparser parsers 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.
  • You need bank-specific :86: sub-field parsing (e.g. Deutsche Bank's ?20 / ?30 / ?32 GVC codes). The raw :86: value is preserved verbatim as the transaction description; downstream tooling can parse it if needed.
  • 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
cd bankstatementparser-loader-mt942
python -m venv .venv && source .venv/bin/activate
pip install -e .
pip install pytest pytest-cov ruff mypy interrogate
pytest --cov=bankstatementparser_loader_mt942 --cov-branch --cov-fail-under=100
ruff check bankstatementparser_loader_mt942 tests examples
mypy bankstatementparser_loader_mt942
interrogate -c pyproject.toml bankstatementparser_loader_mt942

Security

bankstatementparser-loader-mt942 parses a flat text format with no XML envelope, so the XXE / billion-laughs surface does not apply. Field regexes are anchored and bounded, so catastrophic backtracking is not a concern. Reporting practice and supported versions are documented in SECURITY.md. Vulnerabilities go via GitHub Private Vulnerability Reporting, not public issues.

Documentation

Ecosystem

bankstatementparser is part of a modular financial ecosystem. Optional companion packages provide specialized loaders, writers, AI agents, language servers, and transport protocol adapters:

Package GitHub Repository PyPI Role Description
bankstatementparser sebastienrousseau/bankstatementparser PyPI Core Engine Unified parser for CAMT (052/053), PAIN.001, CSV, OFX, QFX, MT940, and PDF statements
bankstatementparser-mcp sebastienrousseau/bankstatementparser-mcp PyPI AI Protocol Model Context Protocol (MCP) server exposing statement tools to LLMs & AI agents
bankstatementparser-lsp sebastienrousseau/bankstatementparser-lsp PyPI Developer Tooling Language Server Protocol (LSP) with live SWIFT MT940 statement validation & diagnostics
bankstatementparser-transport-ebics sebastienrousseau/bankstatementparser-transport-ebics PyPI Transport Automated bank statement retrieval over EBICS 3.0 (H005) and 2.5 (H004) protocols
bankstatementparser-writer-xlsx sebastienrousseau/bankstatementparser-writer-xlsx PyPI Output Writer Formats and exports parsed banking transactions into styled Microsoft Excel (.xlsx) workbooks
bankstatementparser-writer-qif sebastienrousseau/bankstatementparser-writer-qif PyPI Output Writer Serializes transactions into standard Quicken Interchange Format (.qif) exchange files
bankstatementparser-writer-ofx sebastienrousseau/bankstatementparser-writer-ofx PyPI Output Writer Serializes transactions into standard Open Financial Exchange (.ofx) XML/SGML files
bankstatementparser-writer-swift sebastienrousseau/bankstatementparser-writer-swift PyPI Output Writer Exports transactions to SWIFT MT940 customer statements and MT942 interim reports
bankstatementparser-loader-bai2 sebastienrousseau/bankstatementparser-loader-bai2 PyPI Input Loader Parses BAI2 cash-management and account balance statements
bankstatementparser-loader-mt942 sebastienrousseau/bankstatementparser-loader-mt942 PyPI Input Loader Parses SWIFT MT942 interim transaction reports with credit/debit summary reconciliation
bankstatementparser-loader-cfonb sebastienrousseau/bankstatementparser-loader-cfonb PyPI Input Loader Parses French CFONB 120 / AFB120 120-byte fixed-width banking statement files
bankstatementparser-loader-camt054 sebastienrousseau/bankstatementparser-loader-camt054 PyPI Input Loader Ingests ISO 20022 CAMT.054 real-time debit/credit notification stream XML
bankstatementparser-loader-sepa sebastienrousseau/bankstatementparser-loader-sepa PyPI Input Loader Ingests ISO 20022 SEPA PAIN.002 payment status reports and PAIN.008 direct debit mandates
bankstatementparser-loader-bacs sebastienrousseau/bankstatementparser-loader-bacs PyPI Input Loader Parses UK BACS Standard 18 / Faster Payments 106-byte fixed-width transmission files

License

Licensed under the Apache License, Version 2.0. Any contribution submitted for inclusion shall be licensed as above, without additional terms.

Contributing

Contributions are welcome. Open an issue or PR on the repository.

Acknowledgements

Built on the bankstatementparser library. The MT942 grammar follows the SWIFT User Handbook MT942 Interim Transaction Report specification and the common-denominator subset shipped by major EU and UK commercial banks.

Metadata

Release files for bankstatementparser-loader-mt942 0.0.19

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-mt942 0.0.19
File Size Uploaded
bankstatementparser_loader_mt942-0.0.19.tar.gz 25.1 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for bankstatementparser-loader-mt942 0.0.19
File Interpreter ABI Platform
bankstatementparser_loader_mt942-0.0.19-py3-none-any.whl Python 3 none any Details

Total release size: 47.3 kB

Release files / bankstatementparser_loader_mt942-0.0.19.tar.gz

Download URL bankstatementparser_loader_mt942-0.0.19.tar.gz
Size 25.1 kB
Tags Source
SHA-256 checksum
How to use checksums
1313309fa2afb0047bc907c39951cbf8612312e022c0a23542e1e226bc9d8fca
BLAKE2b-256 checksum
How to use checksums
b6b5daa4a9cfab62792ce656bc6f5797295a01b9c26427c80dcf764b1208ca20
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 1, 2026.

Transparency log

Release files / bankstatementparser_loader_mt942-0.0.19-py3-none-any.whl

Download URL bankstatementparser_loader_mt942-0.0.19-py3-none-any.whl
Size 22.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
60c112f208f7576b39928ef2e5fcb27a53d0908f68ceb396b83144c63f22de90
BLAKE2b-256 checksum
How to use checksums
3ed321a30dc1f27ef8a6080ca1a0cd2d6e6b7f169040fc8e2fdde096d03d8189
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.14

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 Sep 1, 2026.

Transparency log

Release history Release notifications | RSS feed

This release

0.0.19 This release

2 release files

0.0.18

2 release files

0.0.16

2 release files

0.0.15

2 release files

0.0.14

2 release files

0.0.13

2 release files

0.0.12

2 release files

0.0.11

2 release files

0.0.10

2 release files

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