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-940Verified import paths — ran on the pinned version, not inferred.
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.
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).
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.
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.
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.
Change the import statement to `import mt940`.
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')`
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)`
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]))`
No dependency data recorded yet.