Skip to main content

Simple Data URL Model

Project description

durl-py

A lightweight Python library for working with Data URLs (RFC 2397).

Installation

pip install durl-py

Usage

DataURL Class

The durl.DataURL class provides a convenient way to create, parse, and manipulate Data URLs.

Creating a DataURL from raw data:

from durl import DataURL, MIMEType

# From bytes
data_url = DataURL.from_data(MIMEType.TEXT_PLAIN, b"Hello, World!")
print(data_url.url)
# data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==

# From string
data_url = DataURL.from_data(MIMEType.TEXT_PLAIN, "Hello, World!")
print(data_url.url)
# data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==

Parsing a DataURL string:

from durl import DataURL

data_url_string = "data:text/plain;base64,SGVsbG8sIFdvcmxkIQ=="
data_url = DataURL.from_url(data_url_string)

print(data_url.mime_type)
# text/plain

print(data_url.data_decoded)
# Hello, World!

message_contents_from_text function

The durl.message_contents_from_text function allows you to extract Data URLs from a string.

from durl import message_contents_from_text, DataURL

text = "Here is an image: data:image/png;base64,iVBORw0KGgoAAAANSUhEUgAAAAUAAAAFCAYAAACNbyblAAAAHElEQVQI12P4//8/w38GIAXDIBKE0DHxgljNBAAO9TXL0Y4OHwAAAABJRU5ErkJggg== and some text."

contents = message_contents_from_text(text)

print(contents[0])
# Here is an image:

assert isinstance(contents[1], DataURL)
print(contents[1].mime_type)
# image/png

print(contents[2])
# and some text.

Development

To install the development dependencies, run:

pip install -r requirements-all.txt

To run the tests, run:

pytest

License

This project is licensed under the MIT License. See the LICENSE file for details.

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

durl_py-0.2.0.tar.gz (7.9 kB view details)

Uploaded Source

Built Distribution

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

durl_py-0.2.0-py3-none-any.whl (8.3 kB view details)

Uploaded Python 3

File details

Details for the file durl_py-0.2.0.tar.gz.

File metadata

  • Download URL: durl_py-0.2.0.tar.gz
  • Upload date:
  • Size: 7.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.11.13 Darwin/24.6.0

File hashes

Hashes for durl_py-0.2.0.tar.gz
Algorithm Hash digest
SHA256 a25fddec3baed0b0c2cbafda10ffe2f9c6b60219d05e01ab295fd99605c57f8f
MD5 7f412b6c7231cfa4f78ad2b4a76fec41
BLAKE2b-256 21965aa38fa6d2ea2ffb4e30fcfb75eeea7a497e625a2b1275217ab7a95d0404

See more details on using hashes here.

File details

Details for the file durl_py-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: durl_py-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 8.3 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/2.1.4 CPython/3.11.13 Darwin/24.6.0

File hashes

Hashes for durl_py-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 1e968da6a8b20ac3454d0cdb94675613e7e62fd693aa8e64d98d8ffb9ea0b581
MD5 60e0f2b109120c79f35ee1f602aed035
BLAKE2b-256 1abcb344fdce939c0d0b49af632812f9b53e0bae27f0da998759deb1d06b1631

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