PyDocs

Nav

Internet Data Handling

guess_type

mimetypes

function (source)
  • guess_type(url, strict=True)
Guess the type of a file based on its URL.

Return value is a tuple (type, encoding) where type is None if the
type can't be guessed (no or unknown suffix) or a string of the
form type/subtype, usable for a MIME Content-type header; and
encoding is None for no encoding or the name of the program used
to encode (e.g. compress or gzip).  The mappings are table
driven.  Encoding suffixes are case sensitive; type suffixes are
first tried case sensitive, then case insensitive.

The suffixes .tgz, .taz and .tz (case sensitive!) are all mapped
to ".tar.gz".  (This is table-driven too, using the dictionary
suffix_map).

Optional 'strict' argument when false adds a bunch of commonly found, but
non-standard types.
Changed in 3.8, 3.13
  • 3.8: Added support for url being a path-like object.
  • 3.13: Soft deprecated. Passing a file path instead of URL. Use guess_file_type() for this.
0 Examples
No examples for mimetypes/guess_type.
See Also
No see-alsos for mimetypes/guess_type
0 Notes
No notes for guess_type