On this page
  1. mimetypes.guess_file_type
  2. Import
  3. Signature & Overview
  4. Usage
  5. Gotchas
  6. REPL Inspect

mimetypes.guess_file_type

Prev: mimetypes.guess_extension | Up: mimetypes | Next: mimetypes.guess_type
Rel: mimetypes.add_type, mimetypes.guess_all_extensions, mimetypes.guess_extension, mimetypes.guess_type
Ref: docs.python.org — mimetypes.guess_file_type
Tags: #public #python3 #stdlib #mimetypes


Import

import mimetypes
from mimetypes import guess_file_type

Signature & Overview

mimetypes.guess_file_type(path, *, strict=True)

Guess the type of a file based on its path.

Usage

import mimetypes

# Python 3.13+: path-aware counterpart to guess_type() (does not parse URL schemes)
if hasattr(mimetypes, "guess_file_type"):
    assert mimetypes.guess_file_type("report.pdf")[0] == "application/pdf"

Gotchas

REPL Inspect

from mimetypes import guess_file_type
help(guess_file_type)

Linked from

Related notes