durl-py
Minimal, strict Data URL handling for Python.
durl-py is a small RFC 2397 library centered on one core type: DURL.
It parses existing data: URLs, builds new ones, preserves round-trip
serialization, and fails loudly on malformed input.
Installation
pip install durl-py
API
The public API is intentionally small:
from durl import DURL
Core properties:
mime_type: str | Noneparameters: Mapping[str, str]is_base64: boolraw_data: strparsed_data: str | bytes
Usage
Parse an existing Data URL:
from durl import DURL
durl = DURL("data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==")
print(durl.mime_type)
# text/plain
print(durl.is_base64)
# True
print(durl.parsed_data)
# Hello, World!
print(str(durl))
# data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==
Parse a non-base64 Data URL with charset:
from durl import DURL
durl = DURL("data:text/plain;charset=UTF-8,%E4%BD%A0%E5%A5%BD")
print(durl.parameters["charset"])
# UTF-8
print(durl.parsed_data)
# 你好
Build a new Data URL from bytes:
from durl import DURL
durl = DURL.build(mime_type="text/plain", data=b"Hello, World!")
print(durl.raw_data)
# SGVsbG8sIFdvcmxkIQ==
print(str(durl))
# data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==
Build a non-base64 URL explicitly:
from durl import DURL
durl = DURL.build(
mime_type="text/plain",
data="你好".encode("utf-8"),
parameters={"charset": "UTF-8"},
is_base64=False,
)
print(str(durl))
# data:text/plain;charset=UTF-8,%E4%BD%A0%E5%A5%BD
Use immutable with_*() updates:
from durl import DURL
original = DURL("data:text/plain;base64,SGVsbG8=")
updated = original.with_mime_type("text/markdown").with_parameters(
{"charset": "UTF-8"}
)
print(str(original))
# data:text/plain;base64,SGVsbG8=
print(str(updated))
# data:text/markdown;charset=UTF-8;base64,SGVsbG8=
Behavior
- Parsing is strict and RFC 2397-oriented.
- Both base64 and non-base64 forms are supported.
- Non-base64 payloads are percent-decoded.
charsetis respected when present.- Text payloads without
charsetmust be ASCII, or decoding raisesValueError. - Invalid media types, duplicate parameters, malformed percent-encoding, and invalid base64 all raise
ValueError.
Non-core Helpers
Text scanning helpers live outside the DURL core API:
from durl.utils.text import contents_from_text
contents_from_text() scans a larger string and returns a mixed list of
plain text segments and parsed DURL objects.
Filesystem helpers are still kept out of the core object and can be added under
durl.utils.* later if needed.
Development
Install dependencies:
poetry install --all-extras --all-groups
Run the docs site locally:
make docs-serve
Build the docs site:
make docs-build
Canonical test command:
python -m pytest -q
The repository also provides:
make pytest
The repository documentation site is built with mkdocs-material and deployed
to GitHub Pages through GitHub Actions.
License
MIT. See LICENSE.
Metadata
Release files for durl-py 0.3.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| durl_py-0.3.0.tar.gz | 6.1 kB | Without provenance | Details for durl_py-0.3.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| durl_py-0.3.0-py3-none-any.whl | Python 3 | none | any | Details for durl_py-0.3.0-py3-none-any.whl |
Total release size: 13.6 kB
Release files / durl_py-0.3.0.tar.gz
| Download URL | durl_py-0.3.0.tar.gz |
|---|---|
| Size | 6.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
c9992989334d0053843ca7e3fc5a85b072fee53f82ad79f0a5e9013f225a9cea
|
|
BLAKE2b-256 checksum How to use checksums |
bac0c97fca7714b001fbe11d2276060201b88e4f746bad20a623da8a150cb4e3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.3.3 CPython/3.11.13 Darwin/25.3.0
|
Release files / durl_py-0.3.0-py3-none-any.whl
| Download URL | durl_py-0.3.0-py3-none-any.whl |
|---|---|
| Size | 7.5 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
5b8d4d9bf9ba8cec87846acdb5f1b579d7db35bbb19714297e320eb49e424623
|
|
BLAKE2b-256 checksum How to use checksums |
fdccea12b6ba3e1199a762c313b3ea9c8580044687d47ab4826ccab460d21dc3
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
poetry/2.3.3 CPython/3.11.13 Darwin/25.3.0
|
Security for durl-py 0.3.0
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.