Media
Media
Bases: BaseModel
Represents a media object.
id
class-attribute
instance-attribute
The unique identifier of the assets.
mime_type
class-attribute
instance-attribute
mime_type: str | None = None
The MIME type of the media.
metadata
class-attribute
instance-attribute
The metadata of the media.
validate_media
classmethod
Validates the content of the media.
Source code in src/mosaico/media.py
from_path
classmethod
from_path(
path: PathLike,
*,
encoding: str = "utf-8",
mime_type: str | None = None,
guess_mime_type: bool = True,
metadata: dict | None = None,
**kwargs: Any
) -> Self
Creates a media from a path.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
path |
PathLike
|
The path to the media. |
required |
encoding |
str
|
The encoding of the media. |
'utf-8'
|
mime_type |
str | None
|
The MIME type of the media. |
None
|
guess_mime_type |
bool
|
Whether to guess the MIME type. |
True
|
metadata |
dict | None
|
The metadata of the media. |
None
|
kwargs |
Any
|
Additional keyword arguments to the constructor. |
{}
|
Returns:
Type | Description |
---|---|
Self
|
The media. |
Source code in src/mosaico/media.py
from_data
classmethod
from_data(
data: str | bytes,
*,
path: PathLike | None = None,
metadata: dict | None = None,
mime_type: str | None = None,
**kwargs: Any
) -> Self
Creates a media from data.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
str | bytes
|
The data of the media. |
required |
path |
PathLike | None
|
The path to the media. |
None
|
metadata |
dict | None
|
The metadata of the media. |
None
|
mime_type |
str | None
|
The MIME type of the media. |
None
|
kwargs |
Any
|
Additional keyword arguments to the constructor. |
{}
|
Returns:
Type | Description |
---|---|
Self
|
The media. |
Source code in src/mosaico/media.py
from_external
classmethod
Converts an external representation to a media.
Source code in src/mosaico/media.py
to_external
Converts the media to an external representation.
Source code in src/mosaico/media.py
to_string
Returns the media as a string.
Source code in src/mosaico/media.py
to_bytes
Returns the media as bytes.
Source code in src/mosaico/media.py
to_bytes_io
to_bytes_io(
*, storage_options: dict[str, Any] | None = None
) -> Generator[BytesIO | BufferedReader]
Read data as a byte stream.