Registry / data / mt-940

mt-940

JSON →
library4.30.0pypypi✓ verified 85d ago

mt-940 is a Python library designed to parse MT940 files, a standard format for bank account statements. It converts the complex MT940 data into easily manageable Python collections, enabling further statistics and manipulation. Currently at version 4.30.0, the library is actively maintained with frequent minor releases addressing various bank-specific parsing nuances and improvements.

pip install mt-940
INSTALL
IMPORT
SIG · MT-940
M
mt-940
datapythonv4.30.0
Install
1.5s avg
Import
138ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v4.30.0 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.143s · 17.9MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.5s · import 0.133s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

mt940
import mt940

This quickstart demonstrates how to parse a sample MT940 string using `mt940.parse`. The function can accept a file path, a file-like object, or raw data as a string. It returns a `Transactions` object which is an iterable collection of individual transaction objects, providing structured access to the parsed data.

import mt940 import pprint import io # Example MT940 data as a string mt940_data = """{1:F01BANKBEBBAXXX0000000000}{2:I940BANKBEBBAXXXN}{4:\n:20:TRN0001\n:25:BE00000000000000/EUR\n:28C:1/1\n:60F:C240315EUR1000,00\n:61:240316C100,00NTRFNONREF\n:86:Test transaction description for example.\n:62F:C240316EUR900,00\n-}""" # Parse from a string (using io.StringIO to simulate a file) transactions = mt940.parse(io.StringIO(mt940_data)) print("Parsed Transactions Data:") pprint.pprint(transactions.data) print("\nIndividual Transactions:") for transaction in transactions: print(f" Date: {transaction.data.get('date')}, Amount: {transaction.data.get('amount')}, Description: {transaction.data.get('entry_details')}") # Accessing a specific field, e.g., the closing balance closing_balance_info = transactions.data.get('closing_balance', {}) if closing_balance_info: print(f"\nClosing balance: {closing_balance_info.get('amount')} {closing_balance_info.get('currency')}") else: print("\nClosing balance not found.")
Debug
Known issues
gotchaMT940 format has many bank-specific variations. While `mt-940` aims for flexibility, highly customized or malformed files might not parse perfectly with default settings, potentially requiring custom pre- or post-processors.
fix
Consult the official documentation for information on using `processors` (e.g., `mt940.processors.add_currency_pre_processor`) or defining custom ones to handle specific bank formats or edge cases. The library includes examples for various banks (e.g., ABN AMRO, ASN, mBank).
affects: All versions
gotchaEncoding issues are common when parsing files. If the MT940 file is not UTF-8, you might encounter `UnicodeDecodeError` or garbled characters.
fix
Explicitly pass the correct `encoding` parameter to `mt940.parse()`. For instance, `mt940.parse(filepath, encoding='latin-1')`. If the encoding is unknown, consider using a library like `chardet` to detect it before parsing.
affects: All versions
gotchaRich transaction details, especially within Tag 86, can be highly structured and bank-dependent. Default parsing may not fully break down these sub-fields into distinct data points.
fix
Utilize the library's pre- and post-processor capabilities. The library provides specialized processors (e.g., for mBank transactions) or you can implement custom ones to extract detailed information from complex tags like Tag 86.
affects: All versions
deprecatedAlthough the library states support for Python 2.7, its string and unicode handling differs significantly from Python 3, making it a common source of encoding-related pitfalls and compatibility challenges.
fix
Strongly prefer using Python 3 (>= 3.3 as per documentation, ideally a recent version like 3.9+) for new projects to leverage Python's improved string handling and avoid legacy encoding issues.
affects: <= 4.x.x (Python 2.7 support)
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'mt-940'
The Python package is installed using `pip install mt-940` (with a hyphen), but the correct module name to import in Python code is `mt940` (without a hyphen).
fix
Change the import statement to `import mt940`.
UnicodeDecodeError: 'charmap' codec can't decode byte X in position Y: character maps to <undefined>
The MT940 file contains characters that cannot be decoded using the default or specified character encoding, often due to non-Latin characters or an incorrect file origin.
fix
Specify the correct encoding when opening the file or passing the data to `mt940.parse()`. Common encodings for MT940 files include 'latin-1', 'cp1252', or 'utf-8'. Example: `mt940.parse(file_content, encoding='latin-1')`
ValueError: Invalid MT940 format: ...
The MT940 file does not conform to the expected SWIFT MT940 standard or has specific bank-variant formatting issues that the parser cannot automatically resolve, leading to a general parsing failure.
fix
Examine the problematic MT940 file for non-standard structures, missing tags, or malformed data. The `mt-940` library offers custom processors to handle bank-specific variations; consider implementing or using existing custom processors if available for your bank's format. Example: `transactions = mt940.parse(file_data, processors=my_custom_processors)`
ValueError: day is out of range for month
This error typically occurs when the MT940 file contains an invalid date, such as '30th of February', which Python's `datetime` module cannot process.
fix
The `mt-940` library includes a `date_fixup_pre_processor` to handle such anomalies. Add this pre-processor to your parsing configuration. Example: `mt940.parse(file_data, processors=dict(pre_transaction=[mt940.processors.date_fixup_pre_processor]))`
Upgrade
Version history
4.30.0latest on PyPI · released Apr 13, 2023
Audit
Dependencies

No dependency data recorded yet.

Agent activity
10 hits · last 30 days
node
10
Resources
mt-940 — pip install mt-940 · libregistry