Skip to main content

High-performance MT940 bank statement parser with JSON, CSV, and camt.053 export

Project description

x940

High-performance MT940 bank statement parser. Converts legacy SWIFT MT940 files to JSON, CSV, and ISO 20022 camt.053 XML — built in Rust with Python bindings via PyO3.

Installation

pip install x940

Requires Python 3.8+.

Quick Start

import x940 as x

stmt = x.MT940(open("statement.sta").read())

# statement info
stmt.account           # "EUR8934567890123456"
stmt.currency          # "EUR"
stmt.opening_balance   # 50000.0
stmt.closing_balance   # 51500.75
stmt.resolver_used     # "auto"

# transactions
len(stmt.transactions)  # 3
tx = stmt.transactions[0]
tx.value_date          # "2026-06-01"
tx.amount              # -1500.0 (signed: negative for debits)
tx.debit_credit        # "D"
tx.is_debit            # True
tx.customer_reference  # "INV-2026-991"
tx.counterparty        # "ALPHA DIGITAL CORP"
tx.purpose             # "MONTHLY RETAINER FEES"

# export
stmt.to_json()         # JSON string
stmt.to_csv()          # CSV string with UTF-8 BOM
stmt.to_camt053()      # camt.053.001.06 XML

Dialect Detection

Tag 86 (transaction details) comes in several regional formats. x940 auto-detects the dialect per-transaction using a chain of decoders:

Resolver Format Use case
auto Auto-detect (default) Mixed-source files
swift /KEYWORD/VALUE structured SWIFT-structured statements
gvc German ?DDKeyValue German bank statements
angular Polish/Nordic <DD / ^DD Polish, Nordic banks

Specify a resolver to prefer a specific dialect (unmatched transactions fall back to unstructured):

stmt = x.MT940(data, resolver="gvc")
stmt.resolver_used  # "gvc"

Transaction Properties

Property Type Description
value_date str Value date (YYYY-MM-DD)
entry_date str or None Entry date (YYYY-MM-DD)
debit_credit str "D" (debit), "C" (credit), etc.
amount float Signed amount (negative = debit)
is_credit bool True if this is a credit entry
is_debit bool True if this is a debit entry
is_reversal bool True if this is a reversal entry
transaction_type str SWIFT transaction type code
customer_reference str Customer reference from :86:
bank_reference str or None Bank reference
details str Raw Tag 86 detail text
structured_details dict or None Parsed key-value map
counterparty str Resolved counterparty name
counter_iban str Resolved counterparty IBAN
purpose str Resolved remittance/purpose text
signed_amount() float Same as amount property

Export Formats

Method Output Description
to_json() str JSON array of statements
to_csv() str CSV with UTF-8 BOM, signed amounts
to_camt053() str ISO 20022 camt.053.001.06 XML

License

GPL-3.0-or-later. See LICENSE.

Links

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

x940-0.1.1.tar.gz (49.8 kB view details)

Uploaded Source

Built Distributions

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

x940-0.1.1-cp310-cp310-manylinux_2_34_x86_64.whl (878.0 kB view details)

Uploaded CPython 3.10manylinux: glibc 2.34+ x86-64

x940-0.1.1-cp310-cp310-macosx_11_0_arm64.whl (785.5 kB view details)

Uploaded CPython 3.10macOS 11.0+ ARM64

File details

Details for the file x940-0.1.1.tar.gz.

File metadata

  • Download URL: x940-0.1.1.tar.gz
  • Upload date:
  • Size: 49.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: maturin/1.13.3

File hashes

Hashes for x940-0.1.1.tar.gz
Algorithm Hash digest
SHA256 a7e14249a2d2bd23e5eb3b3f04e18a3dafba8461cd65b06bd3dc6e35fbc82ff8
MD5 26062a134178140832094a3c0f3fc9f6
BLAKE2b-256 2d20975f96b0799d06fce87477eb289654a8f6d2a0be2ae3382776f284d78340

See more details on using hashes here.

File details

Details for the file x940-0.1.1-cp310-cp310-manylinux_2_34_x86_64.whl.

File metadata

File hashes

Hashes for x940-0.1.1-cp310-cp310-manylinux_2_34_x86_64.whl
Algorithm Hash digest
SHA256 82fb814516b57f19e9eabbb3a5dc4b5803621ed6d795c068e39b9ee8221dc1cb
MD5 733da684c10850a0a72b251c25ea030f
BLAKE2b-256 793a24f2a0f7af5d973ffdc4c5222f91e139c00cb50adce7e31f24b28b66ce18

See more details on using hashes here.

File details

Details for the file x940-0.1.1-cp310-cp310-macosx_11_0_arm64.whl.

File metadata

File hashes

Hashes for x940-0.1.1-cp310-cp310-macosx_11_0_arm64.whl
Algorithm Hash digest
SHA256 aebbdad0364ba72f7aa2ca78a12764d8e5648b39074f16e38091039a08f65318
MD5 5b76c8c5f101cb05df83eff5f9f8b548
BLAKE2b-256 10ca59cce9cdb8eef0630f7d1f34391e379ddac0ed41cc75f9a756e90a225d19

See more details on using hashes here.

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