skillfed

typecode

Comprehensive filetype and mimetype detection using libmagic and Pygments.

typecode v30.2.0 127.4K downloads/30d#11,745 on PyPI10
Permissive license Apache-2.0 Active released

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 typecode

uv

uv add typecode

poetry

poetry add typecode

Installing 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

Development Status :: 5 - Production/StableIntended Audience :: DevelopersProgramming Language :: Python :: 3Programming Language :: Python :: 3 :: OnlyProgramming Language :: Python :: 3.10Programming Language :: Python :: 3.6Programming Language :: Python :: 3.7Programming Language :: Python :: 3.8Programming Language :: Python :: 3.9Topic :: Software DevelopmentTopic :: Utilities

Tags

file type detectionmime type detectionlibmagic wrapperfile format identificationmagic number detectionfiletype classifier
file-identificationlibmagic-wrapper

More Software Development packages