No project description provided
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
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Hashes for data_url-1.0.4.macosx-10.9-x86_64.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | 832b3918b880cd3727fce5f8f55b2ce6a5404d0501602f92915a80a0b28c0f88 |
|
MD5 | 6e40532a0bb1415177c4b6ca474834af |
|
BLAKE2b-256 | 535060a0510e8b3017488d070e5a66e44960e2518578d755e4eb841dd59cae47 |