Python mimetypes Module
Example
Guess the MIME type from a filename:
import mimetypes
print(mimetypes.guess_type("image.png"))
Try it Yourself »
Definition and Usage
The mimetypes module maps filenames to MIME types and encodings.
Use it to infer content type for HTTP responses or file handling tools.
Members
Member | Description |
---|---|
guess_type() | Guess the type of a file based on its name or URL. |
add_type() | Add a mapping from extension to MIME type. |
init() | Initialize the internal data structures. |