mime-enum


Namemime-enum JSON
Version 0.0.1 PyPI version JSON
download
home_pageNone
SummaryType-safe MIME type enumeration for Python
upload_time2025-09-05 11:33:12
maintainerNone
docs_urlNone
authorNone
requires_python<4.0,>=3.11
licenseNone
keywords content-type enum file-extension mime mime-type
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # mime-enum

[![Release](https://img.shields.io/github/v/release/fpgmaas/mime-enum)](https://img.shields.io/github/v/release/fpgmaas/mime-enum)
[![Build status](https://img.shields.io/github/actions/workflow/status/fpgmaas/mime-enum/main.yml?branch=main)](https://github.com/fpgmaas/mime-enum/actions/workflows/main.yml?query=branch%3Amain)
[![codecov](https://codecov.io/gh/fpgmaas/mime-enum/branch/main/graph/badge.svg)](https://codecov.io/gh/fpgmaas/mime-enum)
[![License](https://img.shields.io/github/license/fpgmaas/mime-enum)](https://img.shields.io/github/license/fpgmaas/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:

```bash
pip install mime-enum
```

Or using uv:

```bash
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:

```python
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:

```python
# 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:

```python
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:

```python
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](docs/usage.md).

For complete API documentation, see the [API Reference](docs/api.md).

## Acknowledgments

This project uses the `mimeData.json` file from [mimetype-io](https://github.com/patrickmccallum/mimetype-io) by Patrick McCallum.

            

Raw data

            {
    "_id": null,
    "home_page": null,
    "name": "mime-enum",
    "maintainer": null,
    "docs_url": null,
    "requires_python": "<4.0,>=3.11",
    "maintainer_email": null,
    "keywords": "content-type, enum, file-extension, mime, mime-type",
    "author": null,
    "author_email": "Florian Maas <fpgmaas@gmail.com>",
    "download_url": "https://files.pythonhosted.org/packages/0b/0c/5490c92f5e0f1d44ca87b0b241b6758b710ae6efccb58ef3ba073a39fdbb/mime_enum-0.0.1.tar.gz",
    "platform": null,
    "description": "# mime-enum\n\n[![Release](https://img.shields.io/github/v/release/fpgmaas/mime-enum)](https://img.shields.io/github/v/release/fpgmaas/mime-enum)\n[![Build status](https://img.shields.io/github/actions/workflow/status/fpgmaas/mime-enum/main.yml?branch=main)](https://github.com/fpgmaas/mime-enum/actions/workflows/main.yml?query=branch%3Amain)\n[![codecov](https://codecov.io/gh/fpgmaas/mime-enum/branch/main/graph/badge.svg)](https://codecov.io/gh/fpgmaas/mime-enum)\n[![License](https://img.shields.io/github/license/fpgmaas/mime-enum)](https://img.shields.io/github/license/fpgmaas/mime-enum)\n\n**A type-safe Python library for working with MIME types and file extensions.**\n\nThe `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.\n\n\n## Installation\n\nInstall using pip:\n\n```bash\npip install mime-enum\n```\n\nOr using uv:\n\n```bash\nuv add mime-enum\n```\n\n## Quick Start\n\nThe `mime-enum` library provides three key capabilities: type-safe MIME type access, flexible string parsing, and file extension lookups.\n\n### Type-Safe MIME Types\n\nAccess MIME types as strongly-typed enum values with full IDE support:\n\n```python\nfrom mime_enum import MimeType\n\n# Enum values work as strings with autocompletion and type checking\njson_mime = MimeType.APPLICATION_JSON\nprint(json_mime)  # \"application/json\"\nprint(json_mime.extensions)  # (\"json\",)\n\n```\n\n### Convenient Aliases\n\nFor commonly used MIME types with verbose names, convenient aliases are provided:\n\n```python\n# Microsoft Office formats - use short aliases instead of verbose names\ndocx = MimeType.APPLICATION_DOCX  # vs APPLICATION_VND_OPENXMLFORMATS_OFFICEDOCUMENT_WORDPROCESSINGML_DOCUMENT\nxlsx = MimeType.APPLICATION_XLSX  # vs APPLICATION_VND_OPENXMLFORMATS_OFFICEDOCUMENT_SPREADSHEETML_SHEET\npptx = MimeType.APPLICATION_PPTX  # vs APPLICATION_VND_OPENXMLFORMATS_OFFICEDOCUMENT_PRESENTATIONML_PRESENTATION\n\n# String representation shows the full MIME type\nprint(docx)  # \"application/vnd.openxmlformats-officedocument.wordprocessingml.document\"\nprint(xlsx)  # \"application/vnd.openxmlformats-officedocument.spreadsheetml.sheet\"\nprint(pptx)  # \"application/vnd.openxmlformats-officedocument.presentationml.presentation\"\n\n# All aliases point to the same enum instances\nassert MimeType.APPLICATION_DOCX is MimeType.APPLICATION_VND_OPENXMLFORMATS_OFFICEDOCUMENT_WORDPROCESSINGML_DOCUMENT\n\n# Available aliases: DOCX, XLSX, PPTX, DOTX, XLTX, POTX, PPSX, SLDX\n```\n\n### Flexible String Parsing\n\nParse real-world MIME type strings with automatic parameter stripping and alias normalization:\n\n```python\nfrom mime_enum import parse, try_parse\n\n# Strips parameters automatically\nmime_type = parse(\"application/json; charset=utf-8\")\nprint(mime_type)  # MimeType.APPLICATION_JSON\n\n# Normalizes common aliases to canonical forms\ncanonical = parse(\"text/json\")  # \u2192 MimeType.APPLICATION_JSON\ncanonical = parse(\"application/javascript\")  # \u2192 MimeType.TEXT_JAVASCRIPT\n\n# Safe parsing returns None instead of raising exceptions\nunknown = try_parse(\"application/unknown\")\nprint(unknown)  # None\n```\n\n### File Extension Lookups\n\nDetect MIME types from file extensions and paths:\n\n```python\nfrom mime_enum import from_extension, from_path\n\n# Look up by extension (with or without dot, case-insensitive)\npdf_mime = from_extension(\".pdf\")  # MimeType.APPLICATION_PDF\njson_mime = from_extension(\"JSON\")  # MimeType.APPLICATION_JSON\n\n# Detect from complete file paths\nmime_type = from_path(\"/path/to/document.pdf\")  # MimeType.APPLICATION_PDF\n```\n\n> **Note:** These functions only examine file extensions, not actual file content. For content-based detection, consider `python-magic` or `filetype` packages.\n\nFor detailed usage examples, see the [Usage Guide](docs/usage.md).\n\nFor complete API documentation, see the [API Reference](docs/api.md).\n\n## Acknowledgments\n\nThis project uses the `mimeData.json` file from [mimetype-io](https://github.com/patrickmccallum/mimetype-io) by Patrick McCallum.\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "Type-safe MIME type enumeration for Python",
    "version": "0.0.1",
    "project_urls": {
        "Documentation": "https://fpgmaas.github.io/mime-enum/",
        "Homepage": "https://github.com/fpgmaas/mime-enum",
        "Repository": "https://github.com/fpgmaas/mime-enum"
    },
    "split_keywords": [
        "content-type",
        " enum",
        " file-extension",
        " mime",
        " mime-type"
    ],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "dd0f9bd918a0cbc5ddaff7e9e9c5a44b771e7a31c8c07e75be6bb85ced4ae4c5",
                "md5": "2b3166d5eeb5e9b675b86a904371f4a7",
                "sha256": "f5d05bb9a300d6375974bd40051baab4fd0e7460e19d11f51a24c45cabe4df06"
            },
            "downloads": -1,
            "filename": "mime_enum-0.0.1-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "2b3166d5eeb5e9b675b86a904371f4a7",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": "<4.0,>=3.11",
            "size": 30065,
            "upload_time": "2025-09-05T11:33:11",
            "upload_time_iso_8601": "2025-09-05T11:33:11.702677Z",
            "url": "https://files.pythonhosted.org/packages/dd/0f/9bd918a0cbc5ddaff7e9e9c5a44b771e7a31c8c07e75be6bb85ced4ae4c5/mime_enum-0.0.1-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "0b0c5490c92f5e0f1d44ca87b0b241b6758b710ae6efccb58ef3ba073a39fdbb",
                "md5": "1a712a662d425df5bbf2f5fb1185f9ab",
                "sha256": "daf9fda3fb2c116d01091d39793ef4fe1ffef04ec58b46f791460c9ceb9685bf"
            },
            "downloads": -1,
            "filename": "mime_enum-0.0.1.tar.gz",
            "has_sig": false,
            "md5_digest": "1a712a662d425df5bbf2f5fb1185f9ab",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": "<4.0,>=3.11",
            "size": 137201,
            "upload_time": "2025-09-05T11:33:12",
            "upload_time_iso_8601": "2025-09-05T11:33:12.647442Z",
            "url": "https://files.pythonhosted.org/packages/0b/0c/5490c92f5e0f1d44ca87b0b241b6758b710ae6efccb58ef3ba073a39fdbb/mime_enum-0.0.1.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-09-05 11:33:12",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "fpgmaas",
    "github_project": "mime-enum",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "tox": true,
    "lcname": "mime-enum"
}
        
Elapsed time: 2.54580s