Skip to main content

mimeatlas

Lianes8 Certified

Deterministic, OS-independent file extension and MIME type mapping generated from mime-db, zero dependencies.

Install

pip install mimeatlas

Usage

import mimeatlas

mimeatlas.guess_type("report.pdf")  # "application/pdf"
mimeatlas.guess_type("PHOTO.JPG")  # "image/jpeg"
mimeatlas.guess_type("backup.tar.gz")  # "application/gzip"
mimeatlas.guess_type("Makefile")  # None

mimeatlas.guess_extension("image/png")  # ".png"
mimeatlas.guess_extension("text/html; charset=utf-8")  # ".html"
mimeatlas.extensions_for("image/jpeg")  # (".jpg", ".jpeg", ".jpe")

mimeatlas.guess("site.tar.gz")
# Guess(type='application/x-tar', encoding='gzip', extension='tar')
mimeatlas.content_type_for("index.html")  # "text/html; charset=utf-8"
mimeatlas.media_type_info("application/ld+json")
# MediaTypeInfo(type='application/ld+json', source='iana', extensions=('.jsonld',),
#               charset=None, compressible=True, suffix='json')

mimeatlas.structured_suffix("image/svg+xml")  # "xml"
mimeatlas.essence("Text/HTML; charset=UTF-8")  # "text/html"
mimeatlas.sniff(b"%PDF-1.7 ...")  # "application/pdf"

# Your own mappings, without touching global state.
table = mimeatlas.default_table().with_types({"text/x-typescript": ["ts", "d.ts"]})
table.guess_type("index.d.ts")  # "text/x-typescript"

Lookups are case insensitive and ignore parameters on a MIME type. Unknown or malformed lookup strings give None, an empty extension tuple, or False for is_textual(). Valid unregistered MIME types can still have inferred results: default_charset() gives utf-8 for text/*; is_textual() recognizes text/* and +json, +xml, +yaml, +json-seq; structured_suffix() extracts any suffix. guess() always returns a Guess: unknown type and extension fields are None, while a recognized trailing content coding can still set its encoding. essence() raises InvalidMediaType (a ValueError) on malformed values, MimeTable.with_types() raises ValueError on bad overrides and sniff() raises TypeError for text.

Command line

mimeatlas type report.pdf               # application/pdf
mimeatlas type site.tar.gz --encoding   # application/x-tar<TAB>gzip
mimeatlas ext image/jpeg                # .jpg .jpeg .jpe
mimeatlas info application/json
mimeatlas sniff download.bin
mimeatlas source

Where the data comes from

The table is generated by a committed script from a pinned, separately fetched snapshot of jshttp mime-db 1.54.0 (MIT), which merges the IANA Media Types registry, Apache httpd and nginx. Extension conflicts are resolved with the jshttp mime-types 3.0.2 scoring. A short, labelled, hand-written supplement keeps a few extensions mime-db does not list; it moves three answers away from mime-types (.flac to audio/flac, .yaml and .yml to application/yaml), and every other extension matches mime-types 3.0.2. Call mimeatlas.data_source() for the version, URL, checksum and license. The GUIDE has the full policy and the measured differences from the standard library.

Why

The standard library mimetypes reads the host's files and, on Windows, the registry, so the same call can return different answers on different machines; even mimetypes.init(files=[]) still reads them. Its built-in table also changes between Python versions. A mimetypes.MimeTypes(filenames=()) instance uses the standard library's built-in table, which is a good choice when that coverage and Python-version-dependent behavior suit you. mimeatlas ships a fixed table of 2,524 types and 1,245 extensions and supports immutable local overrides. Its narrow sniff() function recognizes signatures only; it does not validate file contents or implement the complete browser sniffing algorithm.

See the GUIDE for contracts and the CHANGELOG for version changes.

Development

Install .[dev], then run python scripts/fetch_upstream.py to obtain the pinned sources. Set MIMEATLAS_DATA_DIR to keep them outside the checkout. With Node.js installed, tests also run the pinned mime-types reference from its verified archives. scripts/check.ps1 checks formatting, lint, strict types and tests. Tests use a 300-second limit per test; use pytest --basetemp PATH to choose their working folder.

License

MIT. See LICENSE. The embedded data is derived from mime-db and the conflict scoring from mime-types, both MIT; their notices are in LICENSES and ship inside the wheel.

Metadata

Release files for mimeatlas 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for mimeatlas 1.0.0
File Size Uploaded Provenance Actions
mimeatlas-1.0.0.tar.gz 88.5 kB Without provenance Details for mimeatlas-1.0.0.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for mimeatlas 1.0.0
File Interpreter ABI Platform Actions
mimeatlas-1.0.0-py3-none-any.whl Python 3 none any Details for mimeatlas-1.0.0-py3-none-any.whl

Total release size: 143.6 kB

Release files / mimeatlas-1.0.0.tar.gz

Download URL mimeatlas-1.0.0.tar.gz
Size 88.5 kB
Tags Source
SHA-256 checksum
How to use checksums
795c568f1dc6aa72d2e6b8bae69a8ce580b9b3ac0a802531079adde73f1966b8
BLAKE2b-256 checksum
How to use checksums
29178f19534d9890c207e50153eb84d9e29c3ed85e906f609166d07c8abcab40
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.2

Release files / mimeatlas-1.0.0-py3-none-any.whl

Download URL mimeatlas-1.0.0-py3-none-any.whl
Size 55.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
dfc006ee1beef51e323c30568390d760b1c7734ed68349b81eadddd1071dd29f
BLAKE2b-256 checksum
How to use checksums
d526e889c8989e858f672e8970a719a3d68fe52998576bae2909274366684187
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.13.2

Security for mimeatlas 1.0.0

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.

Release history Release notifications | RSS feed

This release

1.0.0 This release

2 release files No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page