Skip to main content

Convert legacy SWIFT MT942 interim transaction reports to camt.052 ParsedDocument.

Project description

camt053-loader-mt942: MT942 → camt.052 loader

camt053-loader-mt942 logo

PyPI Version Python Versions License Tests Quality

Convert legacy SWIFT MT942 interim transaction reports into the same camt053 data model as native camt.052 input. A single parse_mt942(text) call returns a camt053.models.ParsedDocument tagged as a camt.052 Bank-to-Customer Account Report, ready for every downstream consumer in the suite (writer, validator, MCP and LSP servers).

Latest release: v0.0.14. SWIFT MT942 (the intraday sibling of MT940) is scheduled for retirement in November 2028. This loader bridges the window where banks still produce MT942 but downstream tooling expects camt.052.

Contents

Overview

camt053-loader-mt942 is a small, focused companion to the camt053 ISO 20022 cash-management library. It does one thing well: parse the common-denominator MT942 Interim Transaction Report grammar shipped by EU and UK commercial banks, and hand back the same ParsedDocument shape that the camt.052 XML parser produces — only the message_type differs (camt.052.001.08). The rest of the suite then works unchanged.

MT942 is the intraday sibling of MT940. Where MT940 → camt.053 (end-of-day Statement), MT942 → camt.052 (Account Report). The camt053 typed model is message-type-agnostic — its Statement dataclass doubles as a camt.052 <Rpt> container — so MT942 lands in the exact same ParsedDocument structure.

Install

camt053-loader-mt942 runs on macOS, Linux, and Windows and requires Python 3.10+ and pip. It pulls in camt053 automatically and has no other runtime dependencies.

pip install camt053-loader-mt942

Quick Start

from camt053_loader_mt942 import parse_mt942

mt942 = """:20:INTRA-REF-1
:25:COBADEFFXXX/DE89370400440532013000
:28C:42/1
:34F:EURD1000,00
:34F:EURC500,00
:13D:2606211430+0200
:61:2606210621CR500,00NMSCREF1//CREF1
:86:Customer payment for invoice 123
:61:2606210621D200,00NMSCREF2//CREF2
:86:Card settlement
:90D:1EUR200,00
:90C:1EUR500,00
"""

document = parse_mt942(mt942)

print(document.message_type)
# camt.052.001.08
print(document.msg_id)
# INTRA-REF-1
print(document.statements[0].account.iban)
# DE89370400440532013000
print(document.creation_date_time)
# 2026-06-21T14:30:00+02:00

That's a camt053.models.ParsedDocument, ready to feed to camt053-writer-xlsx (Excel output), the camt053 REST API, or any other consumer in the suite.

Supported Fields

Tag Meaning Mapped to
:20: Transaction reference number (mandatory) ParsedDocument.msg_id
:25: Account identification (mandatory; BIC/account or account) Statement.account (IBAN or proprietary other_id + optional servicer_bic)
:28C: Statement / sequence number (mandatory) Statement.id + Statement.electronic_seq_nb
:34F: Floor limit indicator (debit / credit) Balance with type_code="FLIMD" / "FLIMC"
:13D: Date/time indication (report timestamp) ParsedDocument.creation_date_time + Statement.creation_date_time (ISO-8601)
:61: Statement line (movement) Entry with amount, credit_debit_indicator, value_date, booking_date, reference, account_servicer_ref
:86: Information to account owner TransactionDetails.additional_info attached to the preceding entry
:90D: Number and sum of debit entries Balance with type_code="SUMD:<count>", amount=<sum>
:90C: Number and sum of credit entries Balance with type_code="SUMC:<count>", amount=<sum>

Reversal detection

A :61: line whose debit/credit indicator is RD (reversal of debit) or RC (reversal of credit) becomes an Entry with reversal_indicator=True.

Unknown fields

Unrecognised tags are silently ignored, so future SWIFT additions do not break parsing. This follows Postel's law: be liberal in what you accept.

Interim reports vs statements

MT942 differs from MT940 in exactly the ways an interim report differs from an end-of-day statement:

  • No booked opening/closing balances. MT942 has no :60F: / :62F:. It reports movements above a floor limit (:34F:) rather than reconciling opening → closing.
  • Floor limits (:34F:). The threshold above which movements are reported. MT942 carries a debit floor limit and, optionally, a separate credit floor limit.
  • Entry-count summaries (:90D: / :90C:). The number and sum of debit / credit movements — camt.052's <TxsSummry>.

Model limitations

The camt053 typed model is camt.053-statement-oriented: it models <Bal> balances but has no dedicated field for camt.052's <Lmt> floor-limit block or its <TxsSummry> transaction-summary block, and no integer entry-count field. Rather than invent fields or silently drop data, this loader surfaces both on the Statement.balances list using clearly proprietary type_code values:

  • :34F:Balance(type_code="FLIMD" | "FLIMC") — floor limit, debit / credit variant.
  • :90D:Balance(type_code="SUMD:<count>", amount=<sum>)
  • :90C:Balance(type_code="SUMC:<count>", amount=<sum>)

The :90x: sum is carried in Balance.amount; the ISO NbOfNtries count is encoded into type_code after the colon because the typed model has no integer count field. Downstream consumers that only expect real balances (OPBD / CLBD / …) can filter these proprietary codes out by prefix. If the upstream camt053 model later grows first-class floor-limit / transaction- summary fields, this loader will migrate to them.

Examples

Two runnable examples live in examples/:

Both are exercised in CI on every commit.

The camt053 suite

camt053-loader-mt942 is part of a set of independently installable packages built around the camt053 library:

Package Role
camt053 Core library + CLI + FastAPI REST API
camt053-mcp Model Context Protocol server (for AI agents)
camt053-lsp Language Server Protocol server (for editors)
camt053-writer-xlsx Excel .xlsx writer for parsed statements
camt053-loader-mt940 SWIFT MT940 → camt.053 loader
camt053-loader-mt942 SWIFT MT942 → camt.052 loader (this package)
flowchart LR
    A["MT942 text"] -->|parse_mt942| B["camt053-loader-mt942"]
    B -->|ParsedDocument (camt.052)| C["camt053"]
    C -->|writer / validator / MCP / LSP| D["Downstream consumers"]

When not to use camt053-loader-mt942

  • You already have native camt.052 input. Use the camt053 core parser directly — this loader is the bridge for legacy MT942-only data sources.
  • You need MT940 (end-of-day statement). Use camt053-loader-mt940 instead.
  • You need bank-specific :86: sub-field parsing. The raw :86: value is preserved verbatim in TransactionDetails.additional_info.
  • Your MT942 is PGP / GPG encrypted. Decrypt upstream and pass the plaintext to the loader.

Development

git clone https://github.com/sebastienrousseau/camt053-loader-mt942
cd camt053-loader-mt942
python -m venv .venv && source .venv/bin/activate
pip install -e ".[dev]"
pytest                            # 100% line + branch coverage gate
interrogate camt053_loader_mt942  # 100% docstring gate
mypy camt053_loader_mt942         # strict

Security

camt053-loader-mt942 parses a flat text format with no XML envelope — the XXE / billion-laughs surface lives upstream in the camt053 core (defusedxml + xml_guard). Field regexes are anchored and bounded, so catastrophic backtracking is not a concern.

License

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

Acknowledgements

Built on the camt053 ISO 20022 Bank Statement library. The MT942 grammar follows the SWIFT User Handbook MT942 specification and the common-denominator subset shipped by major EU and UK commercial banks.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

camt053_loader_mt942-0.0.14.tar.gz (24.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

camt053_loader_mt942-0.0.14-py3-none-any.whl (15.9 kB view details)

Uploaded Python 3

File details

Details for the file camt053_loader_mt942-0.0.14.tar.gz.

File metadata

  • Download URL: camt053_loader_mt942-0.0.14.tar.gz
  • Upload date:
  • Size: 24.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for camt053_loader_mt942-0.0.14.tar.gz
Algorithm Hash digest
SHA256 778642c5f0f13176e3e2a2f6f253f67d5827fd6422cb27dc81c2a803c0ff5166
MD5 775d27beca24f009e0a59e804b438795
BLAKE2b-256 79aa780d1c38e74db10607a54d997ba3bd77ce04c5de47270af881c0f8a7ba36

See more details on using hashes here.

Provenance

The following attestation bundles were made for camt053_loader_mt942-0.0.14.tar.gz:

Publisher: release.yml on sebastienrousseau/camt053-loader-mt942

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file camt053_loader_mt942-0.0.14-py3-none-any.whl.

File metadata

File hashes

Hashes for camt053_loader_mt942-0.0.14-py3-none-any.whl
Algorithm Hash digest
SHA256 3b587e391e33615e5ac32b5fbdf8757598f34924387de5887b18745c91932490
MD5 6fbb21bacdd6cffd22f7f8c6bb9fb16f
BLAKE2b-256 65a92a1c3706a9e90950966cbc912ffe5a7401b9c6c5bfeff2e506d18dbbbd21

See more details on using hashes here.

Provenance

The following attestation bundles were made for camt053_loader_mt942-0.0.14-py3-none-any.whl:

Publisher: release.yml on sebastienrousseau/camt053-loader-mt942

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page