Skip to main content

Type-safe MIME type enumeration for Python

Project description

mime-enum

Release Build status codecov License

A type-safe Python library for working with MIME types and file extensions.

The mime-enum package provides a comprehensive enumeration of MIME types with their associated file extensions. It offers a clean, type-safe API for parsing MIME type strings, looking up MIME types by file extension, and working with file paths.

Installation

Install using pip:

pip install mime-enum

Or using uv:

uv add mime-enum

Quick Start

The mime-enum library provides three key capabilities: type-safe MIME type access, flexible string parsing, and file extension lookups.

Type-Safe MIME Types

Access MIME types as strongly-typed enum values with full IDE support:

from mime_enum import MimeType

# Enum values work as strings with autocompletion and type checking
json_mime = MimeType.APPLICATION_JSON
print(json_mime)  # "application/json"
print(json_mime.extensions)  # ("json",)

Flexible String Parsing

Parse real-world MIME type strings with automatic parameter stripping and alias normalization:

from mime_enum import parse, try_parse

# Strips parameters automatically
mime_type = parse("application/json; charset=utf-8")
print(mime_type)  # MimeType.APPLICATION_JSON

# Normalizes common aliases to canonical forms
canonical = parse("text/json")  # → MimeType.APPLICATION_JSON
canonical = parse("application/javascript")  # → MimeType.TEXT_JAVASCRIPT

# Safe parsing returns None instead of raising exceptions
unknown = try_parse("application/unknown")
print(unknown)  # None

File Extension Lookups

Detect MIME types from file extensions and paths:

from mime_enum import from_extension, from_path

# Look up by extension (with or without dot, case-insensitive)
pdf_mime = from_extension(".pdf")  # MimeType.APPLICATION_PDF
json_mime = from_extension("JSON")  # MimeType.APPLICATION_JSON

# Detect from complete file paths
mime_type = from_path("/path/to/document.pdf")  # MimeType.APPLICATION_PDF

Note: These functions only examine file extensions, not actual file content. For content-based detection, consider python-magic or filetype packages.

For detailed usage examples, see the Usage Guide.

For complete API documentation, see the API Reference.

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

mime_enum-0.0.1a1.tar.gz (133.6 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

mime_enum-0.0.1a1-py3-none-any.whl (28.8 kB view details)

Uploaded Python 3

File details

Details for the file mime_enum-0.0.1a1.tar.gz.

File metadata

  • Download URL: mime_enum-0.0.1a1.tar.gz
  • Upload date:
  • Size: 133.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.14

File hashes

Hashes for mime_enum-0.0.1a1.tar.gz
Algorithm Hash digest
SHA256 4c634f7a658d1a8d486b8fa7849635a2847fd833cc801b122c0897ef2dc5bbbd
MD5 86f1941f68ea9bdd7a95ff6f21dc77bf
BLAKE2b-256 b6071cdcc49c80b4a341281b4569f9cfeceac39b7718dd53365b0205f476a054

See more details on using hashes here.

File details

Details for the file mime_enum-0.0.1a1-py3-none-any.whl.

File metadata

File hashes

Hashes for mime_enum-0.0.1a1-py3-none-any.whl
Algorithm Hash digest
SHA256 775f6f2680a8b9ec95a5e0891add7f2048c8c16a9c7a81135f00241a48dfeea1
MD5 969c582fc3509c020dcbdda6bbbf5e36
BLAKE2b-256 57fba0986850b623a79b19d5fb0e62ff820155d428ae7c3dfdf5a149470383d0

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page