Skip to main content

A library to parse MT940 files and returns smart Python collections for statistics and manipulation.

Project description

MT940 test status MT940 Pypi version MT940 code coverage https://img.shields.io/pypi/pyversions/mt-940.svg

mt940 - A library to parse MT940 files and returns smart Python collections for statistics and manipulation.

Install

To install the latest release:

pip install mt-940

Or if pip is not available:

easy_install mt-940

To install the latest development release:

git clone --branch develop https://github.com/WoLpH/mt940.git mt940
cd ./mt940
virtualenv .env
source .env/bin/activate
pip install -e .

To run the tests you can use the py.test command or just run tox to test everything in all supported python versions.

Usage

Basic parsing:

import mt940
import pprint

transactions = mt940.parse('mt940_tests/jejik/abnamro.sta')

print('Transactions:')
print(transactions)
pprint.pprint(transactions.data)

print()
for transaction in transactions:
    print('Transaction: ', transaction)
    pprint.pprint(transaction.data)

Set opening / closing balance information on each transaction:

import mt940
import pprint

mt940.tags.BalanceBase.scope = mt940.models.Transaction

# The currency has to be set manually when setting the BalanceBase scope to Transaction.
transactions = mt940.models.Transactions(processors=dict(
    pre_statement=[
        mt940.processors.add_currency_pre_processor('EUR'),
    ],
))

with open('mt940_tests/jejik/abnamro.sta') as f:
    data = f.read()

transactions.parse(data)

for transaction in transactions:
    print('Transaction: ', transaction)
    pprint.pprint(transaction.data)

Simple json encoding:

import json
import mt940


transactions = mt940.parse('mt940_tests/jejik/abnamro.sta')

print(json.dumps(transactions, indent=4, cls=mt940.JSONEncoder))

Parsing statements from the Dutch bank ASN where tag 61 does not follow the Swift specifications:

def ASNB_mt940_data():
    with open('mt940_tests/ASNB/0708271685_09022020_164516.940.txt') as fh:
        return fh.read()

def test_ASNB_tags(ASNB_mt940_data):
    tag_parser = mt940.tags.StatementASNB()
    trs = mt940.models.Transactions(tags={
        tag_parser.id: tag_parser
    })

trs.parse(ASNB_mt940_data)
trs_data = pprint.pformat(trs.data, sort_dicts=False)
print(trs_data)

Contributing

Help is greatly appreciated, just please remember to clone the development branch and to run tox before creating pull requests.

Travis tests for flake8 support and test coverage so it’s always good to check those before creating a pull request.

Development branch: https://github.com/WoLpH/mt940/tree/develop

To run the tests:

pip install -r mt940_tests/requirements.txt
py.test

Or to run the tests on all available Python versions:

pip install tox
tox

Info

Python support

Python 2.7, >= 3.3

Blog

http://wol.ph/

Source

https://github.com/WoLpH/mt940

Documentation

http://mt940.rtfd.org

Changelog

http://mt940.readthedocs.org/en/latest/history.html

API

http://mt940.readthedocs.org/en/latest/modules.html

Issues/roadmap

https://github.com/WoLpH/mt940/issues

Travis

http://travis-ci.org/WoLpH/mt940

Test coverage

https://coveralls.io/r/WoLpH/mt940

Pypi

https://pypi-hypernode.com/pypi/mt-940

Ohloh

https://www.ohloh.net/p/mt-940

License

BSD.

git repo

$ git clone https://github.com/WoLpH/mt940.git

install dev

$ git clone https://github.com/WoLpH/mt940.git mt940
$ cd ./mt940
$ virtualenv .env
$ source .env/bin/activate
$ pip install -e .

tests

$ py.test

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

mt-940-4.25.0.tar.gz (20.6 kB view details)

Uploaded Source

Built Distribution

mt_940-4.25.0-py2.py3-none-any.whl (19.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file mt-940-4.25.0.tar.gz.

File metadata

  • Download URL: mt-940-4.25.0.tar.gz
  • Upload date:
  • Size: 20.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.0

File hashes

Hashes for mt-940-4.25.0.tar.gz
Algorithm Hash digest
SHA256 15c2b0d6cacb5efdade68b441323b9bb672bcb197c6cb2a82e286ca679f57347
MD5 6c210699019b1c59f5f440bf905e37c8
BLAKE2b-256 50b026eaa8779837658d6d2d8a5f74e84392a47f2b4f83b6c322826f12688d79

See more details on using hashes here.

File details

Details for the file mt_940-4.25.0-py2.py3-none-any.whl.

File metadata

  • Download URL: mt_940-4.25.0-py2.py3-none-any.whl
  • Upload date:
  • Size: 19.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.0 CPython/3.10.0

File hashes

Hashes for mt_940-4.25.0-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 72dff5b4b5693f723e800859dc0a955cb2ee0e2dfa21a930344bd6faeffb2dee
MD5 a3254a6b487badb48d2d3759fc15251e
BLAKE2b-256 de5fe49421f350e57fd67f679e49b43270faf0b08b6407b371cee309c9d77cc7

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page