mime-enum
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",)
Convenient Aliases
For commonly used MIME types with verbose names, convenient aliases are provided:
# Microsoft Office formats - use short aliases instead of verbose names
docx = MimeType.APPLICATION_DOCX # vs APPLICATION_VND_OPENXMLFORMATS_OFFICEDOCUMENT_WORDPROCESSINGML_DOCUMENT
xlsx = MimeType.APPLICATION_XLSX # vs APPLICATION_VND_OPENXMLFORMATS_OFFICEDOCUMENT_SPREADSHEETML_SHEET
pptx = MimeType.APPLICATION_PPTX # vs APPLICATION_VND_OPENXMLFORMATS_OFFICEDOCUMENT_PRESENTATIONML_PRESENTATION
# String representation shows the full MIME type
print(docx) # "application/vnd.openxmlformats-officedocument.wordprocessingml.document"
print(xlsx) # "application/vnd.openxmlformats-officedocument.spreadsheetml.sheet"
print(pptx) # "application/vnd.openxmlformats-officedocument.presentationml.presentation"
# All aliases point to the same enum instances
assert MimeType.APPLICATION_DOCX is MimeType.APPLICATION_VND_OPENXMLFORMATS_OFFICEDOCUMENT_WORDPROCESSINGML_DOCUMENT
# Available aliases: DOCX, XLSX, PPTX, DOTX, XLTX, POTX, PPSX, SLDX
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-magicorfiletypepackages.
For detailed usage examples, see the Usage Guide.
For complete API documentation, see the API Reference.
Acknowledgments
This project uses the mimeData.json file from mimetype-io by Patrick McCallum.
Metadata
Release files for mime-enum 0.0.4
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| mime_enum-0.0.4.tar.gz | 126.0 kB | Without provenance | Details for mime_enum-0.0.4.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| mime_enum-0.0.4-py3-none-any.whl | Python 3 | none | any | Details for mime_enum-0.0.4-py3-none-any.whl |
Total release size: 157.4 kB
Release files / mime_enum-0.0.4.tar.gz
| Download URL | mime_enum-0.0.4.tar.gz |
|---|---|
| Size | 126.0 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
407d4e99fba2cf7c73c51d78d98d61ee13d0e7f44ebc734a97966b05068823bf
|
|
BLAKE2b-256 checksum How to use checksums |
6d4670b6e9cafa6ae596f3a74c7a7fce92a1508d456710581d1796907d8b7286
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.14
|
Release files / mime_enum-0.0.4-py3-none-any.whl
| Download URL | mime_enum-0.0.4-py3-none-any.whl |
|---|---|
| Size | 31.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a7145388ea889f6fa6fd679e4c3ee7693c1eca32c71455b841a24292fe2f5c94
|
|
BLAKE2b-256 checksum How to use checksums |
a7210199156b2bfa1d132579323a9bfa8ee15ffc0ba1db34f31f6f00ae5ab42b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
uv/0.6.14
|
Security for mime-enum 0.0.4
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.