MT940 Parser

4.30.0 · active · verified Wed Apr 15

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.

Warnings

Install

Imports

Quickstart

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.")

view raw JSON →