Skip to content

Latest commit

 

History

History
51 lines (34 loc) · 832 Bytes

README.md

File metadata and controls

51 lines (34 loc) · 832 Bytes

Fast MIME

Support Rails/Marcel style MIME for Python.

It uses Apache Tike's rule.

It's customizable.

Install

pip install fast-mime

Usage

Detect MIME

from fast_mime import MIME
with open("a.pdf", "rb") as fi:
    # detect an opened file
    mime = MIME(fi, name="a.pdf", declared_type="application/pdf", extension=".pdf")
    # all parameters are optional

# detect an unopenned file
mime = MIME("a.pdf", declared_type="application/pdf", extension=".pdf")

# detect without any hint
mime = MIME("a")

Customize MIME rules

from fast_mime import Mime

# define your own mime rule
MIME = Mime.from_xmls(your_rule_file_name)

Patch MIME

class MyMime(Mime):
    def _patch(self):
        super()._patch()
        ...