Skip to main content

Easy Data URL management for python

Project description

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_encode=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)

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

data_url-1.1.0.tar.gz (4.9 kB view details)

Uploaded Source

File details

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

File metadata

  • Download URL: data_url-1.1.0.tar.gz
  • Upload date:
  • Size: 4.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/5.1.1 CPython/3.9.6

File hashes

Hashes for data_url-1.1.0.tar.gz
Algorithm Hash digest
SHA256 c5ce1f9e53909aec8996dad81008eb9ab751bf19b7de5287f474b72cf1b4c3de
MD5 da16a345d4e512b4408bb9aa17e1e752
BLAKE2b-256 d31082d97450b8476a3fd76692901de1e916e8da80a09c00ac50107e7fe92994

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page