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
muslpy 3.10–3.95 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibcpy 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.fixOpen 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.fixUse 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.fixRead 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.