ebcdic: Additional EBCDIC Codecs

2.0.1 · active · verified Fri Apr 10

The `ebcdic` package provides additional EBCDIC codecs for Python, primarily facilitating data exchange with legacy mainframe systems. EBCDIC (Extended Binary Coded Decimal Interchange Code) is a family of character encodings distinct from ASCII and Unicode. It is intended for use in scenarios where interoperability with EBCDIC-native systems is required. The current version is 2.0.1, with releases tied to Python version compatibility.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to encode a standard Python string to EBCDIC bytes using a specific EBCDIC code page (e.g., 'cp1141') and then decode EBCDIC bytes back to a Unicode string. The `ebcdic` package extends Python's built-in `str.encode()` and `bytes.decode()` methods with additional EBCDIC code page support.

import ebcdic

# Encode a Unicode string to EBCDIC (e.g., cp1141 for Germany/Austria)
unicode_string = 'hello world'
ebcdic_bytes = unicode_string.encode('cp1141')
print(f"Encoded EBCDIC bytes: {ebcdic_bytes}")

# Decode EBCDIC bytes back to a Unicode string
decoded_string = ebcdic_bytes.decode('cp1141')
print(f"Decoded Unicode string: {decoded_string}")

# Example with a different codec (cp1047 for Open Systems)
# Note: Python's standard library may already include some common EBCDIC codecs.
sample_bytes_cp1047 = b'\x88\x85\x93\x93\x96@\xa6\x96\x99\x93\x84'
decoded_cp1047 = sample_bytes_cp1047.decode('cp1047')
print(f"Decoded with cp1047: {decoded_cp1047}")

view raw JSON →