Python bindings to libmagic
Project description
# python-libmagic

# Usage
```python
import magic
with magic.Magic() as m:
print m.from_buffer("hello") # => "text/plain"
```
```python
import magic
import magic.flags
magic = magic.Magic()
mimetype = magic.from_buffer("\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
print mimetype # => "image/png"
mimetype = magic.from_file("/etc/passwd")
print mimetype # => "text/plain"
updated = magic.set_flags(magic.flags.MAGIC_NONE)
print updated # => True
mimetype = magic.from_file("demo.docx")
print mimetype # => "Microsoft Word 2007+"
magic.close() # don't forget about this
```
# Installation
`python-libmagic` works on CPython 2.7/3.3+ and PyPy.
```bash
$ apt-get install libmagic-dev
$ pip install python-libmagic
```
# License
Licensed under MIT license.

# Usage
```python
import magic
with magic.Magic() as m:
print m.from_buffer("hello") # => "text/plain"
```
```python
import magic
import magic.flags
magic = magic.Magic()
mimetype = magic.from_buffer("\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
print mimetype # => "image/png"
mimetype = magic.from_file("/etc/passwd")
print mimetype # => "text/plain"
updated = magic.set_flags(magic.flags.MAGIC_NONE)
print updated # => True
mimetype = magic.from_file("demo.docx")
print mimetype # => "Microsoft Word 2007+"
magic.close() # don't forget about this
```
# Installation
`python-libmagic` works on CPython 2.7/3.3+ and PyPy.
```bash
$ apt-get install libmagic-dev
$ pip install python-libmagic
```
# License
Licensed under MIT license.
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
python-libmagic-0.4.0.tar.gz
(3.6 kB
view details)
File details
Details for the file python-libmagic-0.4.0.tar.gz
.
File metadata
- Download URL: python-libmagic-0.4.0.tar.gz
- Upload date:
- Size: 3.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | fd42e14fca5f346e36b6a8e984f0798f02f38e5eb1b4868424b1480293baacb1 |
|
MD5 | 491ef10098ec1648e2caf5869f3b2a02 |
|
BLAKE2b-256 | 43793bf793efcf94e730bf324b726b3ae551f9438869bb8995600784bdb17693 |