Skip to main content

Pydantic model for MIME/Media types

Project description

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, mypy 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 mypy .
uv run pytest -v

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pydantic_media_type-0.1.0.tar.gz (2.2 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pydantic_media_type-0.1.0-py3-none-any.whl (3.0 kB view details)

Uploaded Python 3

File details

Details for the file pydantic_media_type-0.1.0.tar.gz.

File metadata

  • Download URL: pydantic_media_type-0.1.0.tar.gz
  • Upload date:
  • Size: 2.2 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pydantic_media_type-0.1.0.tar.gz
Algorithm Hash digest
SHA256 8dab17a9d205b5570958fd7f2e4022bd335bd05d9b06914dd4560e79e17c5be0
MD5 59c70fd8c9e47f3b1f682c7651e4487b
BLAKE2b-256 23fb09595645ee70dc005ff346cc81c3352bb626f056a7d2806c8d03b8038e47

See more details on using hashes here.

File details

Details for the file pydantic_media_type-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: pydantic_media_type-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 3.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: uv/0.10.2 {"installer":{"name":"uv","version":"0.10.2","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"Ubuntu","version":"24.04","id":"noble","libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":true}

File hashes

Hashes for pydantic_media_type-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 921f6db78cc7b41ab2ca1a90932409c22524550453cb325c0883180c07f8fa27
MD5 6a400bf80b257be493325428fe025205
BLAKE2b-256 9f46d0b491cf224504126b684f09d7d8ab332ae1ec8cc8c6741ffddb3e5e137e

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page