DataUri Class
A class to represent a data uri.
If a array is provided, that will be used as the data since it is the most efficient, otherwise the bytes will be used, or the string will be converted to bytes.
When updating either array or bytes, the other will not be updated.
Initialize the data uri.
Make sure to set the data_format to base64 so that it can be decoded properly.
Constructor
DataUri(data_bytes: bytes | None = None, data_str: str | None = None, data_array: ndarray | None = None, mime_type: str | None = None, parameters: Sequence[str] | Mapping[str, str] | None = None, data_format: str | None = None)
Parameters
| Name | Description |
|---|---|
|
data_bytes
|
The data as bytes. Default value: None
|
|
data_str
|
The data as a string. Default value: None
|
|
data_array
|
The data as a numpy array. Default value: None
|
|
mime_type
|
The mime type of the data. Default value: None
|
|
parameters
|
Any parameters for the data. Default value: None
|
|
data_format
|
The format of the data (e.g. base64). Default value: None
|
|
data_bytes
Required
|
The data as bytes. |
|
data_str
Required
|
The data as a string. |
|
data_array
Required
|
The data as a numpy array. |
|
mime_type
Required
|
The mime type of the data. |
|
parameters
Required
|
Any parameters for the data. |
|
data_format
Required
|
The format of the data (e.g. base64). |
|
kwargs
Required
|
Any additional arguments. |
Methods
| from_data_uri |
Create a DataUri object from a data URI string or pydantic URL. |
| to_string |
Return the data uri as a string. |
| update_data |
Update the data, using either a string or bytes. |
from_data_uri
Create a DataUri object from a data URI string or pydantic URL.
from_data_uri(data_uri: str | Url, default_mime_type: str = 'text/plain') -> _T
Parameters
| Name | Description |
|---|---|
|
data_uri
Required
|
|
|
default_mime_type
|
Default value: text/plain
|
to_string
Return the data uri as a string.
to_string(metadata: dict[str, str] = {}) -> str
Parameters
| Name | Description |
|---|---|
|
metadata
|
Default value: {}
|
update_data
Update the data, using either a string or bytes.
update_data(value: str | bytes | ndarray) -> None
Parameters
| Name | Description |
|---|---|
|
value
Required
|
|
Attributes
data_array
data_array: ndarray | None
data_bytes
data_bytes: bytes | None
data_format
data_format: str | None
mime_type
mime_type: str | None
parameters
parameters: MutableMapping[str, str]