typecode

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

Comprehensive filetype and mimetype detection using libmagic and Pygments. Current version: 30.2.0. Regular releases every few months.

pip install typecode
error ImportError: cannot import name 'TypeCode' from 'typecode'
cause Using wrong import path (e.g., from typecode.type import TypeCode) or stale installation.
fix
Use: from typecode import TypeCode. Ensure typecode >= 30.0.0 is installed.
error OSError: cannot load library 'magic'
cause libmagic shared library not found on the system.
fix
Install libmagic (e.g., sudo apt install libmagic1 on Debian/Ubuntu, brew install libmagic on macOS) or install the system_provided extra: pip install typecode[system_provided].
gotcha libmagic must be installed on the system or via the typecode-libmagic-system-provided plugin. On macOS/ARM Linux, you must install the 'system_provided' extra or have libmagic available via package manager.
fix pip install typecode[system_provided] OR install libmagic via apt/brew/etc.
deprecated pkg_resources usage was removed in v30.1.0. Code relying on pkg_resources to access typecode resources may break. Use importlib.metadata instead.
fix Replace pkg_resources references with importlib.metadata for resource access.
gotcha Pre-v30.0.0 used CalVer versioning; current versions are semantic (30.x.y). Some older documentation may reference CalVer patterns.
fix Use semver (30.x.y) for current versions; ignore CalVer references.
pip install typecode[system_provided]

Quickstart: create a TypeCode object from a file path and access mime/file types.

from typecode import TypeCode

# Initialize with a file path
tc = TypeCode('/path/to/file')
print(tc.mimetype)
print(tc.filetype)