Skip to main content

Overview

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.

Metadata

Release files for file 0.3.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for file 0.3.0
File Size Uploaded Provenance Actions
file-0.3.0.tar.gz 15.8 kB Without provenance Details for file-0.3.0.tar.gz

Release files / file-0.3.0.tar.gz

Download URL file-0.3.0.tar.gz
Size 15.8 kB
Tags Source
SHA-256 checksum
How to use checksums
02735d18e92a13dd8335aee2373ffbe41444b2c42091d03b75dd2633121c46f4
BLAKE2b-256 checksum
How to use checksums
0a49317ac8ed10afb25c4c24972ea4de4c5507d6b0ab13bca4941c9a0bdc64ea
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No

Security for file 0.3.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page