{"id":6667,"library":"hexdump","title":"Hexdump Utility","description":"The `hexdump` Python library (version 3.3) provides functionality to dump binary data into a human-readable hexadecimal format and to restore binary data from such hex dumps. It works across Linux, Windows, and OS X, serving as both a Python library and a command-line tool. The last official release was in January 2016, indicating a maintenance phase rather than active development, though it remains functional for its stated purpose.","status":"maintenance","version":"3.3","language":"en","source_language":"en","source_url":"https://github.com/sarnold/hexdump","tags":["binary","hex","dump","utilities","forensics"],"install":[{"cmd":"pip install hexdump","lang":"bash","label":"Install latest version"}],"dependencies":[],"imports":[{"note":"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.","wrong":"import hexdump; hexdump.hexdump(some_string)","symbol":"hexdump","correct":"from hexdump import hexdump"},{"note":"Similar to `hexdump`, the `dehex` function for restoring binary data should be imported explicitly for clarity.","wrong":"import hexdump; hexdump.dehex(some_string)","symbol":"dehex","correct":"from hexdump import dehex"}],"quickstart":{"code":"import hexdump\n\n# Dump bytes to hex string, output to stdout\ndata_to_dump = b\"Hello, hexdump library! This is some binary data to inspect.\"\nprint(\"\\n--- Hex dump of data ---\")\nhexdump.hexdump(data_to_dump)\n\n# Restore binary data from a hex string\nhex_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\"\nrestored_data = hexdump.dehex(hex_string_to_restore)\nprint(\"\\n--- Restored data ---\")\nprint(restored_data)\n\n# You can also get the hexdump as a string instead of printing directly\nhex_lines = []\nfor line in hexdump.dumpgen(data_to_dump):\n    hex_lines.append(line)\nprint(\"\\n--- Hex dump as list of strings ---\")\nprint(\"\\n\".join(hex_lines))\n","lang":"python","description":"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."},"warnings":[{"fix":"Ensure that data passed to `hexdump()` is a `bytes` object. Encode strings (e.g., `my_string.encode('utf-8')`) before passing them to `hexdump()`.","message":"Python 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`.","severity":"breaking","affected_versions":"All Python 3 versions (from `hexdump` 0.3 onwards)"},{"fix":"If 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`).","message":"When 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.","severity":"gotcha","affected_versions":"All versions when used as a command-line tool via OS packages"},{"fix":"If 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.","message":"The `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.","severity":"gotcha","affected_versions":"All versions"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}