Assets
BaseAsset
Represents an assets with various properties.
from_media
classmethod
from_dict
classmethod
validate_params
classmethod
validate_params(params: Any) -> T
Validates the parameters for the assets.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
Any
|
The parameters to validate. |
required |
Returns:
Type | Description |
---|---|
T
|
The validated parameters. |
Source code in src/mosaico/assets/base.py
with_params
Returns a new assets with the specified parameters.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
params |
T | dict[str, Any]
|
The parameters to update. |
required |
Returns:
Type | Description |
---|---|
Self
|
A new assets with the specified parameters. |
Source code in src/mosaico/assets/base.py
AssetType
module-attribute
AssetType = Literal[
"video", "image", "audio", "text", "subtitle"
]
An enumeration of the different types of assets that can be held in an assets.
Asset
module-attribute
Asset = AudioAsset | ImageAsset | TextAsset | SubtitleAsset
Represents an assets with various properties.
AssetParams
module-attribute
AssetParams = (
AudioAssetParams | ImageAssetParams | TextAssetParams
)
Represents the parameters of an assets.
create_asset
create_asset(
asset_type: AssetType,
id: str | None = None,
data: str | bytes | None = None,
path: PathLike | None = None,
metadata: dict[str, Any] | None = None,
params: AssetParams | dict[str, Any] | None = None,
**kwargs: Any
) -> Asset
Create an asset from the given asset type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
asset_type |
AssetType
|
The asset type. |
required |
id |
str | None
|
The asset ID. |
None
|
data |
str | bytes | None
|
The asset data. |
None
|
path |
PathLike | None
|
The asset path. |
None
|
metadata |
dict[str, Any] | None
|
The asset metadata. ;param params: The asset parameters. |
None
|
kwargs |
Any
|
Additional keyword arguments. |
{}
|
Returns:
Type | Description |
---|---|
Asset
|
The asset. |
Source code in src/mosaico/assets/factory.py
get_asset_params_class
get_asset_params_class(
asset_type: AssetType,
) -> type[AssetParams]
Get the asset parameters class for the given asset type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
asset_type |
AssetType
|
The asset type. |
required |
Returns:
Type | Description |
---|---|
type[AssetParams]
|
The asset parameters class. |
Source code in src/mosaico/assets/factory.py
convert_media_to_asset
Convert a media object to an asset.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
media |
Media
|
The media object to convert. |
required |
Returns:
Type | Description |
---|---|
Asset
|
The asset object. |
Raises:
Type | Description |
---|---|
ValueError
|
If the media object does not have a MIME type or the MIME type is unsupported. |
Source code in src/mosaico/assets/utils.py
guess_asset_type_from_mime_type
Guess the asset type from a MIME type.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
mime_type |
str
|
The MIME type to guess the asset type from. |
required |
Returns:
Type | Description |
---|---|
AssetType
|
The asset type. |
Source code in src/mosaico/assets/utils.py
check_user_provided_required_keys
Check if the user provided all required keys.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
data |
dict
|
The data to check. |
required |
required_keys |
Sequence[str]
|
The required keys. |
required |
Returns:
Type | Description |
---|---|
bool
|
Whether the user provided all required keys. |