Assets

Asset resource

Access assets through client.assets.

📋

Prerequisites

Get started with Vi SDK →


Methods

list()

List assets in a dataset.

# Basic listing
assets = client.assets.list(dataset_id="dataset_abc123")

for asset in assets.items:
    print(f"{asset.filename}: {asset.metadata.width}x{asset.metadata.height}")
# With pagination and sorting
from vi.api.types import PaginationParams
from vi.api.resources.datasets.assets.types import (
    AssetSortCriterion,
    SortCriterion,
    SortOrder
)

pagination = PaginationParams(page_size=100)
sort_by = AssetSortCriterion(
    criterion=SortCriterion.FILENAME,
    order=SortOrder.ASC
)

for page in client.assets.list(
    dataset_id="dataset_abc123",
    pagination=pagination,
    sort_by=sort_by
):
    for asset in page.items:
        print(f"{asset.filename}")
# Get assets with download URLs
assets = client.assets.list(
    dataset_id="dataset_abc123",
    contents=True
)

for asset in assets.items:
    if asset.contents and asset.contents.asset:
        print(f"{asset.filename}: {asset.contents.asset.url}")
# Filter by metadata
assets = client.assets.list(
    dataset_id="dataset_abc123",
    metadata_query='custom_field == "value"'
)

Parameters:

ParameterTypeDescriptionDefault
dataset_idstrDataset identifierRequired
paginationPaginationParamsPagination settingsNone
contentsboolInclude download URLsFalse
sort_byAssetSortCriterionSorting criteriaNone
filter_criteriastrFilter queryNone
metadata_querystrMetadata queryNone

Returns: PaginatedResponse[Asset]


get()

Get a specific asset.

# Basic usage
asset = client.assets.get(
    dataset_id="dataset_abc123",
    asset_id="asset_xyz789"
)

print(f"Filename: {asset.filename}")
print(f"Size: {asset.metadata.file_size} bytes")
# Get with download URL
asset = client.assets.get(
    dataset_id="dataset_abc123",
    asset_id="asset_xyz789",
    contents=True
)

if asset.contents and asset.contents.asset:
    print(f"Download URL: {asset.contents.asset.url}")
    print(f"Expires: {asset.contents.asset.expiry}")
# Display detailed information
asset = client.assets.get(
    dataset_id="dataset_abc123",
    asset_id="asset_xyz789"
)
asset.info()  # Prints formatted asset summary

Parameters:

ParameterTypeDescriptionDefault
dataset_idstrDataset identifierRequired
asset_idstrAsset identifierRequired
contentsboolInclude download URLFalse

Returns: Asset


upload()

Upload assets to a dataset.

# Upload single file
result = client.assets.upload(
    dataset_id="dataset_abc123",
    paths="image.jpg",
    wait_until_done=True
)

print(f"Uploaded: {result.total_succeeded}")
# Upload entire folder
result = client.assets.upload(
    dataset_id="dataset_abc123",
    paths="./images/",
    wait_until_done=True
)

print(f"✓ Uploaded: {result.total_succeeded}")
print(f"✗ Failed: {result.total_failed}")
print(result.summary())
# Upload multiple specific files
result = client.assets.upload(
    dataset_id="dataset_abc123",
    paths=["image1.jpg", "image2.png", "image3.webp"],
    wait_until_done=True
)
# Upload with error handling
from vi import ViUploadError, ViFileTooLargeError

try:
    result = client.assets.upload(
        dataset_id="dataset_abc123",
        paths="./images/",
        wait_until_done=True
    )

    print(f"✓ Uploaded: {result.total_succeeded}")
    print(f"✗ Failed: {result.total_failed}")

    if result.failed_files:
        print("Failed files:")
        for f in result.failed_files:
            print(f"  - {f}")

except ViFileTooLargeError as e:
    print(f"File too large: {e.message}")
except ViUploadError as e:
    print(f"Upload failed: {e.message}")
# Async upload (don't wait)
result = client.assets.upload(
    dataset_id="dataset_abc123",
    paths="./large_folder/",
    wait_until_done=False
)

# Get session IDs for later status check
print(f"Session IDs: {result.session_ids}")

Parameters:

ParameterTypeDescriptionDefault
dataset_idstrDataset identifierRequired
pathsstr | list[str]File/folder pathsRequired
wait_until_doneboolWait for completionTrue
failure_modeFailureModeFailure handling"FailAfterOne"
on_asset_overwrittenResourceRetentionModeOverwrite behavior"RemoveLinkedResource"

Returns: AssetUploadResult


download()

Download assets from a dataset.

# Basic download
downloaded = client.assets.download(
    dataset_id="dataset_abc123",
    save_dir="./assets"
)
# Download with progress and overwrite
downloaded = client.assets.download(
    dataset_id="dataset_abc123",
    save_dir="./assets",
    overwrite=True,
    show_progress=True
)

print(f"Downloaded to: {downloaded}")

Parameters:

ParameterTypeDescriptionDefault
dataset_idstrDataset identifierRequired
save_dirstr | PathSave directoryRequired
overwriteboolOverwrite existingFalse
show_progressboolShow progress barsTrue

Returns: AssetDownloadResult


delete()

Delete an asset.

# Delete single asset
deleted = client.assets.delete(
    dataset_id="dataset_abc123",
    asset_id="asset_xyz789"
)
# Delete multiple assets
asset_ids = ["asset_1", "asset_2", "asset_3"]

for asset_id in asset_ids:
    client.assets.delete(
        dataset_id="dataset_abc123",
        asset_id=asset_id
    )
    print(f"Deleted: {asset_id}")

Parameters:

ParameterTypeDescription
dataset_idstrDataset identifier
asset_idstrAsset identifier

Returns: DeletedAsset


wait_until_done()

Wait for an upload session to complete.

# Basic usage
status = client.assets.wait_until_done(
    dataset_id="dataset_abc123",
    asset_ingestion_session_id="session_id"
)

print(f"Succeeded: {status.status.progressCount.succeeded}")
print(f"Failed: {status.status.progressCount.errored}")
# After async upload
result = client.assets.upload(
    dataset_id="dataset_abc123",
    paths="./images/",
    wait_until_done=False
)

# Do other work...

# Then wait for completion
for session_id in result.session_ids:
    status = client.assets.wait_until_done(
        dataset_id="dataset_abc123",
        asset_ingestion_session_id=session_id
    )
    print(f"Session {session_id}: {status.status.progressCount.succeeded} succeeded")

Parameters:

ParameterTypeDescription
dataset_idstrDataset identifier
asset_ingestion_session_idstrSession identifier

Returns: AssetIngestionSession


Response types

Asset

Main asset response object.

from vi.api.resources.datasets.assets.responses import Asset
PropertyTypeDescription
asset_idstrUnique identifier
dataset_idstrParent dataset ID
organization_idstrOrganization ID
filenamestrOriginal filename
kindstrResource kind
ownerstrOwner identifier
metadataAssetMetadataAsset metadata
self_linkstrAPI link
etagstrEntity tag
contentsAssetContents | NoneDownload URLs (if requested)

Methods:

MethodReturnsDescription
info()NoneDisplay formatted asset information

AssetMetadata

from vi.api.resources.datasets.assets.responses import AssetMetadata
PropertyTypeDescription
widthintImage width in pixels
heightintImage height in pixels
file_sizeintFile size in bytes
mime_typestrMIME type
upload_statusstrUpload status
statusstrProcessing status
framesintNumber of frames
visibilitystrVisibility setting
generationsAssetGenerationsAsset URLs
annotationsAssetAnnotationsAnnotation info
dimensionsAssetDimensionsDimension details
pixel_ratioAssetPixelRatioPixel ratio
hashAssetHashFile hash
inserted_bystrUploader ID
cohortslist[str]Cohort IDs
user_defineddict[str, Any]User metadata
custom_metadataAssetCustomMetadataCustom metadata
commentsintComment count
time_createdintCreation timestamp
last_updatedintUpdate timestamp

AssetGenerations

from vi.api.resources.datasets.assets.responses import AssetGenerations
PropertyTypeDescription
assetstrFull-size asset URL
thumbnailstrThumbnail URL

AssetAnnotations

from vi.api.resources.datasets.assets.responses import AssetAnnotations
PropertyTypeDescription
with_tagdict[str, int]Tag counts
totalintTotal annotations

AssetDimensions

from vi.api.resources.datasets.assets.responses import AssetDimensions
PropertyTypeDescription
heightintHeight in pixels
widthintWidth in pixels
depthint | NoneDepth (for 3D)

AssetPixelRatio

from vi.api.resources.datasets.assets.responses import AssetPixelRatio
PropertyTypeDescription
heightintHeight ratio
widthintWidth ratio
depthint | NoneDepth ratio

AssetHash

from vi.api.resources.datasets.assets.responses import AssetHash
PropertyTypeDescription
algorithmstrHash algorithm (e.g., 'sha256')
contentsstrHash value

AssetContents

from vi.api.resources.datasets.assets.responses import AssetContents
PropertyTypeDescription
assetContents | NoneFull asset URL info
thumbnailContents | NoneThumbnail URL info

Contents

from vi.api.resources.datasets.assets.responses import Contents
PropertyTypeDescription
urlstrPre-signed URL
expiryintExpiration timestamp
headersdict[str, str] | NoneRequired headers
methodstr | NoneHTTP method

AssetUploadResult

Aggregates results from batched uploads.

PropertyTypeDescription
total_filesintTotal files processed
total_succeededintSuccessfully uploaded
total_failedintFailed uploads
success_ratefloatSuccess percentage
sessionslist[AssetIngestionSession]Batch sessions
session_idslist[str]Session IDs
failed_fileslist[str]Failed file paths

Methods:

MethodReturnsDescription
summary()strGet summary string

AssetIngestionSession

from vi.api.resources.datasets.assets.responses import AssetIngestionSession
PropertyTypeDescription
organization_idstrOrganization ID
dataset_idstrDataset ID
asset_ingestion_session_idstrSession identifier
asset_source_classstrSource classification
asset_source_providerstrSource provider
asset_source_idstrSource identifier
self_linkstrAPI link
etagstrEntity tag
metadataResourceMetadataMetadata
specAssetIngestionSessionSpecSession spec
statusAssetIngestionSessionStatusSession status

AssetIngestionSessionSpec

from vi.api.resources.datasets.assets.responses import AssetIngestionSessionSpec
PropertyTypeDescription
kindstrResource kind
failureModeFailureModeFailure handling
onAssetOverwrittenResourceRetentionModeOverwrite handling
assetslist[UploadedAssetMetadata] | NoneAssets being uploaded

AssetIngestionSessionStatus

from vi.api.resources.datasets.assets.responses import AssetIngestionSessionStatus
PropertyTypeDescription
conditionslist[ResourceCondition]Status conditions
eventslist[AssetIngestionEvent]Ingestion events
progressCountAssetIngestionProgressCountProgress stats
assetslist[AssetForUpload] | NoneAssets being uploaded

AssetIngestionProgressCount

from vi.api.resources.datasets.assets.responses import AssetIngestionProgressCount
PropertyTypeDescription
totalintTotal assets
succeededintSucceeded
erroredintErrored

AssetIngestionEvent

Union type for ingestion events.

AssetIngestionEvent = AssetIngestionEventError | AssetIngestionEventProgress

UploadedAssetMetadata

from vi.api.resources.datasets.assets.responses import UploadedAssetMetadata
PropertyTypeDescription
kindstrResource kind
filenamestrFile name
mimestrMIME type
sizeintSize in bytes
crc32cint | NoneCRC32C checksum
custom_metadataAssetCustomMetadata | NoneCustom metadata

AssetForUpload

from vi.api.resources.datasets.assets.responses import AssetForUpload
PropertyTypeDescription
metadataUploadedAssetMetadataAsset metadata
uploadContentsUpload URL info

Request types

AssetSortCriterion

from vi.api.resources.datasets.assets.types import AssetSortCriterion
PropertyTypeDescriptionDefault
criterionSortCriterionSort fieldRequired
orderSortOrderSort directionASC

AssetCustomMetadata

from vi.api.resources.datasets.assets.types import AssetCustomMetadata

# Type alias
AssetCustomMetadata = dict[str, str | int | float | bool]

Custom metadata dictionary with string keys and primitive values.


Enums

SortCriterion

from vi.api.resources.datasets.assets.types import SortCriterion
ValueDescription
DEFAULTDefault sorting
ASSET_IDSort by asset ID
FILENAMESort by filename
LAST_MODIFIED_CONTENTSSort by last modified
METADATA_FILE_SIZESort by file size

SortOrder

from vi.api.resources.datasets.assets.types import SortOrder
ValueDescription
ASCAscending order
DESCDescending order

FailureMode

from vi.api.resources.datasets.assets.responses import FailureMode
ValueDescription
FAIL_AFTER_ONEStop on first error
FAIL_AFTER_ALLContinue and report all errors

ResourceRetentionMode

from vi.api.resources.datasets.assets.responses import ResourceRetentionMode
ValueDescription
REMOVE_LINKED_RESOURCERemove linked annotations
KEEP_LINKED_RESOURCESKeep linked annotations

AssetIngestionError

from vi.api.resources.datasets.assets.responses import AssetIngestionError
ValueDescription
EALREADYAsset already exists
EBADMIMEInvalid MIME type
EBADSIZEInvalid file size
ECORRUPTCorrupted file
ENOQUOTAQuota exceeded
ETIMEOUTUpload timeout
EUNKNOWNUnknown error

Supported file formats

FormatExtensions
JPEG.jpg, .jpeg, .jfif
PNG.png
TIFF.tiff, .tif
BMP.bmp
WebP.webp
HEIF.heif, .heic
AVIF.avif
JPEG 2000.jp2, .j2k
GIF.gif

Related resources