GitHub

API reference for mime.

MIME types of file names, and file extensions of MIME types (Effect's Mime), from the standard table of the mime package::

get_type("index.html")          # "text/html"
get_extension("text/html")      # "html"

Functions

get_type

get_type(path) -> str | None

The MIME type of the file name or path's extension (any case), or None for an unknown one or a path without an extension.

ParameterTypeDescription
pathstr

Returns str | None

def get_type(path: str) -> str | None:
    """The MIME type of the file name or path's extension (any case), or
    ``None`` for an unknown one or a path without an extension."""
    last = _DIRECTORY.sub("", path, count=1).lower()
    extension = _STEM.sub("", last, count=1)
    has_path = len(last) < len(path)
    has_dot = len(extension) < len(last) - 1
    if not has_dot and has_path:
        return None
    return _tables().extension_to_type.get(extension)

get_extension

get_extension(mime_type) -> str | None

The usual extension of mime_type (parameters ignored).

ParameterTypeDescription
mime_typestr

Returns str | None

def get_extension(mime_type: str) -> str | None:
    """The usual extension of ``mime_type`` (parameters ignored)."""
    return _tables().type_to_extension.get(_essence(mime_type))

get_all_extensions

get_all_extensions(mime_type) -> frozenset[str] | None

Every extension of mime_type (parameters ignored).

ParameterTypeDescription
mime_typestr

Returns frozenset[str] | None

def get_all_extensions(mime_type: str) -> frozenset[str] | None:
    """Every extension of ``mime_type`` (parameters ignored)."""
    return _tables().type_to_extensions.get(_essence(mime_type))