--- id: filetype version: "1.2.0" license: MIT license_treatment: permissive maintenance: aging --- # filetype — Infer file type and MIME type of any file/buffer. No external dependencies. License: permissive · Maintenance: aging · Popularity: top 1,000 on PyPI ## Install pip install filetype uv add filetype poetry add filetype ## Description filetype.py |Build Status| |PyPI| |Pyversions| |API| ==================================================== Small and dependency free `Python`_ package to infer file type and MIME type checking the `magic numbers`_ signature of a file or buffer. This is a Python port from `filetype`_ Go package. Features -------- - Simple and friendly API - Supports a `wide range`_ of file types - Provides file extension and MIME type inference - File discovery by extension or MIME type - File discovery by kind (image, video, audio…) - `Pluggable`_: add new custom type matchers - `Fast`_, even processing large files - Only first 261 bytes representing the max file header is required, so you can just `pass a list of bytes`_ - Dependency free (just Python code, no C extensions, no libmagic bindings) - Cross-platform file recognition Installation ------------ :: pip install filetype API --- See `annotated API reference`_. Examples -------- Simple file type checking ^^^^^^^^^^^^^^^^^^^^^^^^^ .. code-block:: python import filetype def main(): kind = filetype.guess('tests/fixtures/sample.jpg') if kind is None: print('Cannot guess... ## AI interpretation — verify before relying Identifies file types and MIME types by examining magic number signatures in file headers, supporting images, videos, audio, archives, documents, and fonts without external dependencies. Verdict: A mature, dependency-free utility for file type detection safe for production use. No known vulnerabilities, permissive MIT licensing, and straightforward installation make it low-risk. Aging maintenance (no releases since 2022-11-02) is not a blocker for a stable library, but users should expect no updates for new formats. [View on SkillFed](https://skillfed.io/packages/filetype) · [View on PyPI](https://pypi.org/project/filetype/)