A small Python library for manipulating data URIs, as defined in RFC2397. It provides functionalities for parsing existing data URIs into structured objects and creating new ones from various inputs. The library is currently at version 3.0.2 and appears to have an infrequent release cadence, driven by feature additions and Python version compatibility.
pip install python-datauriVerified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to parse an existing data URI and access its components, and how to create a new data URI from specified media type and data. It highlights the use of `DataURI.data` for bytes and `DataURI.text` for string representations.
Refer to the GitHub release notes or compare API usage between versions if encountering issues after upgrading.
Use `parsed_uri.text` when expecting string data, and `parsed_uri.data` for raw byte data.
Be aware of this limitation when working with diverse or malformed data URIs. For highly robust data URI parsing across all RFC specifications, consider `urllib.request.urlopen` in Python's standard library for basic decoding, or other more comprehensive solutions if available.
Use `import datauri` instead, as the installed module is named 'datauri'.
Ensure the input string is a valid data URI, starting with 'data:' and following the correct structure. Example: `datauri.DataURI('data:text/plain;base64,SGVsbG8sIFdvcmxkIQ==')`Provide the `data` parameter as a `bytes` object for binary data or a `str` object for text data. Example: `datauri.DataURI(mimetype='text/plain', data='Hello, World!')` or `datauri.DataURI(mimetype='application/octet-stream', base64=True, data=b'\x01\x02\x03')`
No dependency data recorded yet.