A serializer and deserializer of ISO8583 data.
Project description
iso8583
iso8583 module serializes and deserializes ISO8583 data between a bytes or bytearray instance containing ISO8583 data and a Python dict.
iso8583 supports custom specifications that can define field encoding (e.g. ASCII, EBCDIC, ISO8859-1, BCD, etc.), field types (e.g. fixed, LLVAR, LLLVAR, etc.), and maximum length
Install:
pip install pyiso8583
Decode iso8583 data received from a socket.
>>> import iso8583
>>> from iso8583.specs import default
>>> s = b'0200\x40\x10\x00\x00\x00\x00\x00\x00161234567890123456123456'
>>> doc_dec, doc_enc = iso8583.decode(s, spec=default)
Contents of the produced dictionaries.
>>> import pprint
>>> pprint.pp(doc_dec) # Decoded data
{'bm': {2, 12},
't': '0200',
'p': '4010000000000000',
'2': '1234567890123456',
'12': '123456'}
>>> pprint.pp(doc_enc) # Encoded data
{'bm': {2, 12},
't': {'len': b'', 'data': b'0200'},
'p': {'len': b'', 'data': b'@\x10\x00\x00\x00\x00\x00\x00'},
'2': {'len': b'16', 'data': b'1234567890123456'},
'12': {'len': b'', 'data': b'123456'}}
Pretty print result using iso8583.pp.
>>> iso8583.pp(doc_dec, spec=default) # Decoded data only
'bm' Enabled Fields : [2, 12]
't' Message Type : [0200]
'p' Bitmap, Primary : [4010000000000000]
'2' Primary Account Number (PAN) : 16 [1234567890123456]
'12' Time, Local Transaction : [123456]
Add or remove fields.
>>> iso8583.del_field(doc_dec, '12') # Decoded data only
'123456'
>>> doc_dec['t'] = '0210'
>>> iso8583.add_field(doc_dec, '39', '00') # Decoded data only
Encode iso8583 data to send to a socket.
>>> s, doc_enc = iso8583.encode(doc_dec, spec=default)
>>> print(s)
bytearray(b'0210@\x00\x00\x00\x02\x00\x00\x0016123456789012345600')
For more info read the docs.
Contribute
iso8583 is hosted on GitHub.
Feel free to fork and send contributions over.
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
Built Distribution
Hashes for pyiso8583-1.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1c2c6568a36d183bb3f845f2b4dbabdc93ce9787f2aecddfc7aa94bed8d7a79c |
|
MD5 | 778d4aa45aecf41b21f5c6be1757f2ff |
|
BLAKE2b-256 | 3228ad64c7210c1c1d1fa2d0d8c1e5254bc3f017b88d24138cded8de2b51fa3b |