Skip to main content

CFFI bindings for libmagic.

Project description

CFFI bindings for libmagic.

  • Free software: MIT License

Installation

pip install file

Usage

from file import Magic

with Magic() as magic:
    print(magic.buffer("hello")) # => "text/plain"

from file import magic_buffer, magic_file, magic_setflags

magic = Magic()
mimetype = magic_buffer("\x89\x50\x4E\x47\x0D\x0A\x1A\x0A")
print(mimetype) # => "image/png"

mimetype = magic_file("/etc/passwd")
print(mimetype) # => "text/plain"

from file import MAGIC_NONE
magic_setflags(MAGIC_NONE)
mimetype = magic_file("demo.docx")
print(mimetype) # => "Microsoft Word 2007+"
magic.close() # don't forget about this

Changelog

0.3.0 (2017-11-03)

  • Remove magic_version - not available in old libmagic.so.

  • Remove magic object - will break import if there’s a load failure.

0.2.1 (2017-11-02)

  • Release without wheels.

0.2.0 (2017-11-02)

  • First release on PyPI.

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

file-0.3.0.tar.gz (15.8 kB view details)

Uploaded Source

File details

Details for the file file-0.3.0.tar.gz.

File metadata

  • Download URL: file-0.3.0.tar.gz
  • Upload date:
  • Size: 15.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No

File hashes

Hashes for file-0.3.0.tar.gz
Algorithm Hash digest
SHA256 02735d18e92a13dd8335aee2373ffbe41444b2c42091d03b75dd2633121c46f4
MD5 0014b0761f33390788a810ae4ea06ca1
BLAKE2b-256 0a49317ac8ed10afb25c4c24972ea4de4c5507d6b0ab13bca4941c9a0bdc64ea

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page