Skip to main content

Command line

Sometimes the question is not in your code at all. You are staring at a bucket listing, or a log line, or a colleague’s message, and you want to know what report.parq is going to be served as without opening a REPL. The package ships a small console script for exactly that moment.

Install

Install it as a tool so it is on your path everywhere.

uv tool install content-types
# or
pipx install content-types

Inside a project that already depends on the package the script is on the virtualenv’s path, so uv run content-types ... works there without a separate install.

Use

One argument in, one line out.

content-types example.jpg
# image/jpeg

content-types .webp
# image/webp

content-types data.parquet
# application/vnd.apache.parquet

The argument goes straight through get_content_type() with its defaults, so the tool inherits the library’s manners: case does not matter, a bare extension works with or without the dot, and an unknown extension prints application/octet-stream and exits 0. It does the forward lookup only. For the reverse direction, open Python.

Flags and exit codes

The script is deliberately tiny, so this table is the whole contract.

Invocation Output Exit code
content-types NAME the content type, or application/octet-stream for an unknown extension 0
content-types usage text on stdout 1
content-types -h or --help usage text 0
content-types --version the installed package version 0

Extra arguments after the first are ignored. There are no environment variables and no configuration file to discover. Under the hood the script is the function content_types.cli() wired up in pyproject.toml, which means you can call it yourself if you ever want the same behaviour from inside another tool.