Registry / serialization / mimesniff

mimesniff

JSON →
library1.1.1pypypi✓ verified 86d ago

A pure Python implementation of the MIME sniffing algorithm from the WHATWG MIME Sniffing specification. Version 1.1.1 supports Python >=3.4 and allows sniffing MIME types from file-like objects or pre-read headers. Uses a decision tree based on byte patterns. Released infrequently.

pip install mimesniff
INSTALL
IMPORT
SIG · MIMESNIFF
M
mimesniff
serializationpythonv1.1.1
Install
1.6s avg
Import
—
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.9–3.13
musl
3.9–3.13
Install & Compatibility
Where this runs
tested against v1.1.1 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibc
py 3.10–3.95 runs
installs and imports cleanly · install 1.6s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

mimesniff
✓ from mimesniff import mimesniff
✗ from mimesniff import MimeSniffer
what
✓ from mimesniff import what

Call sniff() with bytes or a file-like object (opened in binary mode) to get the sniffed MIME type as a string.

import io from mimesniff import sniff # Example from bytes mime_type = sniff(b'%PDF-1.4') print(mime_type) # application/pdf # Example from file-like object with open('example.html', 'rb') as f: mime_type = sniff(f) print(mime_type) # text/html
Debug
Known issues
gotchasniff() expects bytes or a binary file-like object. Passing a string or text mode file will raise TypeError or produce incorrect results.
fix
Open files in binary mode (e.g., open('file', 'rb')) and ensure input is bytes.
affects: all
gotchaMimeSniffer class is partially implemented; sniff() function is the recommended entry point. The class API may change in future versions.
fix
Use sniff() function for stability.
affects: all
deprecatedThe 'PathLike' support was removed in version 1.0.1 for Python 3.4 compatibility. Using pathlib.Path objects may fail.
fix
Read the file bytes manually before passing to sniff().
affects: <1.0.1 (does not exist in 1.0.1+)
Upgrade
Version history
1.1.1latest on PyPI · released Oct 24, 2020
Audit
Dependencies

No dependency data recorded yet.

Agent activity
14 hits · last 30 days
node
14
Resources
mimesniff — pip install mimesniff · libregistry