Artifact¶
An Artifact represents a binary data blob stored in IVCAP — images, CSV files,
NetCDF datasets, model checkpoints, etc. Artifacts are created by
ivcap.upload_artifact() or ivcap.get_artifact().
Quick Reference¶
from ivcap_client.ivcap import IVCAP
ivcap = IVCAP()
# Upload a file
artifact = ivcap.upload_artifact(
name="my-data",
file_path="/path/to/file.csv",
)
print(artifact.id, artifact.mime_type)
# Download
with artifact.as_local_file() as path:
print(f"Downloaded to: {path}")
# Stream to disk
with open("/tmp/output.csv", "wb") as f:
for chunk in artifact.as_stream():
f.write(chunk)
Class Documentation¶
Artifact
dataclass
¶
Represents an artifact stored in an IVCAP deployment.
An artifact is any binary or structured data blob produced or consumed by a job — an image, a CSV file, a NetCDF dataset, a trained model checkpoint, etc.
Each artifact has two complementary parts:
- Blob — the raw bytes, stored in object storage (GCS/S3-compatible).
- Aspects — typed metadata records in the Datafabric describing the artifact's MIME type, size, provenance, and any domain annotations.
Key properties:
id/urn— canonicalurn:ivcap:artifact:<uuid>identifiername— human-readable namemime_type— MIME content type (e.g."image/jpeg")size— size in bytesstatus— current :class:~ivcap_client.models.ArtifactStatusRTStatusvalue
Reading artifact content:
- :meth:
as_local_file— recommended download method; saves to a temp file (auto-deleted on context exit) or to an explicit path. - :meth:
open— returns a file-like object with all bytes loaded into memory (convenient for small files). - :meth:
as_stream— yields rawbyteschunks for memory-efficient streaming or custom chunk processing.
Example::
artifact = ivcap.get_artifact("urn:ivcap:artifact:<uuid>")
# Download to a temp file (auto-deleted when the 'with' block exits)
with artifact.as_local_file() as path:
data = path.read_bytes()
# Download to a specific path (file is kept)
path = artifact.as_local_file("/tmp/output.jpg")
# Load entirely into memory
with artifact.open() as f:
data = f.read()
Source code in ivcap_client/artifact.py
46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 | |
open()
¶
Return a file-like object with the full artifact content loaded into memory.
The entire artifact blob is fetched in a single HTTP request and wrapped in a
:class:ProxyFile backed by an in-memory :class:io.BytesIO buffer. This
is convenient for small artifacts where memory is not a concern.
.. warning::
The full content is loaded into memory. For large artifacts (hundreds of
MB or more) prefer :meth:as_stream (chunked iteration) or
:meth:as_local_file (stream-to-disk), both of which avoid holding the
entire blob in RAM.
Returns:
| Name | Type | Description |
|---|---|---|
ProxyFile |
IOBase
|
A readable, seekable, context-manager-compatible file-like
object. Call :meth: |
Example::
with artifact.open() as f:
data = f.read() # bytes
text = data.decode("utf-8")
Source code in ivcap_client/artifact.py
as_stream(chunk_size=-1)
¶
Stream the artifact content as a sequence of raw byte chunks.
Uses an HTTP streaming GET so that only chunk_size bytes are buffered
in memory at a time. This is the lowest-level download method and is
suitable when you need to:
- Implement custom progress reporting.
- Pipe artifact bytes into a third-party streaming API.
- Process data incrementally without writing a local file.
For simply saving the artifact to disk, :meth:as_local_file is more
ergonomic. For loading everything into memory at once, use :meth:open.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
chunk_size
|
int
|
Number of bytes to read per chunk. Pass |
-1
|
Yields:
| Name | Type | Description |
|---|---|---|
bytes |
bytes
|
The next chunk of raw artifact bytes. |
Example::
# Stream to a file with progress reporting
total = 0
with open("/tmp/output.dat", "wb") as f:
for chunk in artifact.as_stream():
f.write(chunk)
total += len(chunk)
print(f"Downloaded {total} bytes")
Source code in ivcap_client/artifact.py
as_local_file(path=None, chunk_size=-1)
¶
Download the artifact to a local file and return the path.
This is the recommended method for saving artifact content to disk.
It supports two usage patterns depending on whether path is supplied:
Temporary file (path omitted) — a new temp file is created and a
:class:CMPath is returned. :class:CMPath is a context-manager-aware
:class:~pathlib.Path subclass: when used in a with statement the
file is automatically deleted when the block exits. Use this pattern
when you only need the file transiently::
with artifact.as_local_file() as path:
data = path.read_bytes()
# temp file has been deleted here
Explicit path (path provided) — the content is streamed to the given
path (parent directories are created automatically). A plain
:class:~pathlib.Path is returned; the file is not deleted
automatically. Use this pattern when you want to keep the file::
path = artifact.as_local_file("/tmp/output.jpg")
# file remains at /tmp/output.jpg
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
Path | None
|
Destination file path. If |
None
|
chunk_size
|
int
|
Number of bytes to read per chunk. Pass |
-1
|
Returns:
| Type | Description |
|---|---|
Path
|
class: |
Note
Both :class:CMPath and :class:~pathlib.Path are
:class:~pathlib.Path subclasses and support all normal path
operations (read_bytes(), open(), etc.).
Source code in ivcap_client/artifact.py
add_metadata(aspect, *, schema=None, policy=None)
¶
Add a metadata 'aspect' to this artifact. The 'schema' of the aspect, if not defined is expected to found in the 'aspect' under the '$schema' key.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
aspect
|
dict
|
The aspect to be attached |
required |
schema
|
Optional[str]
|
Schema of the aspect. Defaults to 'aspect["$schema"]'. |
None
|
policy
|
URN | None
|
Optional[URN]: Set specific policy controlling access ('urn:ivcap:policy:...'). |
None
|
Returns:
| Name | Type | Description |
|---|---|---|
self |
Artifact
|
To enable chaining |