A pydantic type for media types
  • Python 92.4%
  • Dockerfile 7.6%
Find a file
2026-07-06 09:24:18 +02:00
.github Use ty instead of mypy (#55) 2026-02-11 17:24:02 +01:00
src/pydantic_media_type Task/replace isort black with ruff (#45) 2025-09-24 13:42:26 +02:00
tests Add MediaType type 2024-10-08 13:26:37 +02:00
.gitignore Project skeleton 2024-10-07 15:47:39 +02:00
docker-compose.cache.json Project skeleton 2024-10-07 15:47:39 +02:00
docker-compose.yml Use uv instead of poetry (#44) 2025-09-24 11:18:29 +02:00
Dockerfile Task/update dependencies (#54) 2026-02-11 10:47:59 +01:00
LICENSE Add license (#3) 2024-10-08 16:00:28 +02:00
pyproject.toml Update uv-build requirement from <0.11.0,>=0.8.19 to >=0.8.19,<0.12.0 (#57) 2026-03-31 14:15:14 +02:00
README.md Use ty instead of mypy (#55) 2026-02-11 17:24:02 +01:00
uv.lock update dependencies (#61) 2026-07-06 09:24:18 +02:00

Pydantic Media Type

This package provides a Pydantic type that can be used to validate media types. It uses the media types from the mimetypes module of The Python Standard Library.

Installation

Install using uv:

uv add pydantic-media-type

or using pip:

pip install pydantic-media-type

Example

from pydantic import BaseModel

from pydantic_media_type import MediaType


class Model(BaseModel):
    media_type: MediaType

print(Model(media_type=MediaType("image/png")).media_type)  # Will print: image/png
Model(media_type=MediaType("invalid"))  # Will raise pydantic.ValidationError with code media_type_unsupported

Development

Getting the project up and running can be achieved without much effort using Docker Compose. Doing so ensures that there should be very little difference in environment between all of us devs.

Starting the project

docker compose build
docker compose run --rm pydantic-media-type sh

The last command gives you a shell within the container.

Dependency management

We shouldn't have any other dependencies other than python and pydantic.

However, we do have some dev dependencies like:

  • ruff
  • mypy
  • pytest

We will do our best to keep those up to date. Should you want to upgrade them yourself, please do it from the shell inside the container using:

uv sync --upgrade

Similarly, installing new dependencies is possible using the command:

uv add name-of-the-dependency-to-install

Dev tools

This project uses ruff, ty and pytest. The preferred way to run them is by using the container, for example:

docker compose build
docker compose run --rm pydantic-media-type sh
uv run ruff check
uv run ty check
uv run pytest -v