Python wrapper for Rust infer crate
pip install magic-rs
from magic_rs import from_path, from_bytes
with open("testdata/sample.png", 'rb') as f:
data = f.read()
py_magic = from_bytes(data)
print(py_magic.extension())
print(py_magic.mime_type())
print(py_magic.is_image())
print(py_magic.is_app())
print(py_magic.is_archive())
print(py_magic.is_audio())
print(py_magic.is_book())
print(py_magic.is_document())
print(py_magic.is_font())
print(py_magic.is_video())
print(py_magic.is_text())
py_magic = from_path("testdata/sample.png")
print(py_magic.extension())
print(py_magic.mime_type())
print(py_magic.is_image())
For details, see benchmark.