Skip to content

Rapidata asset manager

RapidataAssetManager #

RapidataAssetManager(openapi_service: OpenAPIService)

Upload media once and reuse the reference across job definitions.

Access this manager via 🇵🇾attr:RapidataClient.asset.

Source code in src/rapidata/rapidata_client/asset/rapidata_asset_manager.py
def __init__(self, openapi_service: OpenAPIService):
    self._asset_uploader = AssetUploader(openapi_service)
    logger.debug("RapidataAssetManager initialized")

upload #

upload(asset: str) -> UploadedAsset

Upload a local file or a URL and return a reference to it.

Pass the reference as a datapoint or media context of any create_*_job_definition; it is not uploaded again. Uploads share the SDK's upload cache, so uploading the same path or URL twice returns the same reference without a second upload.

Parameters:

Name Type Description Default
asset str

A local file path or an http(s) URL.

required

Returns:

Name Type Description
UploadedAsset UploadedAsset

The reference to the uploaded media.

Source code in src/rapidata/rapidata_client/asset/rapidata_asset_manager.py
def upload(self, asset: str) -> UploadedAsset:
    """Upload a local file or a URL and return a reference to it.

    Pass the reference as a datapoint or media context of any
    ``create_*_job_definition``; it is not uploaded again. Uploads share the
    SDK's upload cache, so uploading the same path or URL twice returns the
    same reference without a second upload.

    Args:
        asset (str): A local file path or an http(s) URL.

    Returns:
        UploadedAsset: The reference to the uploaded media.
    """
    with tracer.start_as_current_span("RapidataAssetManager.upload"):
        uploaded = UploadedAsset(self._asset_uploader.upload_asset(asset))
        for warning in self._asset_uploader.drain_warnings():
            logger.warning(
                "Upload warning for '%s': %s", warning.item, warning.message
            )
        return uploaded