Install & Compatibility
Where this runs
tested against v3.3 · 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
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 19.2MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 2.3s · import 0.000s · 20MB
17MB installed
● package 17MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
hexdump
✓ from hexdump import hexdump
✗ import hexdump; hexdump.hexdump(some_string)
The primary function `hexdump` is exposed directly, so it's best to import it explicitly. The `hexdump` module itself also contains the `hexdump` function, but explicit import is clearer.
dehex
✓ from hexdump import dehex
✗ import hexdump; hexdump.dehex(some_string)
Similar to `hexdump`, the `dehex` function for restoring binary data should be imported explicitly for clarity.
This quickstart demonstrates how to use `hexdump.hexdump()` to print a hexadecimal representation of binary data to standard output, and `hexdump.dehex()` to convert a hexadecimal string back into binary data. It also shows how to use `hexdump.dumpgen()` to get the hexdump as an iterable of strings for more control over output.
import hexdump
# Dump bytes to hex string, output to stdout
data_to_dump = b"Hello, hexdump library! This is some binary data to inspect."
print("\n--- Hex dump of data ---")
hexdump.hexdump(data_to_dump)
# Restore binary data from a hex string
hex_string_to_restore = "48 65 6C 6C 6F 2C 20 68 65 78 64 75 6D 70 20 6C 69 62 72 61 72 79 21 20 54 68 69 73 20 69 73 20 73 6F 6D 65 20 62 69 6E 61 72 79 20 64 61 74 61 20 74 6F 20 69 6E 73 70 65 63 74 2E"
restored_data = hexdump.dehex(hex_string_to_restore)
print("\n--- Restored data ---")
print(restored_data)
# You can also get the hexdump as a string instead of printing directly
hex_lines = []
for line in hexdump.dumpgen(data_to_dump):
hex_lines.append(line)
print("\n--- Hex dump as list of strings ---")
print("\n".join(hex_lines))
hexdump --version
Debug
Known issues
breakingPython 3 compatibility requires `bytes` objects for `hexdump()` input. Unlike Python 2 where `str` could be used for binary data, passing a Unicode `str` in Python 3 will result in a `TypeError`.fixEnsure that data passed to `hexdump()` is a `bytes` object. Encode strings (e.g., `my_string.encode('utf-8')`) before passing them to `hexdump()`. affects: All Python 3 versions (from `hexdump` 0.3 onwards)
gotchaWhen installed via an OS package manager, the command-line utility for `hexdump` might conflict with the system's `util-linux hexdump` command. The project suggests a different name like `hexdumper` for such installations.fixIf encountering conflicts, use `python -m hexdump` to invoke the command-line tool explicitly, or check your system's package documentation for alternative names (e.g., `hexdumper`).
affects: All versions when used as a command-line tool via OS packages
gotchaThe `dehex()` function is designed to be more tolerant of whitespace and linefeeds in input hex strings compared to stricter alternatives like `binascii.unhexlify()`. While often convenient, this behavior might be unexpected if very strict parsing of hex data is required.fixIf strict hex string validation is needed before conversion, consider pre-processing the input string to remove all whitespace yourself, or use `binascii.unhexlify()` if its stricter parsing is preferred for the use case.
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'hexdump'
The 'hexdump' Python library has not been installed or is not accessible within the current Python environment.
ImportError: No module named hexdump
The 'hexdump' Python library has not been installed or is not accessible within the current Python environment.
TypeError: Abstract unicode data (expected bytes)
In Python 3, the `hexdump` function expects a `bytes` object as input, but a `str` (unicode) object was provided.
fixEnsure the input data is encoded to bytes, for example: `hexdump.hexdump(data.encode('utf-8'))` or `hexdump.hexdump(b'\x00'*16)`. AttributeError: module 'hexdump' has no attribute 'hexdump'
After `import hexdump`, users might mistakenly try to call a top-level `hexdump()` function, but the actual dumping function is `hexdump.hexdump()` or `hexdump.dump()`.
fixAccess the correct function via the module: `import hexdump; hexdump.hexdump(some_bytes)` or `from hexdump import hexdump; hexdump(some_bytes)` (after `from hexdump import hexdump`).
hexdump: bad format
When using the `hexdump` command-line utility, the specified format string with the `-e` option is syntactically incorrect or incompatible with the input data.
fixReview the `hexdump` man page or documentation for the correct format string syntax. For example, to display bytes as two-character hexadecimal with a newline, use `hexdump -v -e '/1 "%02X\n"'`.
Upgrade
Version history
3.3latest on PyPI · released Jan 22, 2016
Audit
Dependencies
No dependency data recorded yet.