python-datauri
A li'l class for data URI manipulation in Python
What it is and what it does
python-datauri is a lightweight class for parsing and creating data URIs—the inline data scheme used to embed files, images, and text directly in URLs. It handles the common case of extracting or encoding a mimetype, charset, and base64 flag, then provides access to the decoded payload as bytes or text. The package is intentionally minimal and does not attempt to validate all edge cases; it focuses on the practical subset most developers need.
You use it to parse existing data URIs into their components (mimetype, charset, raw data) or to construct new ones from strings or files. It integrates with Pydantic for type validation in data models. The implementation depends only on cached-property and typing_extensions, making it a low-friction addition to any project that needs to work with embedded data URIs.
Use it for:
- Extract image data from a data URI embedded in HTML or JSON to save to disk or process
- Encode a file as a data URI for embedding in web pages or API responses
- Parse and validate data URIs in Pydantic models for REST APIs that accept inline uploads
- Convert between string and binary representations of embedded data without external libraries
- Build data URIs programmatically for testing or generating HTML with inline assets
Worth the install?
AI-flagged interpretation of the facts on this page — verify before relying
Parses and creates data URIs, extracting or encoding mimetype, charset, and base64 flags with minimal validation.
Yes, if you work with data URIs regularly. The package is stable, permissively licensed, has no security vulnerabilities, and requires minimal dependencies. Dormant maintenance is not a concern for a focused utility that does one thing well. Install it when you need to parse or create data URIs; skip it if you only handle them occasionally or can use simpler string manipulation.
Install
python-datauri on PyPI
pip
pip install python-datauriuv
uv add python-datauripoetry
poetry add python-datauriInstalling python-datauri
Before you install
Low friction: pure Python wheel with only two lightweight runtime dependencies (cached-property and typing_extensions). Dormant maintenance since 588 days ago, though the repository remains active with a recent commit on 2025-01-03.
License in practice
Released under the Unlicense, a permissive public-domain equivalent that places no restrictions on use, modification, or distribution.
Quickstart
from datauri import DataURI
# Parse a data URI
uri = DataURI('data:text/plain;charset=utf-8;base64,VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2cu')
print(uri.mimetype) # 'text/plain'
print(uri.data) # b'The quick brown fox jumped over the lazy dog.'
# Create from string
made = DataURI.make('text/plain', charset='us-ascii', base64=True, data='This is a message.')
print(str(made)) # 'data:text/plain;charset=us-ascii;base64,...'
Verify before relying
- Whether the package handles all valid data URIs or only the subset described as 'most useful'
- Performance characteristics with large embedded data or many URI operations
- Whether Pydantic integration requires additional setup beyond the example shown
Package facts
| License | Unlicense (permissive) |
| Python support | not specified |
| Install friction | low — pure-Python wheel |
| Runtime dependencies | 2 — cached-property, typing_extensions |
| Maintenance | dormant — 588 days since the last release |
| Last repo commit | |
| First released | |
| Downloads | 328,132/month — #7,559 on PyPI (30-day window, as of 2026-08-14) |
| Known vulnerabilities | none known (OSV.dev, checked 2026-08-14) |
Evidence: python_datauri-3.0.2-py2.py3-none-any.whl
Tags
More Internet packages
Botocore provides low-level, data-driven access…
permissive · top 100 on PyPI
aiobotocoreProvides an async client for AWS services using…
permissive · top 100 on PyPI
pydanticPydantic validates Python data structures…
permissive · top 100 on PyPI
filelockProvides a platform-independent file locking…
permissive · top 100 on PyPI
fastapiFastAPI is a Python web framework for building…
permissive · top 100 on PyPI
googleapis-common-protosProvides common Protocol Buffer message…
permissive · top 100 on PyPI
base2048Encodes and decodes binary data using Base2048,…
permissive · top 15,000 on PyPI
lazr.uriParse, manipulate, and generate URIs with a…
copyleft · top 15,000 on PyPI
prisonEncodes and decodes a compact URI-friendly data…
permissive · top 5,000 on PyPI
risonEncodes and decodes data to and from Rison, a…
permissive · top 15,000 on PyPI
rfc3986Parses, validates, and normalizes URIs…
permissive · top 1,000 on PyPI
webencodingsImplements the WHATWG Encoding standard to map…
permissive · top 1,000 on PyPI
uritoolsParses, validates, and composes URIs and URI…
permissive · top 5,000 on PyPI
arcpGenerate and parse arcp (Archive and Package)…
permissive · top 15,000 on PyPI
base64ioProvides a streaming interface for Base64…
permissive · top 15,000 on PyPI
pyuriPyURI parses, constructs, and manipulates URIs…
permissive · top 15,000 on PyPI