mimetypes - pydoc - phpman

Look up a command

 

Markdown Format | JSON API | MCP Server Tool


mimetypes
NAME MODULE REFERENCE DESCRIPTION CLASSES FUNCTIONS DATA FILE
Help on module mimetypes:

NAME
    mimetypes - Guess the MIME type of a file.

MODULE REFERENCE
    https://docs.python.org/3.10/library/mimetypes.html

    The following documentation is automatically generated from the Python
    source files.  It may be incomplete, incorrect or include features that
    are considered implementation detail and may vary between Python
    implementations.  When in doubt, consult the module reference at the
    location listed above.

DESCRIPTION
    This module defines two useful functions:

    guess_type(url, strict=True) -- guess the MIME type and encoding of a URL.

    guess_extension(type, strict=True) -- guess the extension for a given MIME type.

    It also contains the following, for tuning the behavior:

    Data:

    knownfiles -- list of files to parse
    inited -- flag set when init() has been called
    suffix_map -- dictionary mapping suffixes to suffixes
    encodings_map -- dictionary mapping suffixes to encodings
    types_map -- dictionary mapping suffixes to types

    Functions:

    init([files]) -- parse a list of files, default knownfiles (on Windows, the
      default values are taken from the registry)
    read_mime_types(file) -- parse one file, return a dictionary or None

CLASSES
    builtins.object
        MimeTypes

    class MimeTypes(builtins.object)
     |  MimeTypes(filenames=(), strict=True)
     |
     |  MIME-types datastore.
     |
     |  This datastore can handle information from mime.types-style files
     |  and supports basic determination of MIME type from a filename or
     |  URL, and can guess a reasonable extension given a MIME type.
     |
     |  Methods defined here:
     |
     |  __init__(self, filenames=(), strict=True)
     |      Initialize self.  See help(type(self)) for accurate signature.
     |
     |  add_type(self, type, ext, strict=True)
     |      Add a mapping between a type and an extension.
     |
     |      When the extension is already known, the new
     |      type will replace the old one. When the type
     |      is already known the extension will be added
     |      to the list of known extensions.
     |
     |      If strict is true, information will be added to
     |      list of standard types, else to the list of non-standard
     |      types.
     |
     |  guess_all_extensions(self, type, strict=True)
     |      Guess the extensions for a file based on its MIME type.
     |
     |      Return value is a list of strings giving the possible filename
     |      extensions, including the leading dot ('.').  The extension is not
     |      guaranteed to have been associated with any particular data stream,
     |      but would be mapped to the MIME type `type' by guess_type().
     |
     |      Optional `strict' argument when false adds a bunch of commonly found,
     |      but non-standard types.
     |
     |  guess_extension(self, type, strict=True)
     |      Guess the extension for a file based on its MIME type.
     |
     |      Return value is a string giving a filename extension,
     |      including the leading dot ('.').  The extension is not
     |      guaranteed to have been associated with any particular data
     |      stream, but would be mapped to the MIME type `type' by
     |      guess_type().  If no extension can be guessed for `type', None
     |      is returned.
     |
     |      Optional `strict' argument when false adds a bunch of commonly found,
     |      but non-standard types.
     |
     |  guess_type(self, url, strict=True)
     |      Guess the type of a file which is either a URL or a path-like object.
     |
     |      Return value is a tuple (type, encoding) where type is None if
     |      the type can't be guessed (no or unknown suffix) or a string
     |      of the form type/subtype, usable for a MIME Content-type
     |      header; and encoding is None for no encoding or the name of
     |      the program used to encode (e.g. compress or gzip).  The
     |      mappings are table driven.  Encoding suffixes are case
     |      sensitive; type suffixes are first tried case sensitive, then
     |      case insensitive.
     |
     |      The suffixes .tgz, .taz and .tz (case sensitive!) are all
     |      mapped to '.tar.gz'.  (This is table-driven too, using the
     |      dictionary suffix_map.)
     |
     |      Optional `strict' argument when False adds a bunch of commonly found,
     |      but non-standard types.
     |
     |  read(self, filename, strict=True)
     |      Read a single mime.types-format file, specified by pathname.
     |
     |      If strict is true, information will be added to
     |      list of standard types, else to the list of non-standard
     |      types.
     |
     |  read_windows_registry(self, strict=True)
     |      Load the MIME types database from Windows registry.
     |
     |      If strict is true, information will be added to
     |      list of standard types, else to the list of non-standard
     |      types.
     |
     |  readfp(self, fp, strict=True)
     |      Read a single mime.types-format file.
     |
     |      If strict is true, information will be added to
     |      list of standard types, else to the list of non-standard
     |      types.
     |
     |  ----------------------------------------------------------------------
     |  Data descriptors defined here:
     |
     |  __dict__
     |      dictionary for instance variables (if defined)
     |
     |  __weakref__
     |      list of weak references to the object (if defined)

FUNCTIONS
    add_type(type, ext, strict=True)
        Add a mapping between a type and an extension.

        When the extension is already known, the new
        type will replace the old one. When the type
        is already known the extension will be added
        to the list of known extensions.

        If strict is true, information will be added to
        list of standard types, else to the list of non-standard
        types.

    guess_all_extensions(type, strict=True)
        Guess the extensions for a file based on its MIME type.

        Return value is a list of strings giving the possible filename
        extensions, including the leading dot ('.').  The extension is not
        guaranteed to have been associated with any particular data
        stream, but would be mapped to the MIME type `type' by
        guess_type().  If no extension can be guessed for `type', None
        is returned.

        Optional `strict' argument when false adds a bunch of commonly found,
        but non-standard types.

    guess_extension(type, strict=True)
        Guess the extension for a file based on its MIME type.

        Return value is a string giving a filename extension, including the
        leading dot ('.').  The extension is not guaranteed to have been
        associated with any particular data stream, but would be mapped to the
        MIME type `type' by guess_type().  If no extension can be guessed for
        `type', None is returned.

        Optional `strict' argument when false adds a bunch of commonly found,
        but non-standard types.

    guess_type(url, strict=True)
        Guess the type of a file based on its URL.

        Return value is a tuple (type, encoding) where type is None if the
        type can't be guessed (no or unknown suffix) or a string of the
        form type/subtype, usable for a MIME Content-type header; and
        encoding is None for no encoding or the name of the program used
        to encode (e.g. compress or gzip).  The mappings are table
        driven.  Encoding suffixes are case sensitive; type suffixes are
        first tried case sensitive, then case insensitive.

        The suffixes .tgz, .taz and .tz (case sensitive!) are all mapped
        to ".tar.gz".  (This is table-driven too, using the dictionary
        suffix_map).

        Optional `strict' argument when false adds a bunch of commonly found, but
        non-standard types.

    init(files=None)

    read_mime_types(file)

DATA
    __all__ = ['knownfiles', 'inited', 'MimeTypes', 'guess_type', 'guess_a...
    common_types = {'.jpg': 'image/jpg', '.mid': 'audio/midi', '.midi': 'a...
    encodings_map = {'.Z': 'compress', '.br': 'br', '.bz2': 'bzip2', '.gz'...
    inited = False
    knownfiles = ['/etc/mime.types', '/etc/httpd/mime.types', '/etc/httpd/...
    suffix_map = {'.svgz': '.svg.gz', '.taz': '.tar.gz', '.tbz2': '.tar.bz...
    types_map = {'.3g2': 'audio/3gpp2', '.3gp': 'audio/3gpp', '.3gpp': 'au...

FILE
    /usr/lib/python3.10/mimetypes.py



Generated by phpMan Author: Che Dong Under GNU General Public License
2026-06-02 05:17 @216.73.216.198 CrawledBy Mozilla/5.0 AppleWebKit/537.36 (KHTML, like Gecko; compatible; ClaudeBot/1.0; +claudebot@anthropic.com)
Valid XHTML 1.0 TransitionalValid CSS!

^_back to top