Get Mimetypes Of File In Python with module mimetypes

The mimetypes module converts between a filename or URL and the MIME type associated with the filename extension.

1
2
3
4
5
6
7
8
import mimetypes

def get_mimetype(path):
    """
    get mime type of file with file path
    """
    mime_type, _ = mimetypes.guess_type(path)
    return mime_type