API Reference
content-types is intentionally tiny: lookup functions for both directions (filename -> type, and type -> extension), the mapping table behind them, and a handful of precomputed shortcut constants for the most common formats.
Forward lookup
Map a filename, bare extension, Path, or URL to its MIME / content type.
- get_content_type()
-
Return the most specific, commonly accepted MIME type for a filename or extension.
Reverse lookup
Map a MIME / content type back to its file extension(s) — the inverse of get_content_type.
- guess_extension()
-
Return the canonical file extension for a MIME / content type.
- guess_all_extensions()
-
Return every known file extension for a MIME / content type, canonical first.
Mapping data
The underlying extension -> content-type table (364 entries; keys have no leading dot).
- EXTENSION_TO_CONTENT_TYPE
-
The extension -> content type table that every lookup reads from.
Shortcut constants
Precomputed content types for very common formats, exposed as module-level attributes.
- webp
-
The content type for
.webpfiles:image/webp. - png
-
The content type for
.pngfiles:image/png. - jpg
-
The content type for
.jpgfiles:image/jpeg. - mp3
-
The content type for
.mp3files:audio/mpeg. - json
-
The content type for
.jsonfiles:application/json. -
The content type for
.pdffiles:application/pdf. - zip
-
The content type for
.zipfiles:application/zip. - xml
-
The content type for
.xmlfiles:application/xml. - csv
-
The content type for
.csvfiles:text/csv. - md
-
The content type for
.mdfiles:text/markdown. - parquet
-
The content type for
.parquetfiles:application/vnd.apache.parquet. - ipynb
-
The content type for
.ipynbfiles:application/x-ipynb+json. - pkl
-
The content type for
.pklfiles:application/octet-stream. - yaml
-
The content type for
.yamlfiles:application/yaml. - toml
-
The content type for
.tomlfiles:application/toml. - sqlite
-
The content type for
.sqlitefiles:application/vnd.sqlite3.