Skip to content

Add DataUri type to web domain #11

@oborchers

Description

@oborchers

Summary

Add a DataUri type to the web domain for validating RFC 2397 data URIs (data:[<mediatype>][;base64],<data>). This fills a documented gap in PydanticAnyUrl explicitly does not support data: URIs (see pydantic#2157).

Proposed Type

DataUri (Pattern A — str subclass)

  • Spec: RFC 2397 — The "data" URL scheme
  • Domain: web/
  • Format: data:[<mediatype>][;base64],<data>
  • Parsed properties:
    • .media_typestr (e.g. "text/plain", "image/png", defaults to "text/plain;charset=US-ASCII" per RFC)
    • .is_base64bool
    • .datastr (the raw data portion after the comma)
  • Usage: Common in web APIs, ML model serving (embedding images/audio), configuration files, email templates, and data pipelines. Pydantic's AnyUrl explicitly rejects data: URIs, making this a known ecosystem gap.
  • Examples:
    • "data:,Hello%20World" (plain text, no mediatype)
    • "data:text/plain;base64,SGVsbG8gV29ybGQ=" (base64-encoded text)
    • "data:image/png;base64,iVBORw0KGgo..." (embedded image)
    • "data:application/json,{\"key\":\"value\"}" (inline JSON)

Verification

  • Fills a documented Pydantic gap (pydantic#2157)
  • Not in Pydantic core, pydantic-extra-types, or any known Pydantic-native library
  • Regex/parsing only — no external service calls
  • Follows Pattern A per ARCHITECTURE.md (str subclass with parsed properties)

Implementation

  • File: src/pydantypes/web/data_uri.py
  • Tests: tests/web/test_data_uri.py
  • Export: Add to src/pydantypes/web/__init__.py

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions