{
    "mode": "pydoc",
    "parameter": "magic",
    "section": "",
    "url": "https://www.chedong.com/phpMan.php/pydoc/magic/json",
    "generated": "2026-06-10T10:05:02Z",
    "sections": {
        "NAME": {
            "content": "magic - magic is a wrapper around the libmagic file identification library.\n",
            "subsections": []
        },
        "DESCRIPTION": {
            "content": "See README for more information.\n\nUsage:\n\n>>> import magic\n>>> magic.fromfile(\"testdata/test.pdf\")\n'PDF document, version 1.2'\n>>> magic.fromfile(\"testdata/test.pdf\", mime=True)\n'application/pdf'\n>>> magic.frombuffer(open(\"testdata/test.pdf\").read(1024))\n'PDF document, version 1.2'\n>>>\n",
            "subsections": []
        },
        "PACKAGE CONTENTS": {
            "content": "compat\nloader\n",
            "subsections": []
        },
        "CLASSES": {
            "content": "builtins.Exception(builtins.BaseException)\nMagicException\nbuiltins.object\nMagic\n",
            "subsections": [
                {
                    "name": "class Magic",
                    "content": "|  Magic(mime=False, magicfile=None, mimeencoding=False, keepgoing=False, uncompress=False, raw=False, extension=False)\n|\n|  Magic is a wrapper around the libmagic C library.\n|\n|  Methods defined here:\n|\n|  del(self)\n|\n|  init(self, mime=False, magicfile=None, mimeencoding=False, keepgoing=False, uncompress=False, raw=False, extension=False)\n|      Create a new libmagic wrapper.\n|\n|      mime - if True, mimetypes are returned instead of textual descriptions\n|      mimeencoding - if True, codec is returned\n|      magicfile - use a mime database other than the system default\n|      keepgoing - don't stop at the first match, keep going\n|      uncompress - Try to look inside compressed files.\n|      raw - Do not try to decode \"non-printable\" chars.\n|      extension - Print a slash-separated list of valid extensions for the file type found.\n|\n|  frombuffer(self, buf)\n|      Identify the contents of `buf`\n|\n|  fromdescriptor(self, fd)\n|\n|  fromfile(self, filename)\n|\n|  getparam(self, param)\n|\n|  setparam(self, param, val)\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors defined here:\n|\n|  dict\n|      dictionary for instance variables (if defined)\n|\n|  weakref\n|      list of weak references to the object (if defined)\n"
                },
                {
                    "name": "class MagicException",
                    "content": "|  MagicException(message)\n|\n|  Method resolution order:\n|      MagicException\n|      builtins.Exception\n|      builtins.BaseException\n|      builtins.object\n|\n|  Methods defined here:\n|\n|  init(self, message)\n|      Initialize self.  See help(type(self)) for accurate signature.\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors defined here:\n|\n|  weakref\n|      list of weak references to the object (if defined)\n|\n|  ----------------------------------------------------------------------\n|  Static methods inherited from builtins.Exception:\n|\n|  new(*args, kwargs) from builtins.type\n|      Create and return a new object.  See help(type) for accurate signature.\n|\n|  ----------------------------------------------------------------------\n|  Methods inherited from builtins.BaseException:\n|\n|  delattr(self, name, /)\n|      Implement delattr(self, name).\n|\n|  getattribute(self, name, /)\n|      Return getattr(self, name).\n|\n|  reduce(...)\n|      Helper for pickle.\n|\n|  repr(self, /)\n|      Return repr(self).\n|\n|  setattr(self, name, value, /)\n|      Implement setattr(self, name, value).\n|\n|  setstate(...)\n|\n|  str(self, /)\n|      Return str(self).\n|\n|  withtraceback(...)\n|      Exception.withtraceback(tb) --\n|      set self.traceback to tb and return self.\n|\n|  ----------------------------------------------------------------------\n|  Data descriptors inherited from builtins.BaseException:\n|\n|  cause\n|      exception cause\n|\n|  context\n|      exception context\n|\n|  dict\n|\n|  suppresscontext\n|\n|  traceback\n|\n|  args\n"
                }
            ]
        },
        "FUNCTIONS": {
            "content": "POINTER(...)\n",
            "subsections": [
                {
                    "name": "byref",
                    "content": "byref(C instance[, offset=0]) -> byref-object\nReturn a pointer lookalike to a C instance, only usable\nas function argument\n"
                },
                {
                    "name": "coerce_filename",
                    "content": "detectfromcontent = (*args, kwargs)\n\ndetectfromfilename = (*args, kwargs)\n\ndetectfromfobj = (*args, kwargs)\n"
                },
                {
                    "name": "errorcheck_negative_one",
                    "content": ""
                },
                {
                    "name": "errorcheck_null",
                    "content": ""
                },
                {
                    "name": "from_buffer",
                    "content": "Accepts a binary string and returns the detected filetype.  Return\nvalue is the mimetype if mime=True, otherwise a human readable\nname.\n\n>>> magic.frombuffer(open(\"testdata/test.pdf\").read(1024))\n'PDF document, version 1.2'\n"
                },
                {
                    "name": "from_descriptor",
                    "content": "Accepts a file descriptor and returns the detected filetype.  Return\nvalue is the mimetype if mime=True, otherwise a human readable\nname.\n\n>>> f = open(\"testdata/test.pdf\")\n>>> magic.fromdescriptor(f.fileno())\n'PDF document, version 1.2'\n"
                },
                {
                    "name": "from_file",
                    "content": "\"\nAccepts a filename and returns the detected filetype.  Return\nvalue is the mimetype if mime=True, otherwise a human readable\nname.\n\n>>> magic.fromfile(\"testdata/test.pdf\", mime=True)\n'application/pdf'\n"
                },
                {
                    "name": "magic_buffer",
                    "content": ""
                },
                {
                    "name": "magic_descriptor",
                    "content": ""
                },
                {
                    "name": "magic_file",
                    "content": ""
                },
                {
                    "name": "magic_getparam",
                    "content": ""
                },
                {
                    "name": "magic_load",
                    "content": ""
                },
                {
                    "name": "magic_setparam",
                    "content": ""
                },
                {
                    "name": "maybe_decode",
                    "content": "# return str on python3.  Don't want to unconditionally\n# decode because that results in unicode on python2\n\nopen = (*args, kwargs)\n"
                },
                {
                    "name": "version",
                    "content": ""
                }
            ]
        },
        "DATA": {
            "content": "APPLE = 2048\nCHECK = 64\nCOMPRESS = 4\nCONTINUE = 32\nDEBUG = 1\nDEFAULTMODE = 0\nDEVICES = 8\nERROR = 512\nMAGICAPPLE = 2048\nMAGICCHECK = 64\nMAGICCOMPRESS = 4\nMAGICCONTINUE = 32\nMAGICDEBUG = 1\nMAGICDEVICES = 8\nMAGICERROR = 512\nMAGICEXTENSION = 16777216\nMAGICMIME = 16\nMAGICMIMEENCODING = 1024\nMAGICMIMETYPE = 16\nMAGICNONE = 0\nMAGICNOCHECKAPPTYPE = 32768\nMAGICNOCHECKASCII = 131072\nMAGICNOCHECKBUILTIN = 4173824\nMAGICNOCHECKCDF = 262144\nMAGICNOCHECKCOMPRESS = 4096\nMAGICNOCHECKELF = 65536\nMAGICNOCHECKENCODING = 2097152\nMAGICNOCHECKFORTRAN = 524288\nMAGICNOCHECKSOFT = 16384\nMAGICNOCHECKTAR = 8192\nMAGICNOCHECKTEXT = 131072\nMAGICNOCHECKTOKENS = 1048576\nMAGICNOCHECKTROFF = 262144\nMAGICPARAMBYTESMAX = 6\nMAGICPARAMELFNOTESMAX = 4\nMAGICPARAMELFPHNUMMAX = 2\nMAGICPARAMELFSHNUMMAX = 3\nMAGICPARAMINDIRMAX = 0\nMAGICPARAMNAMEMAX = 1\nMAGICPARAMREGEXMAX = 5\nMAGICPRESERVEATIME = 128\nMAGICRAW = 256\nMAGICSYMLINK = 2\nMIME = 1040\nMIMEENCODING = 1024\nMIMETYPE = 16\nNONE = 0\nNOCHECKAPPTYPE = 32768\nNOCHECKBUILTIN = 4173824\nNOCHECKCDF = 262144\nNOCHECKCOMPRESS = 4096\nNOCHECKELF = 65536\nNOCHECKENCODING = 2097152\nNOCHECKSOFT = 16384\nNOCHECKTAR = 8192\nNOCHECKTEXT = 131072\nNOCHECKTOKENS = 1048576\nPRESERVEATIME = 128\nRAW = 256\nRTLDGLOBAL = 256\nRTLDLOCAL = 0\nSYMLINK = 2\nlibmagic = <CDLL 'libmagic.so.1', handle 5629bfe6bd80>\nmagiccheck = <FuncPtr object>\nmagicclose = <FuncPtr object>\nmagiccompile = <FuncPtr object>\nmagicerrno = <FuncPtr object>\nmagicerror = <FuncPtr object>\nmagicopen = <FuncPtr object>\nmagicsetflags = <FuncPtr object>\nmagicversion = <FuncPtr object>\n",
            "subsections": []
        },
        "FILE": {
            "content": "/usr/lib/python3/dist-packages/magic/init.py\n\n",
            "subsections": []
        }
    },
    "summary": "magic - magic is a wrapper around the libmagic file identification library.",
    "flags": [],
    "examples": [],
    "see_also": []
}