filetype


Namefiletype JSON
Version 1.2.0 PyPI version JSON
download
home_pagehttps://github.com/h2non/filetype.py
SummaryInfer file type and MIME type of any file/buffer. No external dependencies.
upload_time2022-11-02 17:34:04
maintainer
docs_urlNone
authorTomas Aparicio
requires_python
licenseMIT
keywords file libmagic magic infer numbers magicnumbers discovery mime type kind
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI
coveralls test coverage
            filetype.py |Build Status| |PyPI| |Pyversions| |API|
====================================================

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.

Features
--------

-  Simple and friendly API
-  Supports a `wide range`_ of file types
-  Provides file extension and MIME type inference
-  File discovery by extension or MIME type
-  File discovery by kind (image, video, audio…)
-  `Pluggable`_: add new custom type matchers
-  `Fast`_, even processing large files
-  Only first 261 bytes representing the max file header is required, so
   you can just `pass a list of bytes`_
-  Dependency free (just Python code, no C extensions, no libmagic
   bindings)
-  Cross-platform file recognition

Installation
------------

::

    pip install filetype

API
---

See `annotated API reference`_.

Examples
--------

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()

Supported types
---------------

Image
^^^^^

-  **dwg** - ``image/vnd.dwg``
-  **xcf** - ``image/x-xcf``
-  **jpg** - ``image/jpeg``
-  **jpx** - ``image/jpx``
-  **png** - ``image/png``
-  **apng** - ``image/apng``
-  **gif** - ``image/gif``
-  **webp** - ``image/webp``
-  **cr2** - ``image/x-canon-cr2``
-  **tif** - ``image/tiff``
-  **bmp** - ``image/bmp``
-  **jxr** - ``image/vnd.ms-photo``
-  **psd** - ``image/vnd.adobe.photoshop``
-  **ico** - ``image/x-icon``
-  **heic** - ``image/heic``
-  **avif** - ``image/avif``

Video
^^^^^

-  **3gp** - ``video/3gpp``
-  **mp4** - ``video/mp4``
-  **m4v** - ``video/x-m4v``
-  **mkv** - ``video/x-matroska``
-  **webm** - ``video/webm``
-  **mov** - ``video/quicktime``
-  **avi** - ``video/x-msvideo``
-  **wmv** - ``video/x-ms-wmv``
-  **mpg** - ``video/mpeg``
-  **flv** - ``video/x-flv``

Audio
^^^^^

-  **aac** - ``audio/aac``
-  **mid** - ``audio/midi``
-  **mp3** - ``audio/mpeg``
-  **m4a** - ``audio/mp4``
-  **ogg** - ``audio/ogg``
-  **flac** - ``audio/x-flac``
-  **wav** - ``audio/x-wav``
-  **amr** - ``audio/amr``
-  **aiff** - ``audio/x-aiff``

Archive
^^^^^^^

-  **br** - ``application/x-brotli``
-  **rpm** - ``application/x-rpm``
-  **dcm** - ``application/dicom``
-  **epub** - ``application/epub+zip``
-  **zip** - ``application/zip``
-  **tar** - ``application/x-tar``
-  **rar** - ``application/x-rar-compressed``
-  **gz** - ``application/gzip``
-  **bz2** - ``application/x-bzip2``
-  **7z** - ``application/x-7z-compressed``
-  **xz** - ``application/x-xz``
-  **pdf** - ``application/pdf``
-  **exe** - ``application/x-msdownload``
-  **swf** - ``application/x-shockwave-flash``
-  **rtf** - ``application/rtf``
-  **eot** - ``application/octet-stream``
-  **ps** - ``application/postscript``
-  **sqlite** - ``application/x-sqlite3``
-  **nes** - ``application/x-nintendo-nes-rom``
-  **crx** - ``application/x-google-chrome-extension``
-  **cab** - ``application/vnd.ms-cab-compressed``
-  **deb** - ``application/x-deb``
-  **ar** - ``application/x-unix-archive``
-  **Z** - ``application/x-compress``
-  **lzo** - ``application/x-lzop``
-  **lz** - ``application/x-lzip``
-  **lz4** - ``application/x-lz4``
-  **zstd** - ``application/zstd``

Document
^^^^^^^^

-  **doc** - ``application/msword``
-  **docx** - ``application/vnd.openxmlformats-officedocument.wordprocessingml.document``
-  **odt** - ``application/vnd.oasis.opendocument.text``
-  **xls** - ``application/vnd.ms-excel``
-  **xlsx** - ``application/vnd.openxmlformats-officedocument.spreadsheetml.sheet``
-  **ods** - ``application/vnd.oasis.opendocument.spreadsheet``
-  **ppt** - ``application/vnd.ms-powerpoint``
-  **pptx** - ``application/vnd.openxmlformats-officedocument.presentationml.presentation``
-  **odp** - ``application/vnd.oasis.opendocument.presentation``

Font
^^^^

-  **woff** - ``application/font-woff``
-  **woff2** - ``application/font-woff``
-  **ttf** - ``application/font-sfnt``
-  **otf** - ``application/font-sfnt``

Application
^^^^^^^^^^^ 

-  **wasm** - ``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



            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/h2non/filetype.py",
    "name": "filetype",
    "maintainer": "",
    "docs_url": null,
    "requires_python": "",
    "maintainer_email": "",
    "keywords": "file libmagic magic infer numbers magicnumbers discovery mime type kind",
    "author": "Tomas Aparicio",
    "author_email": "tomas@aparicio.me",
    "download_url": "https://files.pythonhosted.org/packages/bb/29/745f7d30d47fe0f251d3ad3dc2978a23141917661998763bebb6da007eb1/filetype-1.2.0.tar.gz",
    "platform": "any",
    "description": "filetype.py |Build Status| |PyPI| |Pyversions| |API|\n====================================================\n\nSmall and dependency free `Python`_ package to infer file type and MIME\ntype checking the `magic numbers`_ signature of a file or buffer.\n\nThis is a Python port from `filetype`_ Go package.\n\nFeatures\n--------\n\n-  Simple and friendly API\n-  Supports a `wide range`_ of file types\n-  Provides file extension and MIME type inference\n-  File discovery by extension or MIME type\n-  File discovery by kind (image, video, audio\u2026)\n-  `Pluggable`_: add new custom type matchers\n-  `Fast`_, even processing large files\n-  Only first 261 bytes representing the max file header is required, so\n   you can just `pass a list of bytes`_\n-  Dependency free (just Python code, no C extensions, no libmagic\n   bindings)\n-  Cross-platform file recognition\n\nInstallation\n------------\n\n::\n\n    pip install filetype\n\nAPI\n---\n\nSee `annotated API reference`_.\n\nExamples\n--------\n\nSimple file type checking\n^^^^^^^^^^^^^^^^^^^^^^^^^\n\n.. code-block:: python\n\n    import filetype\n\n    def main():\n        kind = filetype.guess('tests/fixtures/sample.jpg')\n        if kind is None:\n            print('Cannot guess file type!')\n            return\n\n        print('File extension: %s' % kind.extension)\n        print('File MIME type: %s' % kind.mime)\n\n    if __name__ == '__main__':\n        main()\n\nSupported types\n---------------\n\nImage\n^^^^^\n\n-  **dwg** - ``image/vnd.dwg``\n-  **xcf** - ``image/x-xcf``\n-  **jpg** - ``image/jpeg``\n-  **jpx** - ``image/jpx``\n-  **png** - ``image/png``\n-  **apng** - ``image/apng``\n-  **gif** - ``image/gif``\n-  **webp** - ``image/webp``\n-  **cr2** - ``image/x-canon-cr2``\n-  **tif** - ``image/tiff``\n-  **bmp** - ``image/bmp``\n-  **jxr** - ``image/vnd.ms-photo``\n-  **psd** - ``image/vnd.adobe.photoshop``\n-  **ico** - ``image/x-icon``\n-  **heic** - ``image/heic``\n-  **avif** - ``image/avif``\n\nVideo\n^^^^^\n\n-  **3gp** - ``video/3gpp``\n-  **mp4** - ``video/mp4``\n-  **m4v** - ``video/x-m4v``\n-  **mkv** - ``video/x-matroska``\n-  **webm** - ``video/webm``\n-  **mov** - ``video/quicktime``\n-  **avi** - ``video/x-msvideo``\n-  **wmv** - ``video/x-ms-wmv``\n-  **mpg** - ``video/mpeg``\n-  **flv** - ``video/x-flv``\n\nAudio\n^^^^^\n\n-  **aac** - ``audio/aac``\n-  **mid** - ``audio/midi``\n-  **mp3** - ``audio/mpeg``\n-  **m4a** - ``audio/mp4``\n-  **ogg** - ``audio/ogg``\n-  **flac** - ``audio/x-flac``\n-  **wav** - ``audio/x-wav``\n-  **amr** - ``audio/amr``\n-  **aiff** - ``audio/x-aiff``\n\nArchive\n^^^^^^^\n\n-  **br** - ``application/x-brotli``\n-  **rpm** - ``application/x-rpm``\n-  **dcm** - ``application/dicom``\n-  **epub** - ``application/epub+zip``\n-  **zip** - ``application/zip``\n-  **tar** - ``application/x-tar``\n-  **rar** - ``application/x-rar-compressed``\n-  **gz** - ``application/gzip``\n-  **bz2** - ``application/x-bzip2``\n-  **7z** - ``application/x-7z-compressed``\n-  **xz** - ``application/x-xz``\n-  **pdf** - ``application/pdf``\n-  **exe** - ``application/x-msdownload``\n-  **swf** - ``application/x-shockwave-flash``\n-  **rtf** - ``application/rtf``\n-  **eot** - ``application/octet-stream``\n-  **ps** - ``application/postscript``\n-  **sqlite** - ``application/x-sqlite3``\n-  **nes** - ``application/x-nintendo-nes-rom``\n-  **crx** - ``application/x-google-chrome-extension``\n-  **cab** - ``application/vnd.ms-cab-compressed``\n-  **deb** - ``application/x-deb``\n-  **ar** - ``application/x-unix-archive``\n-  **Z** - ``application/x-compress``\n-  **lzo** - ``application/x-lzop``\n-  **lz** - ``application/x-lzip``\n-  **lz4** - ``application/x-lz4``\n-  **zstd** - ``application/zstd``\n\nDocument\n^^^^^^^^\n\n-  **doc** - ``application/msword``\n-  **docx** - ``application/vnd.openxmlformats-officedocument.wordprocessingml.document``\n-  **odt** - ``application/vnd.oasis.opendocument.text``\n-  **xls** - ``application/vnd.ms-excel``\n-  **xlsx** - ``application/vnd.openxmlformats-officedocument.spreadsheetml.sheet``\n-  **ods** - ``application/vnd.oasis.opendocument.spreadsheet``\n-  **ppt** - ``application/vnd.ms-powerpoint``\n-  **pptx** - ``application/vnd.openxmlformats-officedocument.presentationml.presentation``\n-  **odp** - ``application/vnd.oasis.opendocument.presentation``\n\nFont\n^^^^\n\n-  **woff** - ``application/font-woff``\n-  **woff2** - ``application/font-woff``\n-  **ttf** - ``application/font-sfnt``\n-  **otf** - ``application/font-sfnt``\n\nApplication\n^^^^^^^^^^^ \n\n-  **wasm** - ``application/wasm``\n\n.. _Python: http://python.org\n.. _magic numbers: https://en.wikipedia.org/wiki/Magic_number_(programming)#Magic_numbers_in_files\n.. _filetype: https://github.com/h2non/filetype\n.. _wide range: #supported-types\n.. _Pluggable: #add-additional-file-type-matchers\n.. _Fast: #benchmarks\n.. _pass a list of bytes: #file-header\n.. _annotated API reference: https://h2non.github.io/filetype.py/\n\n.. |Build Status| image:: https://travis-ci.org/h2non/filetype.py.svg?branch=master\n   :target: https://travis-ci.org/h2non/filetype.py\n.. |PyPI| image:: https://img.shields.io/pypi/v/filetype.svg?maxAge=2592000?style=flat-square\n   :target: https://pypi.python.org/pypi/filetype\n.. |Pyversions| image:: https://img.shields.io/pypi/pyversions/filetype.svg?style=flat-square\n    :target: https://pypi.python.org/pypi/filetype\n.. |API| image:: https://img.shields.io/badge/api-docs-green.svg\n   :target: https://h2non.github.io/filetype.py\n\n\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "Infer file type and MIME type of any file/buffer. No external dependencies.",
    "version": "1.2.0",
    "split_keywords": [
        "file",
        "libmagic",
        "magic",
        "infer",
        "numbers",
        "magicnumbers",
        "discovery",
        "mime",
        "type",
        "kind"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "md5": "0386ec78d63783e9d61d149bfbfbbafd",
                "sha256": "7ce71b6880181241cf7ac8697a2f1eb6a8bd9b429f7ad6d27b8db9ba5f1c2d25"
            },
            "downloads": -1,
            "filename": "filetype-1.2.0-py2.py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "0386ec78d63783e9d61d149bfbfbbafd",
            "packagetype": "bdist_wheel",
            "python_version": "py2.py3",
            "requires_python": null,
            "size": 19970,
            "upload_time": "2022-11-02T17:34:01",
            "upload_time_iso_8601": "2022-11-02T17:34:01.425061Z",
            "url": "https://files.pythonhosted.org/packages/18/79/1b8fa1bb3568781e84c9200f951c735f3f157429f44be0495da55894d620/filetype-1.2.0-py2.py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "md5": "915c437718ad93c2cd347eb5aa465af1",
                "sha256": "66b56cd6474bf41d8c54660347d37afcc3f7d1970648de365c102ef77548aadb"
            },
            "downloads": -1,
            "filename": "filetype-1.2.0.tar.gz",
            "has_sig": false,
            "md5_digest": "915c437718ad93c2cd347eb5aa465af1",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": null,
            "size": 998020,
            "upload_time": "2022-11-02T17:34:04",
            "upload_time_iso_8601": "2022-11-02T17:34:04.141142Z",
            "url": "https://files.pythonhosted.org/packages/bb/29/745f7d30d47fe0f251d3ad3dc2978a23141917661998763bebb6da007eb1/filetype-1.2.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2022-11-02 17:34:04",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "github_user": "h2non",
    "github_project": "filetype.py",
    "travis_ci": true,
    "coveralls": true,
    "github_actions": true,
    "tox": true,
    "lcname": "filetype"
}
        
Elapsed time: 0.07099s