1 file was added to this release more than 14 days after its initial publication. Inspect the release files before installing.
magicfile (A CFFI fork of python-magic)
magicfile is a python interface to the libmagic file type
identification library. libmagic identifies file types by checking
their headers according to a predefined list of file types. This
functionality is exposed to the command line by the Unix command
file.
Usage
>>> import magicfile as magic
>>> magic.from_file("testdata/test.pdf")
'PDF document, version 1.2'
>>> magic.from_buffer(open("testdata/test.pdf").read(1024))
'PDF document, version 1.2'
>>> magic.from_file("testdata/test.pdf", mime=True)
'application/pdf'
There is also a Magic class that provides more direct control,
including overriding the magic database file and turning on character
encoding detection. This is not recommended for general use. In
particular, it's not safe for sharing across multiple threads and
will fail throw if this is attempted.
>>> f = magic.Magic(uncompress=True)
>>> f.from_file('testdata/test.gz')
'ASCII text (gzip compressed data, was "test", last modified: Sat Jun 28
21:32:52 2008, from Unix)'
You can also combine the flag options:
>>> f = magic.Magic(mime=True, uncompress=True)
>>> f.from_file('testdata/test.gz')
'text/plain'
Versioning
Minor version bumps should be backwards compatible. Major bumps are not.
Name Conflict
There are, sadly, two libraries which use the module name magic. Both have been around for quite a while.If you are using this module and get an error using a method like open, your code is expecting the other one. Hopefully one day these will be reconciled.
Installation
The current stable version of magicfile is available on pypi and
can be installed by running pip install magicfile.
Other sources:
Troubleshooting
-
'MagicException: could not find any magic files!': some installations of libmagic do not correctly point to their magic database file. Try specifying the path to the file explicitly in the constructor:
magic.Magic(magic_file="path_to_magic_file"). -
'WindowsError: [Error 193] %1 is not a valid Win32 application': Attempting to run the 32-bit libmagic DLL in a 64-bit build of python will fail with this error. Here are 64-bit builds of libmagic for windows: https://github.com/pidydx/libmagicwin64
-
'WindowsError: exception: access violation writing 0x00000000 ' This may indicate you are mixing Windows Python and Cygwin Python. Make sure your libmagic and python builds are consistent.
Author
Written by Adam Hupp in 2001 for a project that never got off the ground. It originally used SWIG for the C library bindings, but switched to ctypes once that was part of the python standard library.
You can contact me via my website or github.
Contributors
Thanks to these folks on github who submitted features and bugfixes.
- Amit Sethi
- bigben87
- fallgesetz
- FlaPer87
- lukenowak
- NicolasDelaby
- sacha@ssl.co.uk
- SimpleSeb
- tehmaze
License
magicfile is distributed under the MIT license. See the included LICENSE file for details.
Release files for magicfile 0.4.27
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
File added late
1 file was uploaded more than 14 days after the first file in this release.
While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.
We recommend inspecting the release files before installing.
Built distributions (wheels)
Total release size: 5.0 MB
Release files / magicfile-0.4.27-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
| Download URL | magicfile-0.4.27-cp310-cp310-manylinux_2_12_x86_64.manylinux2010_x86_64.whl |
|---|---|
| Size | 616.2 kB |
| Tags | CPython 3.10 Linux glibc 2.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
dbd07816497dbb769b81a2dc0bb9a5addec13c803d90e34d1bb00d801d60dd95
|
|
BLAKE2b-256 checksum How to use checksums |
7c7051950831fdc2a73471c1087243b4e4c99f1c6e59e9c42a52cb78a64817c0
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12
|
Release files / magicfile-0.4.27-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
| Download URL | magicfile-0.4.27-cp39-cp39-manylinux_2_12_x86_64.manylinux2010_x86_64.whl |
|---|---|
| Size | 616.3 kB |
| Tags | CPython 3.9 Linux glibc 2.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
32a4dda8f947ede2d0f228671e7d5c21339f8ef1998d25d82d0640145108810f
|
|
BLAKE2b-256 checksum How to use checksums |
380b6d1509be3a8eb5d4d7af5db0ed63a0721aac4cd780c78900b57ecf9cafef
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12
|
Release files / magicfile-0.4.27-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
| Download URL | magicfile-0.4.27-cp38-cp38-manylinux_2_12_x86_64.manylinux2010_x86_64.whl |
|---|---|
| Size | 616.7 kB |
| Tags | CPython 3.8 Linux glibc 2.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
2bf4fabb2a166648cd2704a312e5573e4f50ade54bbb2c052894795c23171dcf
|
|
BLAKE2b-256 checksum How to use checksums |
9c0baddb1b137cb65cae0596bf62ab09638962079b6ef31a1802f4a7915a4b07
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12
|
Release files / magicfile-0.4.27-cp38-cp38-macosx_12_0_arm64.whl
File added late
This file was uploaded more than 14 days after the first file in this release.
While project maintainers occasionally add legitimate files to an existing release, late additions can also indicate a security compromise.
We recommend inspecting the release file before installing.
| Download URL | magicfile-0.4.27-cp38-cp38-macosx_12_0_arm64.whl |
|---|---|
| Size | 474.9 kB |
| Tags | CPython 3.8 macOS 12.0+ ARM64 |
|
SHA-256 checksum How to use checksums |
ef66e7ee687988ee830a95259c5a62cae48ff39694c421182de0e7e6b69eec4c
|
|
BLAKE2b-256 checksum How to use checksums |
4bf6a77034c051c6f689185dc42051377216bb72ceeeb137544807f2af7d6c46
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/4.0.1 CPython/3.10.4
|
Release files / magicfile-0.4.27-cp38-cp38-macosx_10_14_x86_64.whl
| Download URL | magicfile-0.4.27-cp38-cp38-macosx_10_14_x86_64.whl |
|---|---|
| Size | 479.1 kB |
| Tags | CPython 3.8 macOS 10.14+ x86-64 |
|
SHA-256 checksum How to use checksums |
99d94205ce66631f1fe1117b56b3a3734f4be20e3938fc5d2694e21d9d40c166
|
|
BLAKE2b-256 checksum How to use checksums |
eecef07c313bf80b747238b9c3b61b68210ba7a7f2ac2fc4f48466c91ce1cd2f
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12
|
Release files / magicfile-0.4.27-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
| Download URL | magicfile-0.4.27-cp37-cp37m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl |
|---|---|
| Size | 616.2 kB |
| Tags | CPython 3.7 CPython 3.7 pymalloc Linux glibc 2.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
b7531c947cb487ccd80a116c5427e762744b6daf062454294e4c9224b44691cd
|
|
BLAKE2b-256 checksum How to use checksums |
8e3a732f7518aa8d29635580635965391e549b60b5db34325d60732d026343bf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12
|
Release files / magicfile-0.4.27-cp37-cp37m-macosx_10_14_x86_64.whl
| Download URL | magicfile-0.4.27-cp37-cp37m-macosx_10_14_x86_64.whl |
|---|---|
| Size | 479.1 kB |
| Tags | CPython 3.7 CPython 3.7 pymalloc macOS 10.14+ x86-64 |
|
SHA-256 checksum How to use checksums |
3d55827f0f51a6fb25384b7066ad7588609155c85816f3d4bbeca2349b328c00
|
|
BLAKE2b-256 checksum How to use checksums |
09b37e09b70723f35fbabd2ba83fff97483780af146e97b60139a3b13bb5d9f2
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.7.12
|
Release files / magicfile-0.4.27-cp36-cp36m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl
| Download URL | magicfile-0.4.27-cp36-cp36m-manylinux_2_12_x86_64.manylinux2010_x86_64.whl |
|---|---|
| Size | 616.2 kB |
| Tags | CPython 3.6 CPython 3.6 pymalloc Linux glibc 2.12+ x86-64 |
|
SHA-256 checksum How to use checksums |
578d577c5730aa000edbd03691f0f3d31a679cd2d1bf6faa87e472baec8a7e08
|
|
BLAKE2b-256 checksum How to use checksums |
1b788469be2ceeac967cfbb34edef8bb5c6149238982895f9b77ba60fce9b038
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.8.12
|
Release files / magicfile-0.4.27-cp36-cp36m-macosx_10_14_x86_64.whl
| Download URL | magicfile-0.4.27-cp36-cp36m-macosx_10_14_x86_64.whl |
|---|---|
| Size | 479.1 kB |
| Tags | CPython 3.6 CPython 3.6 pymalloc macOS 10.14+ x86-64 |
|
SHA-256 checksum How to use checksums |
c119b660baeb91e167c7cfd54cf3dedebcc14cfa8ed57fdcff074beef2388935
|
|
BLAKE2b-256 checksum How to use checksums |
d1268ef1792c1e46235c966d4b72c1f552533b976e96480e6b5e3053d11f06b5
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/3.6.0 importlib_metadata/4.8.2 pkginfo/1.7.1 requests/2.26.0 requests-toolbelt/0.9.1 tqdm/4.62.3 CPython/3.6.15
|