mt940 package¶
Submodules¶
mt940.json module¶
-
class
mt940.json.
JSONEncoder
(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, encoding='utf-8', default=None)[source]¶ Bases:
json.encoder.JSONEncoder
-
default
(value)[source]¶ Implement this method in a subclass such that it returns a serializable object for
o
, or calls the base implementation (to raise aTypeError
).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
-
mt940.models module¶
-
class
mt940.models.
Amount
(amount, status, currency=None, **kwargs)[source]¶ Bases:
mt940.models.Model
Amount object containing currency and amount
Parameters: >>> Amount('123.45', 'C', 'EUR') <123.45 EUR> >>> Amount('123.45', 'D', 'EUR') <-123.45 EUR>
-
class
mt940.models.
Balance
(status=None, amount=None, date=None, **kwargs)[source]¶ Bases:
mt940.models.Model
Parse balance statement
Parameters: >>> balance = Balance('C', '0.00', Date(2010, 7, 22)) >>> balance.status 'C' >>> balance.amount.amount Decimal('0.00') >>> isinstance(balance.date, Date) True >>> balance.date.year, balance.date.month, balance.date.day (2010, 7, 22)
>>> Balance() <None @ None>
-
class
mt940.models.
Date
[source]¶ Bases:
datetime.date
,mt940.models.Model
Just a regular date object which supports dates given as strings
>>> Date(year='2000', month='1', day='2') Date(2000, 1, 2)
>>> Date(year='123', month='1', day='2') Date(2123, 1, 2)
Parameters:
-
class
mt940.models.
DateTime
[source]¶ Bases:
datetime.datetime
,mt940.models.Model
Just a regular datetime object which supports dates given as strings
>>> DateTime(year='2000', month='1', day='2', hour='3', minute='4', ... second='5', microsecond='6') DateTime(2000, 1, 2, 3, 4, 5, 6)
>>> DateTime(year='123', month='1', day='2', hour='3', minute='4', ... second='5', microsecond='6') DateTime(2123, 1, 2, 3, 4, 5, 6)
>>> DateTime(2000, 1, 2, 3, 4, 5, 6) DateTime(2000, 1, 2, 3, 4, 5, 6)
>>> DateTime(year='123', month='1', day='2', hour='3', minute='4', ... second='5', microsecond='6', tzinfo=FixedOffset('60')) DateTime(2123, 1, 2, 3, 4, 5, 6, tzinfo=<mt940.models.FixedOffset ...>)
Parameters: - year (str) – Year (0-100), will automatically add 2000 when needed
- month (str) – Month
- day (str) – Day
- hour (str) – Hour
- minute (str) – Minute
- second (str) – Second
- microsecond (str) – Microsecond
- tzinfo (tzinfo) – Timezone information. Overwrites offset
- offset (str) – Timezone offset in minutes, generates a tzinfo object with the given offset if no tzinfo is available.
-
class
mt940.models.
FixedOffset
(offset=0, name=None)[source]¶ Bases:
datetime.tzinfo
Fixed time offset based on the Python docs Source: https://docs.python.org/2/library/datetime.html#tzinfo-objects
>>> offset = FixedOffset(60) >>> offset.utcoffset(None).total_seconds() 3600.0 >>> offset.dst(None) datetime.timedelta(0) >>> offset.tzname(None) '60'
-
class
mt940.models.
SumAmount
(*args, **kwargs)[source]¶ Bases:
mt940.models.Amount
-
class
mt940.models.
Transaction
(transactions, data=None)[source]¶ Bases:
mt940.models.Model
-
class
mt940.models.
Transactions
(processors=None, tags=None)[source]¶ Bases:
_abcoll.Sequence
Collection of
Transaction
objects with global properties such as begin and end balance-
DEFAULT_PROCESSORS
= {'post_account_identification': [], 'post_available_balance': [], 'post_closing_balance': [], 'post_date_time_indication': [], 'post_final_closing_balance': [], 'post_final_opening_balance': [], 'post_floor_limit_indicator': [], 'post_forward_available_balance': [], 'post_intermediate_closing_balance': [], 'post_intermediate_opening_balance': [], 'post_non_swift': [], 'post_opening_balance': [], 'post_related_reference': [], 'post_statement': [<function date_cleanup_post_processor>], 'post_statement_number': [], 'post_sum_credit_entries': [], 'post_sum_debit_entries': [], 'post_transaction_details': [<function transaction_details_post_processor>], 'post_transaction_reference_number': [], 'pre_account_identification': [], 'pre_available_balance': [], 'pre_closing_balance': [], 'pre_date_time_indication': [], 'pre_final_closing_balance': [], 'pre_final_opening_balance': [], 'pre_floor_limit_indicator': [], 'pre_forward_available_balance': [], 'pre_intermediate_closing_balance': [], 'pre_intermediate_opening_balance': [], 'pre_non_swift': [], 'pre_opening_balance': [], 'pre_related_reference': [], 'pre_statement': [<function date_fixup_pre_processor>], 'pre_statement_number': [], 'pre_sum_credit_entries': [], 'pre_sum_debit_entries': [], 'pre_transaction_details': [], 'pre_transaction_reference_number': []}¶ Using the processors you can pre-process data before creating objects and modify them after creating the objects
-
currency
¶
-
parse
(data)[source]¶ Parses mt940 data, expects a string with data
Parameters: data (str) – The MT940 data Returns:
list
ofTransaction
-
mt940.parser module¶
Format¶
Sources:
[] = optional
! = fixed length
a = Text
x = Alphanumeric, seems more like text actually. Can include special
characters (slashes) and whitespace as well as letters and numbers
d = Numeric separated by decimal (usually comma)
c = Code list value
n = Numeric
-
mt940.parser.
parse
(src, encoding=None, processors=None, tags=None)[source]¶ Parses mt940 data and returns transactions object
Parameters: src – file handler to read, filename to read or raw data as string Returns: Collection of transactions Return type: Transactions
mt940.processors module¶
-
mt940.processors.
date_fixup_pre_processor
(transactions, tag, tag_dict, *args)[source]¶ Replace illegal February 29, 30 dates with the last day of February.
German banks use a variant of the 30/360 interest rate calculation, where each month has always 30 days even February. Python’s datetime module won’t accept such dates.
-
mt940.processors.
mBank_set_iph_id
(transactions, tag, tag_dict, *args)[source]¶ mBank Collect uses ID IPH to distinguish between virtual accounts, adding iph_id may be helpful in further processing
-
mt940.processors.
mBank_set_tnr
(transactions, tag, tag_dict, *args)[source]¶ mBank Collect states TNR in transaction details as unique id for transactions, that may be used to identify the same transactions in different statement files eg. partial mt942 and full mt940 Information about tnr uniqueness has been obtained from mBank support, it lacks in mt940 mBank specification.
-
mt940.processors.
mBank_set_transaction_code
(transactions, tag, tag_dict, *args)[source]¶ mBank Collect uses transaction code 911 to distinguish icoming mass payments transactions, adding transaction_code may be helpful in further processing
-
mt940.processors.
transaction_details_post_processor
(transactions, tag, tag_dict, result, space=False)[source]¶ Parse the extra details in some transaction formats such as the 60-65 keys.
Parameters: - transactions (mt940.models.Transactions) – list of transactions
- tag (mt940.tags.Tag) – tag
- tag_dict (dict) – dict with the raw tag details
- result (dict) – the resulting tag dict
- space (bool) – include spaces between lines in the mt940 details
-
mt940.processors.
transaction_details_post_processor_with_space
(transactions, tag, tag_dict, result)¶ Parse the extra details in some transaction formats such as the 60-65 keys.
Parameters: - transactions (mt940.models.Transactions) – list of transactions
- tag (mt940.tags.Tag) – tag
- tag_dict (dict) – dict with the raw tag details
- result (dict) – the resulting tag dict
- space (bool) – include spaces between lines in the mt940 details
mt940.tags module¶
Format¶
Sources:
[] = optional
! = fixed length
a = Text
x = Alphanumeric, seems more like text actually. Can include special
characters (slashes) and whitespace as well as letters and numbers
d = Numeric separated by decimal (usually comma)
c = Code list value
n = Numeric
Bases:
mt940.tags.Tag
Account identification
Pattern: 35x
Bases:
mt940.tags.BalanceBase
Bases:
mt940.tags.Tag
Balance base
Pattern: 1!a6!n3!a15d
Bases:
mt940.tags.BalanceBase
Bases:
mt940.tags.Tag
Date/Time indication at which the report was created
Pattern: 6!n4!n1! x4!n
Bases:
mt940.tags.ClosingBalance
Bases:
mt940.tags.BalanceBase
Bases:
mt940.tags.Tag
Floor limit indicator indicates the minimum value reported for debit and credit amounts
Pattern: :34F:GHSC0,00
Bases:
mt940.tags.BalanceBase
Bases:
mt940.tags.ClosingBalance
Bases:
mt940.tags.BalanceBase
Bases:
mt940.tags.Tag
Non-swift extension for MT940 containing extra information. The actual definition is not consistent between banks so the current implementation is a tad limited. Feel free to extend the implementation and create a pull request with a better version :)
It seems this could be anything so we’ll have to be flexible about it.
Pattern: 2!n35x | *x
Bases:
mt940.tags.BalanceBase
Bases:
mt940.tags.Tag
Related reference
Pattern: 16x
Bases:
mt940.tags.Tag
Pattern: 6!n[4!n]2a[1!a]15d1!a3!c23x[//16x]
alias of
mt940.models.Transaction
Bases:
mt940.tags.Statement
From: https://www.sepaforcorporates.com/swift-for-corporates
Pattern: 6!n[4!n]2a[1!a]15d1!a3!c16x[//16x] [34x]
But ASN bank puts the IBAN in the customer reference, which is acording to Wikipedia at most 34 characters.
So this is the new pattern:
Pattern: 6!n[4!n]2a[1!a]15d1!a3!c34x[//16x] [34x]
Bases:
mt940.tags.Tag
Statement number / sequence number
Pattern: 5n[/5n]
Bases:
mt940.tags.SumEntries
Bases:
mt940.tags.SumEntries
Bases:
mt940.tags.Tag
Number and Sum of debit Entries
Bases:
object
alias of
mt940.models.Transactions
Bases:
enum.Enum
Bases:
mt940.tags.Tag
Transaction details
Pattern: 6x65x
alias of
mt940.models.Transaction
Bases:
mt940.tags.Tag
Transaction reference number
Pattern: 16x
mt940.utils module¶
Module contents¶
-
class
mt940.
JSONEncoder
(skipkeys=False, ensure_ascii=True, check_circular=True, allow_nan=True, sort_keys=False, indent=None, separators=None, encoding='utf-8', default=None)[source]¶ Bases:
json.encoder.JSONEncoder
-
default
(value)[source]¶ Implement this method in a subclass such that it returns a serializable object for
o
, or calls the base implementation (to raise aTypeError
).For example, to support arbitrary iterators, you could implement default like this:
def default(self, o): try: iterable = iter(o) except TypeError: pass else: return list(iterable) # Let the base class default method raise the TypeError return JSONEncoder.default(self, o)
-
-
mt940.
parse
(src, encoding=None, processors=None, tags=None)[source]¶ Parses mt940 data and returns transactions object
Parameters: src – file handler to read, filename to read or raw data as string Returns: Collection of transactions Return type: Transactions