Infer file type and MIME type of any file/buffer. No external dependencies.
Small and dependency free Python
_ package to infer file type and MIME
type checking the magic numbers
_ signature of a file or buffer.
This is a Python port from filetype
_ Go package.
wide range
_ of file typesPluggable
_: add new custom type matchersFast
_, even processing large filespass a list of bytes
_::
pip install filetype
See annotated API reference
_.
Simple file type checking ^^^^^^^^^^^^^^^^^^^^^^^^^
.. code-block:: python
import filetype
def main():
kind = filetype.guess('tests/fixtures/sample.jpg')
if kind is None:
print('Cannot guess file type!')
return
print('File extension: %s' % kind.extension)
print('File MIME type: %s' % kind.mime)
if __name__ == '__main__':
main()
Image ^^^^^
image/vnd.dwg
image/x-xcf
image/jpeg
image/jpx
image/png
image/apng
image/gif
image/webp
image/x-canon-cr2
image/tiff
image/bmp
image/vnd.ms-photo
image/vnd.adobe.photoshop
image/x-icon
image/heic
image/avif
Video ^^^^^
video/3gpp
video/mp4
video/x-m4v
video/x-matroska
video/webm
video/quicktime
video/x-msvideo
video/x-ms-wmv
video/mpeg
video/x-flv
Audio ^^^^^
audio/aac
audio/midi
audio/mpeg
audio/mp4
audio/ogg
audio/x-flac
audio/x-wav
audio/amr
audio/x-aiff
Archive ^^^^^^^
application/x-brotli
application/x-rpm
application/dicom
application/epub+zip
application/zip
application/x-tar
application/x-rar-compressed
application/gzip
application/x-bzip2
application/x-7z-compressed
application/x-xz
application/pdf
application/x-msdownload
application/x-shockwave-flash
application/rtf
application/octet-stream
application/postscript
application/x-sqlite3
application/x-nintendo-nes-rom
application/x-google-chrome-extension
application/vnd.ms-cab-compressed
application/x-deb
application/x-unix-archive
application/x-compress
application/x-lzop
application/x-lzip
application/x-lz4
application/zstd
Document ^^^^^^^^
application/msword
application/vnd.openxmlformats-officedocument.wordprocessingml.document
application/vnd.oasis.opendocument.text
application/vnd.ms-excel
application/vnd.openxmlformats-officedocument.spreadsheetml.sheet
application/vnd.oasis.opendocument.spreadsheet
application/vnd.ms-powerpoint
application/vnd.openxmlformats-officedocument.presentationml.presentation
application/vnd.oasis.opendocument.presentation
Font ^^^^
application/font-woff
application/font-woff
application/font-sfnt
application/font-sfnt
Application ^^^^^^^^^^^
application/wasm
.. _Python: http://python.org .. magic numbers: https://en.wikipedia.org/wiki/Magic_number(programming)#Magic_numbers_in_files .. _filetype: https://github.com/h2non/filetype .. _wide range: #supported-types .. _Pluggable: #add-additional-file-type-matchers .. _Fast: #benchmarks .. _pass a list of bytes: #file-header .. _annotated API reference: https://h2non.github.io/filetype.py/
.. |Build Status| image:: https://travis-ci.org/h2non/filetype.py.svg?branch=master :target: https://travis-ci.org/h2non/filetype.py .. |PyPI| image:: https://img.shields.io/pypi/v/filetype.svg?maxAge=2592000?style=flat-square :target: https://pypi.python.org/pypi/filetype .. |Pyversions| image:: https://img.shields.io/pypi/pyversions/filetype.svg?style=flat-square :target: https://pypi.python.org/pypi/filetype .. |API| image:: https://img.shields.io/badge/api-docs-green.svg :target: https://h2non.github.io/filetype.py