Skip to main content

data_url.py

data_url is a Python 3 library which provides easy methods for creating and working with data URL's. The full API documentation is available here.

Examples

Creating a data URL

If all you need is to create a URL and nothing else there is a shortcut method included so you don't need to directly instantiate the DataURL class.

import data_url

with open('image.jpeg', 'rb') as image:
  data = image.read()

url = data_url.construct_data_url(mime_type='image/jpeg', base64_encoded=True, data=data)

If you need the information to persist it is recommended to instantiate a class through one of the factory methods on DataURL

import data_url

with open('image.jpeg', 'rb') as image:
  data = image.read()
  
url = data_url.DataURL.from_data('image/jpeg', True, data)
print(str(url))

You can access the full data URL by either converting the DataURL object to a string as above or by accessing the url attribute.

Retrieving data from a URL

Given you already have a data URL you can instantiate a DataURL object and retrieve each individual attribute.

import data_url

raw_url = "data:application/json;base64,ewogICJ0ZXN0IjogMTIzCn0K"

url = data_url.DataURL.from_url(raw_url)

print(url.mime_type, url.is_base64_encoded, url.data)

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

data_url-1.4.0.tar.gz (6.5 kB view details)

Uploaded Source

File details

Details for the file data_url-1.4.0.tar.gz.

File metadata

  • Download URL: data_url-1.4.0.tar.gz
  • Upload date:
  • Size: 6.5 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/7.0.0 CPython/3.13.14

File hashes

Hashes for data_url-1.4.0.tar.gz
Algorithm Hash digest
SHA256 21a13f65fa3b3c75b1d7beb56bbb47b46110e8ae21bdcfe20c3da05a7fc59521
MD5 3433c9f8e76c631cd83329693cef6958
BLAKE2b-256 5466f5778a96f6853819c7555cda4d821031403d626865369bd0d9706565bd08

See more details on using hashes here.

Provenance

The following attestation bundles were made for data_url-1.4.0.tar.gz:

Publisher: publish.yml on telday/data_url

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Release history Release notifications | RSS feed

This release

1.4.0 This release

1 file

1.3.1

1 file

1.3.0

1 file

1.2.1

1 file

1.2.0

1 file

1.1.1

1 file

1.1.0

1 file

1.0.7

1 file

1.0.6

1 file

1.0.5

1 file

1.0.4

1 file

1.0.3

1 file

1.0.2

1 file

1.0.1

1 file

1.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page