typecode
Comprehensive filetype and mimetype detection using libmagic and Pygments.
What it is and what it does
TypeCode is a file type and MIME type detection library that wraps libmagic and Pygments to identify file formats. It started as a library within scancode-toolkit and provides a unified interface for comprehensive filetype detection across Linux, Windows, and macOS.
The package supports multiple installation modes: the [full] extra bundles libmagic binaries for immediate use, while the minimal install expects libmagic to be provided by the system, environment variables, or a plugin. It integrates with the plugincode system to allow custom libmagic providers, making it flexible for environments with non-standard library locations.
Use it for:
- Identify file types in batch processing pipelines without relying on file extensions.
- Determine MIME types for web servers or content management systems handling user uploads.
- Integrate file type detection into security scanning or compliance tools.
- Classify documents by format in archival or document management workflows.
- Detect and handle PDF and other structured formats via pdfminer.six integration.
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Detects file types and MIME types using libmagic and Pygments, with support for multiple detection methods and optional system or bundled libmagic libraries.
Yes. Active maintenance, production-stable status, low install friction, no known vulnerabilities, and permissive licensing make it a solid choice. Install with [full] for immediate use, or [minimal] if your environment already provides libmagic 5.39. Best suited for projects needing reliable file type detection beyond filename inspection.
Install
typecode on PyPI
pip
pip install typecodeuv
uv add typecodepoetry
poetry add typecodeInstalling typecode
Before you install
Low install friction with a pure Python wheel. Actively maintained with recent commits and production-stable status. Five runtime dependencies including attrs, binaryornot, commoncode, pdfminer.six, and plugincode.
License in practice
Apache-2.0 permissive license allows commercial and private use with minimal restrictions—suitable for most projects.
Quickstart
pip install typecode
from typecode import identify
result = identify.identify_file('path/to/file')
Requires libmagic 5.39 available either via the [full] extra, system PATH, environment variables (TYPECODE_LIBMAGIC_PATH, TYPECODE_LIBMAGIC_DB_PATH), or a typecode-libmagic plugin.
Verify before relying
- Whether the package's API surface and typical workflows are well-documented beyond the README.
- Performance characteristics when processing large batches of files or unusual formats.
- Specific accuracy or edge-case behavior compared to direct libmagic or Pygments use.
Package facts
| License | Apache-2.0 (permissive) |
| Python support | supports the current Python release (>=3.10) |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 5 — attrs, binaryornot, commoncode, pdfminer.six, plugincode |
| Maintenance | actively maintained — 144 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 127,394/month — #11,745 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: typecode-30.2.0-py3-none-any.whl
Keywords: open source, filetype, mimetype, libmagic, scancode-toolkit, typecode, utilities
Tags
More Software Development packages
Provides backported and experimental type hints…
permissive · top 100 on PyPI
numpyNumPy provides an N-dimensional array object…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
annotated-docProvides a way to document function parameters,…
permissive · top 100 on PyPI
typerTyper builds command-line applications from…
permissive · top 1,000 on PyPI
distlibDistlib provides low-level packaging utilities…
permissive · top 1,000 on PyPI
typecode-libmagicProvides a prebuilt native libmagic binary and…
copyleft · top 15,000 on PyPI
filetypeInfers file type and MIME type by examining…
permissive · top 1,000 on PyPI
libmagicProvides Python bindings to the libmagic…
copyleft · top 15,000 on PyPI
polyfile-weaveIdentifies and maps the semantic and syntactic…
permissive · top 5,000 on PyPI
python-magicIdentifies file types by reading file headers…
permissive · top 1,000 on PyPI
file-magicfile-magic provides a Python interface to…
permissive · top 15,000 on PyPI
python-magic-binIdentifies file types by examining file headers…
permissive · top 15,000 on PyPI
extractcode-libarchiveProvides a prebuilt native libarchive binary as…
permissive · top 15,000 on PyPI
mediatypeParses and creates MIME types (media types)…
permissive · top 15,000 on PyPI
scancode-toolkitScanCode Toolkit detects licenses, copyrights,…
permissive · top 15,000 on PyPI