-
Notifications
You must be signed in to change notification settings - Fork 0
Open
Description
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 Pydantic — AnyUrl 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_type→str(e.g."text/plain","image/png", defaults to"text/plain;charset=US-ASCII"per RFC).is_base64→bool.data→str(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
AnyUrlexplicitly rejectsdata: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
Reactions are currently unavailable
Metadata
Metadata
Assignees
Labels
No labels