Skip to main content

Better MIME types in Python.

Project description

mimelib 🙊

Build Status Coverage Status Maintainability

A MIME type is a label used to identify a type of data. It is used so software can know how to handle the data. It serves the same purpose on the Internet that file extensions do on Microsoft Windows. — Quentin

mimelib aims at working with MIME types easier in Python. The standard library comes with the mimetypes module. This library builds on top of it and adds more niceties to it, so you're generally happier when working with MIME types today.

>>> import mimelib
>>> mimelib.mimetype('application/json').is_text
>>> mimelib.url('').is_image
>>> mimelib.url('pianoman.mp3').file_type


To install mimelib, use pipenv (or pip):

$ pipenv install mimelib


mimelib is intended to be used alongside the mimetypes standard library module, and builds on top of it under the hood. So, if you are adding additional MIME types to be recognized, mimelib will work just as fine.


Either a valid MIME type string, or a URL or path can be used to work with mimelib.

>>> m1 = mimelib.mimetype("application/json")  # pass a valid MIME type
>>> m2 = mimelib.url("foo/bar/dataset.csv")  # or pass a path / url

Both these methods return a MIME object, the various useful properties of which are listed below.

Getting the file type

The following file types are reported: text, image, media and binary.

>>> mimelib.mimetype("application/ecmascript").file_type
>>> mimelib.mimetype("video/mpeg").file_type
>>> mimelib.url("archive.rar").file_type

The Mime object also has the following properties for conveniently checking specific file types:

  • is_text
  • is_image
  • is_media
  • is_binary

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

mimelib-0.1.1.tar.gz (5.4 kB view hashes)

Uploaded source

Built Distribution

mimelib-0.1.1-py2.py3-none-any.whl (4.6 kB view hashes)

Uploaded py2 py3

Supported by

AWS AWS Cloud computing Datadog Datadog Monitoring Facebook / Instagram Facebook / Instagram PSF Sponsor Fastly Fastly CDN Google Google Object Storage and Download Analytics Huawei Huawei PSF Sponsor Microsoft Microsoft PSF Sponsor NVIDIA NVIDIA PSF Sponsor Pingdom Pingdom Monitoring Salesforce Salesforce PSF Sponsor Sentry Sentry Error logging StatusPage StatusPage Status page