Skip to main content

content-types 🗃️🔎

A Python library to map file extensions to MIME types. It also provides a CLI for quick lookups right from your terminal. If no known mapping is found, the tool returns application/octet-stream.

Unlike other libraries, this one does not try to access the file or parse the bytes of the file or stream. It just looks at the extension which is valuable when you don't have access to the file directly. For example, you know the filename but it is stored in s3 and you don't want to download it just to fully inspect the file.

Installation

uv pip install content-types

Usage

import content_types

# Forward lookup: filename -> MIME type
the_type = content_types.get_content_type("example.jpg")
print(the_type)  # "image/jpeg"

# For very common files, you have shortcuts:
print(f'Content-Type for webp is {content_types.webp}.') 
# Content-Type for webp is image/webp.

CLI

To use the library as a CLI tool, just install it with uv or pipx.

uv tool install content-types

Now it will be available machine-wide.

content-types example.jpg

# Outputs image/jpeg

Contributing

Contributions are welcome! Check out the GitHub repo for more details on how to get involved.

Metadata

Release files for content-types 0.2.1

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

Source distribution (sdist)

Source distribution for content-types 0.2.1
File Size Uploaded Provenance Actions
content_types-0.2.1.tar.gz 6.9 kB Without provenance Details for content_types-0.2.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for content-types 0.2.1
File Interpreter ABI Platform Actions
content_types-0.2.1-py3-none-any.whl Python 3 none any Details for content_types-0.2.1-py3-none-any.whl

Total release size: 12.7 kB

Release files / content_types-0.2.1.tar.gz

Download URL content_types-0.2.1.tar.gz
Size 6.9 kB
Tags Source
SHA-256 checksum
How to use checksums
b5c26cac96e3c864249e6e6608d9aee2cc07a873412c14fab5885756ff4273f6
BLAKE2b-256 checksum
How to use checksums
5eb35e0604c8e6d5799b22078c24466a0fc86491726a7536feb1dd9a70686367
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.25

Release files / content_types-0.2.1-py3-none-any.whl

Download URL content_types-0.2.1-py3-none-any.whl
Size 5.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1beb8e816a2aaa79146648668c1a09864fd509c6823146b5736c6249a504ad16
BLAKE2b-256 checksum
How to use checksums
f4739ad0b2ac2caaf98f7bad87ba8ef89454c70b791bba920bc8010a5cadfe1c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via uv/0.5.25

Security for content-types 0.2.1

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.

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