/magic-rs

Python wrapper for Rust infer crate

Primary LanguagePythonMIT LicenseMIT

magic-rs

Package version Supported Python versions

Python wrapper for Rust infer crate


Installation

pip install magic-rs

Quickstart

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())

Benchmarks

For details, see benchmark.