filetype
Infer file type and MIME type of any file/buffer. No external dependencies.
Install
filetype on PyPI
pip
pip install filetypeuv
uv add filetypepoetry
poetry add filetypePackage facts
| License | MIT (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | none |
| Maintenance | aging — 1,380 days since the last release |
| Last repo commit | |
| First released | |
| Popularity | one of the top 1,000 most-downloaded packages on PyPI (30-day window, as of 2026-08-13) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-13) |
Evidence: filetype-1.2.0-py2.py3-none-any.whl
Keywords: file, libmagic, magic, infer, numbers, magicnumbers, discovery, mime, type, kind
About filetype
from the package's own PyPI description — quoted content, verbatim
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 matchersFast_, 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...
Read as markdown · JSON record · Source repository · Homepage
AI interpretation — verify before relying
AI-generated interpretation of the package facts above; every digit, version, license, or vulnerability id it cites is grounded in the facts already shown on this page
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.
Low friction: pure Python with zero runtime dependencies and a single wheel distribution. Maintenance is aging—last release was 2022-11-02 and repository shows no recent activity—but the codebase is stable and marked Production/Stable.
MIT license (permissive) imposes no restrictions on commercial or proprietary use; you may use, modify, and distribute freely provided you retain the license notice.
Usage
pip install filetype==1.2.0
import filetype
kind = filetype.guess('sample.jpg')
if kind:
print(f'Extension: {kind.extension}, MIME: {kind.mime}')
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.
Needs verification
- Whether classifier support for Python 3.5–3.9 extends to Python 3.10+ or if compatibility issues exist with newer versions.
- Whether the 261-byte file header limit is sufficient for all supported file types or if some require deeper inspection.
- How many distinct file types are actually supported across all categories listed in the documentation.
Similar packages
permissive · top 1,000 on PyPI
python-magicpermissive · top 1,000 on PyPI
soundfilepermissive · top 1,000 on PyPI
ImageIOpermissive · top 1,000 on PyPI
backports.zstdpermissive · top 1,000 on PyPI
datasetspermissive · top 1,000 on PyPI
fonttoolspermissive · top 1,000 on PyPI
cramjampermissive · top 1,000 on PyPI
python-pptxpermissive · top 1,000 on PyPI
chardetpermissive · top 1,000 on PyPI