Registry / serialization / mediatype

mediatype

JSON →
library0.1.6pypypi✓ verified 84d ago

A Python library for parsing, validating, and creating media types (MIME types) per RFC 7231. Current version 0.1.6, with monthly releases. Actively maintained.

pip install mediatype
INSTALL
IMPORT
SIG · MEDIATYPE
M
mediatype
serializationpythonv0.1.6
Install
1.7s avg
Import
325ms
Disk
16MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.1.6 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.95 runs
installs and imports cleanly · install 0.0s · import 0.336s · 18.3MB
glibc
py 3.103.95 runs
installs and imports cleanly · install 1.7s · import 0.314s · 19MB
16MB installed
● package 16MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

MediaType
from mediatype import MediaType

Parse and create media type objects.

from mediatype import MediaType # Parse a media type string media = MediaType('application/json; charset=utf-8') print(media.type) # application print(media.subtype) # json print(media.suffix) # None print(media.parameters) # {'charset': 'utf-8'} # Create a media type media2 = MediaType('application', 'json', parameters={'charset': 'utf-8'}) print(str(media2)) # application/json; charset=utf-8
Debug
Known issues
gotchaMediaType does not validate parameters keys/values beyond basic syntax. Invalid parameters may be silently accepted.
fix
Manually validate parameter values if strict compliance required.
affects: >=0.1.0
gotchaSubtype suffix (e.g., +json) is stored separately; comparisons ignore suffix unless explicitly checked.
fix
Compare using .type and .subtype and .suffix separately or convert to string.
affects: >=0.1.0
Errors
Common errors & fixes
AttributeError: module 'mediatype' has no attribute 'MediaType'
Importing the module instead of the class.
fix
Use: from mediatype import MediaType
ValueError: invalid media type: 'text'
String lacks a '/' separator.
fix
Provide a valid media type string with a slash, e.g., 'text/plain'.
Upgrade
Version history
0.1.6latest on PyPI · released Apr 12, 2022
Audit
Dependencies

No dependency data recorded yet.

Agent activity
1 hits · last 30 days
Meta
1
Resources
mediatype — pip install mediatype · libregistry