Metadata-Version: 2.5
Name: mimeatlas
Version: 1.0.0
Summary: Deterministic, OS-independent file extension and MIME type mapping generated from mime-db, zero dependencies
Project-URL: Homepage, https://lianes8studio.com
Project-URL: Source, https://github.com/JaviLianes8/mimeatlas
Project-URL: Issues, https://github.com/JaviLianes8/mimeatlas/issues
Project-URL: Changelog, https://github.com/JaviLianes8/mimeatlas/blob/main/CHANGELOG.md
Project-URL: LinkedIn, https://www.linkedin.com/in/jlianes/
Project-URL: Funding, https://buymeacoffee.com/jlianesglrs
Author-email: Javier Lianes <javier@lianes8studio.com>
License-Expression: MIT
License-File: LICENSE
License-File: LICENSES/mime-db.txt
License-File: LICENSES/mime-types.txt
Keywords: content-type,file-extension,media-type,mime,mime-db,mimetypes
Classifier: Development Status :: 5 - Production/Stable
Classifier: Environment :: Console
Classifier: Intended Audience :: Developers
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Typing :: Typed
Requires-Python: >=3.10
Provides-Extra: dev
Requires-Dist: build; extra == 'dev'
Requires-Dist: mypy; extra == 'dev'
Requires-Dist: pytest; extra == 'dev'
Requires-Dist: pytest-timeout; extra == 'dev'
Requires-Dist: ruff; extra == 'dev'
Requires-Dist: tomli; (python_version < '3.11') and extra == 'dev'
Requires-Dist: twine; extra == 'dev'
Description-Content-Type: text/markdown

# mimeatlas

[![Lianes8 Certified](https://lianes8studio.com/certified/lianes8-certified-badge.svg)](https://lianes8studio.com/certified)

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

## Install

```
pip install mimeatlas
```

## Usage

```python
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](https://github.com/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](https://github.com/JaviLianes8/mimeatlas/blob/main/GUIDE.md) 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](https://github.com/JaviLianes8/mimeatlas/blob/main/GUIDE.md)
for contracts and the [CHANGELOG](https://github.com/JaviLianes8/mimeatlas/blob/main/CHANGELOG.md)
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](https://github.com/JaviLianes8/mimeatlas/blob/main/LICENSE). The embedded data is derived from mime-db and the
conflict scoring from mime-types, both MIT; their notices are in
[LICENSES](https://github.com/JaviLianes8/mimeatlas/tree/main/LICENSES) and ship inside the wheel.

## Links

- Website: https://lianes8studio.com
- GitHub: https://github.com/JaviLianes8
- LinkedIn: https://www.linkedin.com/in/jlianes/
