{"id":24033,"library":"mimesniff","title":"mimesniff","description":"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.","status":"active","version":"1.1.1","language":"python","source_language":"en","source_url":"https://github.com/corona10/mimesniff","tags":["mime","sniffing","whatwg","python"],"install":[{"cmd":"pip install mimesniff","lang":"bash","label":"Install from PyPI"}],"dependencies":[],"imports":[{"wrong":"from mimesniff import MimeSniffer","symbol":"mimesniff","correct":"from mimesniff import mimesniff"},{"symbol":"what","correct":"from mimesniff import what"}],"quickstart":{"code":"import io\nfrom mimesniff import sniff\n\n# Example from bytes\nmime_type = sniff(b'%PDF-1.4')\nprint(mime_type)  # application/pdf\n\n# Example from file-like object\nwith open('example.html', 'rb') as f:\n    mime_type = sniff(f)\n    print(mime_type)  # text/html","lang":"python","description":"Call sniff() with bytes or a file-like object (opened in binary mode) to get the sniffed MIME type as a string."},"warnings":[{"fix":"Open files in binary mode (e.g., open('file', 'rb')) and ensure input is bytes.","message":"sniff() expects bytes or a binary file-like object. Passing a string or text mode file will raise TypeError or produce incorrect results.","severity":"gotcha","affected_versions":"all"},{"fix":"Use sniff() function for stability.","message":"MimeSniffer class is partially implemented; sniff() function is the recommended entry point. The class API may change in future versions.","severity":"gotcha","affected_versions":"all"},{"fix":"Read the file bytes manually before passing to sniff().","message":"The 'PathLike' support was removed in version 1.0.1 for Python 3.4 compatibility. Using pathlib.Path objects may fail.","severity":"deprecated","affected_versions":"<1.0.1 (does not exist in 1.0.1+)"}],"env_vars":null,"search_vec":"'1.1.1':18 '3.4':21 'algorithm':10 'allow':23 'base':41 'byte':43 'decis':39 'file':29 'file-lik':28 'header':36 'implement':5 'infrequ':46 'like':30 'mime':8,14,25,47 'mimesniff':1 'object':31 'pattern':44 'pre':34 'pre-read':33 'pure':3 'python':4,20,50 'read':35 'releas':45 'snif':9,15,24,48 'specif':16 'support':19 'tree':40 'type':26 'use':37 'version':17 'whatwg':13,49","created_at":"2026-05-01T08:10:56.069774+00:00","updated_at":"2026-05-01T08:10:56.069774+00:00","problems":null,"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"1.1.1","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/corona10/mimesniff","docs":null,"changelog":null,"pypi":"https://pypi.org/project/mimesniff/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["serialization","http-networking"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-07-03","last_verified":"2026-07-03","next_check":"2026-08-02","install_tag":null}}