python-magic is a module that uses ctypes to access the libmagic file type identification library. It makes use of the local magic database and supports both textual and MIME-type output.