all Python 3mimetypesfunction
mimetypes.guess_all_extensions()
extensions
Returns a list of every known extension for a MIME type, such as all the extensions of text/plain. An empty list if the type is unknown.
Syntax
exts = mimetypes.guess_all_extensions(type, strict=True)
The list is longer than you expect: for text/plain it includes '.c', '.h', '.bat' and more, and its contents depend on the Python version and on the system type files, so never compare it whole with a literal in tests — check membership instead. An unknown type gives [], not None and not an exception.
Examples
import mimetypes
db = mimetypes.MimeTypes()
exts = db.guess_all_extensions('text/plain')
print('.txt' in exts, '.c' in exts) # → True True
print(db.guess_all_extensions('application/x-nonsense')) # → []
See also
Open in the full glossarydocs.python.orgReport an inaccuracy