mimetypes.guess_extension()
mimetypes.guess_extension() is a Python function in the Mimetypes Module category. Guesses the file extension for a given MIME type. The syntax is mimetypes.guess_extension(type, strict=True). Parameters: type — MIME type string. Returns: Extension string or None. A typical example: mimetypes.guess_extension("image/jpeg") # ".jpg"
mimetypes.guess_extension("text/html") # ".html". A close sibling is mimetypes.guess_type(), which guesses the MIME type and encoding of a file from its URL/extension. A close sibling is mimetypes.init(), which initializes the MIME type database from system files. A close sibling is mimetypes.MimeTypes(), which creates a MIME types registry with optional custom mappings. A close sibling is mimetypes.read_windows_registry(), which loads MIME types from Windows registry (Windows only). More about this category: MIME type guessing — guess_type, guess_extension, init. Related Mimetypes Module entries: mimetypes.guess_type(), mimetypes.init(), mimetypes.MimeTypes(), mimetypes.read_windows_registry(). This page is part of the free Python Reference documentation covering 978+ functions, methods, and modules with examples and parameter details.