all Python 3mimetypesfunction
mimetypes.init()
type database
Rebuilds the module-wide MIME database: the built-in table plus the system files or a given list of files.
Syntax
mimetypes.init(files=None)
You rarely need to call it: the first guess_type runs init() itself. Calling it again erases everything added with add_type. The files you pass are added on top of the built-in table and the system files rather than replacing them, and a missing file in the list is simply skipped. Because of the system files, the shared database answers differently on different machines.
Examples
import mimetypes
with open('my.types', 'w', encoding='utf-8') as f:
f.write('text/x-foo foo fo\n')
print(mimetypes.guess_type('a.foo')) # → (None, None)
mimetypes.init(['my.types'])
print(mimetypes.guess_type('a.fo')) # → ('text/x-foo', None)
See also
Open in the full glossarydocs.python.orgReport an inaccuracy