58 lines
1.3 KiB
Plaintext
58 lines
1.3 KiB
Plaintext
= python-magic =
|
|
|
|
Adam Hupp <adam at hupp.org>
|
|
|
|
Distributed under the PSF License: http://www.python.org/psf/license/
|
|
|
|
python-magic is a simple wrapper for libmagic. libmagic identifies
|
|
file types according to their headers. It is the core of the Unix
|
|
"file" command.
|
|
|
|
= Installation =
|
|
|
|
To build and install run:
|
|
|
|
# python setup.py install
|
|
|
|
= Installation on Win32 =
|
|
|
|
You need magic1.dll from http://gnuwin32.sourceforge.net/, grab the
|
|
binaries and dependencies ZIP-file, extract magic1.dll, regex2.dll
|
|
and zlib1.dll and put it in C:\Windows\System32. You also need a
|
|
magic file from Linux, compatible with file version 5.0.
|
|
|
|
To build and install run:
|
|
|
|
# python setup.py install
|
|
|
|
= Example Usage =
|
|
|
|
>>> import magic
|
|
>>> m = magic.Magic()
|
|
>>> m.from_file("testdata/test.pdf")
|
|
'PDF document, version 1.2'
|
|
>>> m.from_buffer(open("testdata/test.pdf").read(1024))
|
|
'PDF document, version 1.2'
|
|
|
|
# For MIME types
|
|
>>> mime = magic.Magic(mime=True)
|
|
>>> mime.from_file("testdata/test.pdf")
|
|
'application/pdf'
|
|
>>>
|
|
|
|
# For MIME encoding
|
|
>>> mime_encoding = magic.Magic(mime_encoding=True)
|
|
>>> mime_encoding.from_file("testdata/text-iso8859-1.txt")
|
|
'iso-8859-1'
|
|
>>>
|
|
|
|
= Contributors =
|
|
|
|
Thanks to these folks on github who submitted features and bugfixes.
|
|
|
|
NicolasDelaby
|
|
lukenowak
|
|
FlaPer87
|
|
SimpleSeb
|
|
tehmaze
|