ishex

raw JSON →
1.1.0 verified Fri May 01 auth: no python

Simple Python package to check if a string is valid hexadecimal. Current version 1.1.0, updated infrequently.

pip install ishex
error ModuleNotFoundError: No module named 'isHex'
cause Importing with wrong casing; module name is all lowercase 'ishex'.
fix
pip install ishex; then use 'from ishex import isHex'.
error NameError: name 'isHex' is not defined
cause Attempting to call isHex() without importing it correctly.
fix
Ensure import: 'from ishex import isHex'.
gotcha Function names use camelCase (isHex, isHexLower, isHexUpper) while package name is all lowercase (ishex). Ensure correct casing when importing.
fix Use 'from ishex import isHex' not 'import ishex' then call 'ishex.isHex' (though that also works, but the function is isHex).
gotcha The functions accept optional '0x' or '0X' prefix by default and treat them as valid hex. Some other hex checkers may reject prefixes. Be aware if you need strict no-prefix validation.
fix If you need to reject prefixes, strip them before calling isHex().
gotcha Package is very small and not actively maintained. Last release 1.1.0 (2022). No future updates guaranteed.
fix Consider alternatives like 'binascii' or a custom check if you need active maintenance.

Basic usage: check if string is hexadecimal, with optional case validation.

from ishex import isHex, isHexLower, isHexUpper

# Validate a hex string
print(isHex("1a2b3f"))  # True
print(isHex("0x1a2b3f")) # True (with 0x prefix)
print(isHex("xyz"))     # False

# Validate case-specific
print(isHexLower("1a2b")) # True
print(isHexUpper("1A2B")) # True