{"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":"python","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,"search_vec":"'-940':4 '4.30.0':40 'account':19 'activ':44 'address':50 'bank':18,53,60 'bank-specif':52 'collect':31 'complex':24 'convert':22 'current':37 'data':26 'design':9 'easili':28 'enabl':32 'file':13 'financ':59 'format':16 'frequent':47 'improv':58 'librari':8,42 'maintain':45 'manag':29 'manipul':36 'minor':48 'mt':3 'mt940':1,12,25,62 'nuanc':56 'pars':11,55 'parser':2,61 'python':7,30 'releas':49 'specif':54 'standard':15 'statement':20 'statist':34 'swift':63 'various':51 'version':39","created_at":"2026-04-15T18:40:19.644451+00:00","updated_at":"2026-04-16T16:42:18.652995+00:00","problems":[{"fix":"Change the import statement to `import mt940`.","cause":"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).","error":"ModuleNotFoundError: No module named 'mt-940'"},{"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')`","cause":"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.","error":"UnicodeDecodeError: 'charmap' codec can't decode byte X in position Y: character maps to <undefined>"},{"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)`","cause":"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.","error":"ValueError: Invalid MT940 format: ..."},{"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]))`","cause":"This error typically occurs when the MT940 file contains an invalid date, such as '30th of February', which Python's `datetime` module cannot process.","error":"ValueError: day is out of range for month"}],"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"4.30.0","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/WoLpH/mt940","docs":null,"changelog":null,"pypi":"https://pypi.org/project/mt-940/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["data","serialization"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-06-28","last_verified":"2026-06-28","next_check":"2026-07-28","install_tag":null}}