A library to parse MT940 files and returns smart Python collections for statistics and manipulation.
Project description
mt940 - A library to parse MT940 files and returns smart Python collections for statistics and manipulation.
Links
- Documentation
- Bug reports
- Package homepage
- My blog
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 |
|
Source |
|
Documentation |
|
Changelog |
|
API |
|
Issues/roadmap |
|
Travis |
|
Test coverage |
|
Pypi |
|
Ohloh |
|
License |
BSD. |
git repo |
|
install dev |
|
tests |
|
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for mt_940-4.21.0-py2.py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 81fbfe647ebf2fc9700d6f61e2ba4c9d6c5fab56ccde2b54144481497c64b65c |
|
MD5 | 7b16355130084b3140865feea57d5920 |
|
BLAKE2b-256 | d213ca1f93984ccd26fe84ec282b2454bf3a758285aa2ea267b8dd6f1f30f78b |