Skip to main content

A serializer and deserializer of ISO8583 data.

Project description

PyPI Documentation Status Test coverage

iso8583 package serializes and deserializes ISO8583 data between raw bytes ISO8583 data and a regular Python dict.

iso8583 package supports custom specifications that can define:

  • Field length and data encoding, such as BCD, ASCII, EBCDIC, etc.

  • Field length count measured in bytes or nibbles.

  • Field type, such as fixed, LLVAR, LLLVAR, etc.

  • Maximum length

  • Optional field description

Multiple specifications can co-exist to support ISO8583 messages for POS, ATM, file actions, and so on. Simply define a new specification dictionary. iso8583 package includes a starter specification in iso8583.specs module that can be used as a base to create own custom/proprietary specifications.

Additional information is available on Read The Docs.

Installation

iso8583 is published on PyPI as pyiso8583 and can be installed from there:

pip install pyiso8583

Encoding & Decoding

Use iso8583.decode to decode raw ISO8583 message. It returns two dictionaries: one with decoded data and one with encoded data.

>>> import pprint
>>> import iso8583
>>> from iso8583.specs import default_ascii as spec
>>> encoded_raw = b'02004000000000000000101234567890'
>>> decoded, encoded = iso8583.decode(encoded_raw, spec)
>>> pprint.pp(decoded)
{'t': '0200', 'p': '4000000000000000', '2': '1234567890'}
>>> pprint.pp(encoded)
{'t': {'len': b'', 'data': b'0200'},
 'p': {'len': b'', 'data': b'4000000000000000'},
 '2': {'len': b'10', 'data': b'1234567890'}}

Modify the decoded message to send a response back. Change message type from ‘0200’ to ‘0210’. Remove field 2 (PAN). And add field 39 (Response Code).

>>> decoded['t'] = '0210'
>>> decoded.pop('2', None)
'1234567890'
>>> decoded['39'] = '05'

Use iso8583.encode to encode updated ISO8583 message. It returns a raw ISO8583 message and a dictionary with encoded data.

>>> encoded_raw, encoded = iso8583.encode(decoded, spec)
>>> encoded_raw
bytearray(b'0210000000000200000005')
>>> pprint.pp(decoded)
{'t': '0210', 'p': '0000000002000000', '39': '05'}
>>> pprint.pp(encoded)
{'t': {'len': b'', 'data': b'0210'},
 'p': {'len': b'', 'data': b'0000000002000000'},
 '39': {'len': b'', 'data': b'05'}}

Pretty Print Messages

Use iso8583.pp to pretty print ISO8583 message.

>>> import iso8583
>>> from iso8583.specs import default_ascii as spec
>>> encoded_raw = b'02004000000000000000101234567890'
>>> decoded, encoded = iso8583.decode(encoded_raw, spec)
>>> iso8583.pp(decoded, spec)
t   Message Type                  : '0200'
p   Bitmap, Primary               : '4000000000000000'
2   Primary Account Number (PAN)  : '1234567890'
>>> iso8583.pp(encoded, spec)
t   Message Type                  : b'0200'
p   Bitmap, Primary               : b'4000000000000000'
2   Primary Account Number (PAN)  : b'10' b'1234567890'

Contribute

iso8583 package 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

pyiso8583-3.0.0.tar.gz (33.4 kB view details)

Uploaded Source

Built Distribution

pyiso8583-3.0.0-py3-none-any.whl (19.6 kB view details)

Uploaded Python 3

File details

Details for the file pyiso8583-3.0.0.tar.gz.

File metadata

  • Download URL: pyiso8583-3.0.0.tar.gz
  • Upload date:
  • Size: 33.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.5

File hashes

Hashes for pyiso8583-3.0.0.tar.gz
Algorithm Hash digest
SHA256 81419fe09b5ba6c8ba02a7e90a5301da4124106ee9d46f99fa6fbfe1a8439eb3
MD5 8e30d4c20cbe2a83bb9c97e08f59856f
BLAKE2b-256 f3429ca216b510c6dbd7fb36186df8dd93370f96813141f40c55c5656db1e9c7

See more details on using hashes here.

File details

Details for the file pyiso8583-3.0.0-py3-none-any.whl.

File metadata

  • Download URL: pyiso8583-3.0.0-py3-none-any.whl
  • Upload date:
  • Size: 19.6 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.10.5

File hashes

Hashes for pyiso8583-3.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 be3a1f8a855ac4ec6278139aaa07e089e5841ff25747b6d6ba1edc547edc15fc
MD5 e97f799fe9a28e6884041a18d6e0d94e
BLAKE2b-256 eb73d5e4e96202a6fe654a16440ace47700e3170fa3b50f32ad2686c8828c230

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