{"id":6726,"library":"mt-940","title":"MT940 Parser","description":"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.","status":"active","version":"4.30.0","language":"en","source_language":"en","source_url":"https://github.com/WoLpH/mt940","tags":["finance","banking","parser","mt940","swift"],"install":[{"cmd":"pip install mt-940","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"symbol":"mt940","correct":"import mt940"}],"quickstart":{"code":"import mt940\nimport pprint\nimport io\n\n# Example MT940 data as a string\nmt940_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-}\"\"\"\n\n# Parse from a string (using io.StringIO to simulate a file)\ntransactions = mt940.parse(io.StringIO(mt940_data))\n\nprint(\"Parsed Transactions Data:\")\npprint.pprint(transactions.data)\n\nprint(\"\\nIndividual Transactions:\")\nfor transaction in transactions:\n    print(f\"  Date: {transaction.data.get('date')}, Amount: {transaction.data.get('amount')}, Description: {transaction.data.get('entry_details')}\")\n\n# Accessing a specific field, e.g., the closing balance\nclosing_balance_info = transactions.data.get('closing_balance', {})\nif closing_balance_info:\n    print(f\"\\nClosing balance: {closing_balance_info.get('amount')} {closing_balance_info.get('currency')}\")\nelse:\n    print(\"\\nClosing balance not found.\")","lang":"python","description":"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."},"warnings":[{"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).","message":"MT940 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"Encoding issues are common when parsing files. If the MT940 file is not UTF-8, you might encounter `UnicodeDecodeError` or garbled characters.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"Rich 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.","severity":"gotcha","affected_versions":"All versions"},{"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.","message":"Although 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.","severity":"deprecated","affected_versions":"<= 4.x.x (Python 2.7 support)"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}