Name | Date | Size | #Lines | LOC | ||
---|---|---|---|---|---|---|
.. | 03-May-2022 | - | ||||
examples/ | H | 28-Apr-2020 | - | 70 | 36 | |
filetype/ | H | 28-Apr-2020 | - | 1,864 | 1,453 | |
filetype.egg-info/ | H | 03-May-2022 | - | 181 | 149 | |
tests/ | H | 28-Apr-2020 | - | 199 | 132 | |
History.md | H A D | 18-Jan-2020 | 2.7 KiB | 100 | 81 | |
LICENSE | H A D | 18-Jan-2020 | 1.1 KiB | 22 | 17 | |
MANIFEST.in | H A D | 18-Jan-2020 | 67 | 5 | 4 | |
PKG-INFO | H A D | 28-Apr-2020 | 6.5 KiB | 181 | 149 | |
README.rst | H A D | 23-Mar-2020 | 4.2 KiB | 154 | 123 | |
setup.cfg | H A D | 28-Apr-2020 | 67 | 8 | 5 | |
setup.py | H A D | 28-Apr-2020 | 1.6 KiB | 42 | 37 |
README.rst
1filetype.py |Build Status| |PyPI| |Pyversions| |API| 2==================================================== 3 4Small and dependency free `Python`_ package to infer file type and MIME 5type checking the `magic numbers`_ signature of a file or buffer. 6 7This is a Python port from `filetype`_ Go package. 8 9Features 10-------- 11 12- Simple and friendly API 13- Supports a `wide range`_ of file types 14- Provides file extension and MIME type inference 15- File discovery by extension or MIME type 16- File discovery by kind (image, video, audio…) 17- `Pluggable`_: add new custom type matchers 18- `Fast`_, even processing large files 19- Only first 261 bytes representing the max file header is required, so 20 you can just `pass a list of bytes`_ 21- Dependency free (just Python code, no C extensions, no libmagic 22 bindings) 23- Cross-platform file recognition 24 25Installation 26------------ 27 28:: 29 30 pip install filetype 31 32API 33--- 34 35See `annotated API reference`_. 36 37Examples 38-------- 39 40Simple file type checking 41^^^^^^^^^^^^^^^^^^^^^^^^^ 42 43.. code-block:: python 44 45 import filetype 46 47 def main(): 48 kind = filetype.guess('tests/fixtures/sample.jpg') 49 if kind is None: 50 print('Cannot guess file type!') 51 return 52 53 print('File extension: %s' % kind.extension) 54 print('File MIME type: %s' % kind.mime) 55 56 if __name__ == '__main__': 57 main() 58 59Supported types 60--------------- 61 62Image 63^^^^^ 64 65- **jpg** - ``image/jpeg`` 66- **jpx** - ``image/jpx`` 67- **png** - ``image/png`` 68- **gif** - ``image/gif`` 69- **webp** - ``image/webp`` 70- **cr2** - ``image/x-canon-cr2`` 71- **tif** - ``image/tiff`` 72- **bmp** - ``image/bmp`` 73- **jxr** - ``image/vnd.ms-photo`` 74- **psd** - ``image/vnd.adobe.photoshop`` 75- **ico** - ``image/x-icon`` 76- **heic** - ``image/heic`` 77 78Video 79^^^^^ 80 81- **mp4** - ``video/mp4`` 82- **m4v** - ``video/x-m4v`` 83- **mkv** - ``video/x-matroska`` 84- **webm** - ``video/webm`` 85- **mov** - ``video/quicktime`` 86- **avi** - ``video/x-msvideo`` 87- **wmv** - ``video/x-ms-wmv`` 88- **mpg** - ``video/mpeg`` 89- **flv** - ``video/x-flv`` 90 91Audio 92^^^^^ 93 94- **mid** - ``audio/midi`` 95- **mp3** - ``audio/mpeg`` 96- **m4a** - ``audio/m4a`` 97- **ogg** - ``audio/ogg`` 98- **flac** - ``audio/x-flac`` 99- **wav** - ``audio/x-wav`` 100- **amr** - ``audio/amr`` 101 102Archive 103^^^^^^^ 104 105- **epub** - ``application/epub+zip`` 106- **zip** - ``application/zip`` 107- **tar** - ``application/x-tar`` 108- **rar** - ``application/x-rar-compressed`` 109- **gz** - ``application/gzip`` 110- **bz2** - ``application/x-bzip2`` 111- **7z** - ``application/x-7z-compressed`` 112- **xz** - ``application/x-xz`` 113- **pdf** - ``application/pdf`` 114- **exe** - ``application/x-msdownload`` 115- **swf** - ``application/x-shockwave-flash`` 116 117- **rtf** - ``application/rtf`` 118- **eot** - ``application/octet-stream`` 119- **ps** - ``application/postscript`` 120- **sqlite** - ``application/x-sqlite3`` 121- **nes** - ``application/x-nintendo-nes-rom`` 122- **crx** - ``application/x-google-chrome-extension`` 123- **cab** - ``application/vnd.ms-cab-compressed`` 124- **deb** - ``application/x-deb`` 125- **ar** - ``application/x-unix-archive`` 126- **Z** - ``application/x-compress`` 127- **lz** - ``application/x-lzip`` 128 129Font 130^^^^ 131 132- **woff** - ``application/font-woff`` 133- **woff2** - ``application/font-woff`` 134- **ttf** - ``application/font-sfnt`` 135- **otf** - ``application/font-sfnt`` 136 137.. _Python: http://python.org 138.. _magic numbers: https://en.wikipedia.org/wiki/Magic_number_(programming)#Magic_numbers_in_files 139.. _filetype: https://github.com/h2non/filetype 140.. _wide range: #supported-types 141.. _Pluggable: #add-additional-file-type-matchers 142.. _Fast: #benchmarks 143.. _pass a list of bytes: #file-header 144.. _annotated API reference: https://h2non.github.io/filetype.py/ 145 146.. |Build Status| image:: https://travis-ci.org/h2non/filetype.py.svg?branch=master 147 :target: https://travis-ci.org/h2non/filetype.py 148.. |PyPI| image:: https://img.shields.io/pypi/v/filetype.svg?maxAge=2592000?style=flat-square 149 :target: https://pypi.python.org/pypi/filetype 150.. |Pyversions| image:: https://img.shields.io/pypi/pyversions/filetype.svg?style=flat-square 151 :target: https://pypi.python.org/pypi/filetype 152.. |API| image:: https://img.shields.io/badge/api-docs-green.svg 153 :target: https://h2non.github.io/filetype.py 154