{"id":6832,"library":"python-datauri","title":"Python DataURI","description":"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.","status":"active","version":"3.0.2","language":"en","source_language":"en","source_url":"https://github.com/fcurella/python-datauri/","tags":["data uri","uri","encoding","base64","rfc2397"],"install":[{"cmd":"pip install python-datauri","lang":"bash","label":"Install latest"}],"dependencies":[],"imports":[{"note":"The primary class for creating and parsing data URIs.","symbol":"DataURI","correct":"from datauri import DataURI"}],"quickstart":{"code":"from datauri import DataURI\n\n# Parsing a data URI\nuri_string = 'data:text/plain;charset=utf-8;base64,VGhlIHF1aWNrIGJyb3duIGZveCBqdW1wZWQgb3ZlciB0aGUgbGF6eSBkb2cu'\nparsed_uri = DataURI(uri_string)\n\nprint(f\"MIME Type: {parsed_uri.mimetype}\")\nprint(f\"Charset: {parsed_uri.charset}\")\nprint(f\"Is Base64: {parsed_uri.is_base64}\")\nprint(f\"Decoded data (bytes): {parsed_uri.data}\")\nprint(f\"Decoded data (text): {parsed_uri.text}\")\n\n# Creating a data URI\nmade_uri = DataURI.make('image/png', base64=True, data=b'\\x89PNG\\r\\n...') # Example with bytes\nprint(f\"Created URI: {made_uri}\")\n\n# Creating from a string directly\ntext_uri = DataURI.make('text/plain', data='Hello, World!')\nprint(f\"Text URI: {text_uri}\")","lang":"python","description":"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."},"warnings":[{"fix":"Refer to the GitHub release notes or compare API usage between versions if encountering issues after upgrading.","message":"The library underwent a major version bump from 2.x to 3.x (v3.0.0 released Jan 3, 2025). While explicit breaking changes are not extensively documented in the README for this specific jump, major version changes typically introduce backwards-incompatible changes. Users upgrading from 2.x should review their code for compatibility.","severity":"breaking","affected_versions":">=3.0.0"},{"fix":"Use `parsed_uri.text` when expecting string data, and `parsed_uri.data` for raw byte data.","message":"The `DataURI.data` attribute always returns the decoded data as `bytes`. If you need a string representation (assuming the data is textual and decodable), you must use the `DataURI.text` attribute.","severity":"gotcha","affected_versions":"All"},{"fix":"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.","message":"The library's GitHub README notes that it is 'not very robust, and will reject a number of valid data URIs.' It primarily supports cases with a mimetype, charset, and base64 flag. Complex or non-standard data URIs might not parse correctly.","severity":"gotcha","affected_versions":"All"}],"env_vars":null,"last_verified":"2026-04-15T00:00:00.000Z","next_check":"2026-07-14T00:00:00.000Z","problems":[]}