all Python 3mimetypesfunction
mimetypes.add_type()
type database
Adds an 'extension → MIME type' mapping to the module-wide database so that guess_type recognises new formats.
Syntax
mimetypes.add_type(type, ext, strict=True)
The extension needs its dot: add_type('text/x-foo', 'foo') quietly registers a useless key (DeprecationWarning since 3.14, ValueError promised for 3.16). The change is global and lasts for the life of the process; calling mimetypes.init() again wipes it. To avoid affecting other code, add the type to your own MimeTypes instance.
Examples
import mimetypes
mimetypes.add_type('application/x-mydata', '.myd')
print(mimetypes.guess_type('save.myd')) # → ('application/x-mydata', None)
print(mimetypes.guess_extension('application/x-mydata')) # → .myd
See also
Open in the full glossarydocs.python.orgReport an inaccuracy