Registry / data / ebcdic

ebcdic

JSON →
library2.0.1pypypi✓ verified 25d ago

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.

pip install ebcdic
INSTALL
IMPORT
SIG · EBCDIC
E
ebcdic
datapythonv2.0.1
Install
1.6s avg
Import
18ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v2.0.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.020s · 18.5MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.6s · import 0.016s · 19MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

ebcdic
import ebcdic
The 'ebcdic' package registers its codecs directly, allowing standard string methods like .encode() and .decode() with EBCDIC codec names.

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}")
Debug
Known issues
breakingVersion 2.0.0 and later of the `ebcdic` package require Python 3.9 or newer. Older Python versions (2.7, 3.4-3.8) require `ebcdic` version 1.1.1, and even older versions (2.6, 3.1-3.3) require `ebcdic` version 1.0.0.
fix
Ensure your Python environment is 3.9+ to use `ebcdic` 2.0.1. For older Python versions, explicitly install an earlier `ebcdic` version (e.g., `pip install ebcdic==1.1.1` for Python 3.4-3.8).
affects: 2.0.0+
gotchaSome EBCDIC codecs, such as 'cp037', 'cp273', 'cp500', and 'cp1140', may already be provided by Python's standard library and can 'overrule' or conflict with those provided by the `ebcdic` package. This might lead to unexpected behavior if specific mappings from the `ebcdic` package are expected.
fix
Use `ebcdic.ignored_codec_names()` to see which codecs are provided by the standard library and thus 'ignored' by this package. If specific mappings are critical, test thoroughly or consider manual encoding/decoding if conflicts arise.
affects: All versions
gotchaUsing an incorrect EBCDIC code page (e.g., 'cp037' when the data is 'cp1047') will result in garbled or incorrect text during decoding. EBCDIC variants are not universally compatible.
fix
Always verify the exact EBCDIC code page used by the source system for your data. This information is crucial for accurate encoding and decoding operations.
affects: All versions
gotchaWhen performing file I/O with EBCDIC data, it is critical to explicitly specify the correct EBCDIC encoding (e.g., `encoding='cp500'`) in Python's `open()` function. Failing to do so will cause Python to attempt decoding with a default encoding (often UTF-8 or the system default), leading to `UnicodeDecodeError` or corrupted data.
fix
Always pass the appropriate EBCDIC code page to the `encoding` parameter of `open()` when reading or writing EBCDIC files: `with open('file.ebcdic', 'r', encoding='cp1047') as f:`.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'ebcdic'
The `ebcdic` package has not been installed in the current Python environment.
fix
Install the package using pip: `pip install ebcdic`
LookupError: unknown encoding: cpXXXX
The specified EBCDIC codepage (e.g., 'cp1047', 'cp037') is not recognized by Python's built-in `codecs` module or the installed `ebcdic` library version. This can happen if the `ebcdic` package is not installed, or if an unsupported or misspelled codepage name is used.
fix
Ensure the `ebcdic` package is installed (`pip install ebcdic`). Verify the exact EBCDIC codepage name against the list of supported codecs provided by the `ebcdic` library or Python's `codecs` documentation. For example, `bytes_data.decode('cp037')` or `string_data.encode('cp1141')`.
UnicodeDecodeError: 'charmap' codec can't decode byte 0xXX in position Y: character maps to <undefined>
This error occurs when attempting to decode EBCDIC-encoded bytes using an incorrect character encoding (e.g., an ASCII-based codec like 'utf-8' or 'charmap', or the wrong EBCDIC codepage) for the actual EBCDIC data, meaning certain byte sequences do not have a valid character mapping in the specified codec.
fix
Explicitly specify the correct EBCDIC codepage (e.g., 'cp037', 'cp1047', 'cp500') that precisely matches the source data's encoding when decoding bytes. Consider using the `errors` parameter (e.g., `'ignore'`, `'replace'`) if some characters are expected to be un-decodable or if you want to handle them gracefully: `ebcdic_bytes.decode('cp037', errors='replace')`.
UnicodeEncodeError: 'cpXXXX' codec can't encode character '\uXXXX' in position Y: ordinal not in range(256)
This error arises when attempting to encode a Python string (which internally uses Unicode) into a specific EBCDIC codepage, but the string contains characters that do not have a corresponding representation in the target EBCDIC codepage.
fix
Review the input string for characters not present in the target EBCDIC codepage. Use the `errors` parameter during encoding to handle unencodable characters (e.g., `'ignore'`, `'replace'`, `'xmlcharrefreplace'`, or `'backslashreplace'`). For example: `python_string.encode('cp037', errors='replace')`.
Upgrade
Version history
2.0.1latest on PyPI · released Mar 3, 2026
Audit
Dependencies

No dependency data recorded yet.

Agent activity
15 hits · last 30 days
node
14
Resources
ebcdic — pip install ebcdic · libregistry