datarobot_genai.drmcputils.files.store
store
Blob storage for drtools, backed by the DataRobot Files API (v3.10+).
Defines a minimal path-based :class:BlobStore Protocol and a Files-API-backed
implementation. Higher-level domains (e.g. panels) depend on the Protocol, not
the concrete backend, so storage stays swappable (a local/in-memory backend can
satisfy the same contract for tests) and the Files API is the production
default.
Layout. All blobs live inside one shared Files container (a catalog item
created via Files.create_empty_catalog_item_dir and discovered by the
dr_panel_root marker tag), addressed by /-separated paths. This is the
Files API's sanctioned folder mechanism: upload_file(prefix=...) joins the
folder path server-side after filename sanitization, so paths survive intact
— unlike a path embedded in an uploaded filename, which the server strips to
its basename as a disk-traversal defense (and logs a security warning for).
One container also renders as a single folder row on the registry page instead
of one row per blob, and prefix listing is a single server-side query (the
per-blob-container + tag design this replaces needed client-side AND filtering
over the whole catalog, because catalog tag search matches with OR semantics).
Legacy blobs. Blobs stored before the shared-container layout are
standalone single-file containers addressed by their Files id. :meth:get and
:meth:delete accept a bare id (no /) and fall back to that layout, so
pre-existing panels stay reachable by id.
The DataRobot Files SDK (datarobot.models.Files) is synchronous; its calls
are dispatched to a worker thread via :func:asyncio.to_thread, which copies
the current context so the per-request client configured by
:func:request_user_dr_sdk remains in effect inside the thread.
BlobRef
dataclass
A lightweight, serializable handle to a stored blob.
path— the blob's/-separated path inside the shared container; unique per blob and stable until the blob is moved.container_id— the shared container's Files id. Together withpaththis is exactly what the Files download API needs (POST files/<container_id>/downloads/withfileName=<path>).size— byte size (recorded on put, returned by the listing API).
MIME content-type is intentionally not a field: the Files API does not
persist one, so it could not be populated symmetrically by list.
Callers that need a content-type should record it themselves (e.g. a panel
manifest); see content_type on :meth:BlobStore.put.
Source code in datarobot_genai/drmcputils/files/store.py
BlobStore
Bases: Protocol
Storage seam for opaque byte payloads. Implementations must be async-safe.
Source code in datarobot_genai/drmcputils/files/store.py
put
async
put(data: bytes, *, path: str, content_type: str | None = None, timeout: int = DEFAULT_PUT_TIMEOUT_SECONDS) -> BlobRef
Store data at path, replacing any existing blob at that path.
content_type is advisory: the Files backend does not persist it, so
it is not reflected on the returned :class:BlobRef. Callers that need
it should record it alongside their own metadata.
timeout bounds the upload (seconds); raise it for very large blobs.
Source code in datarobot_genai/drmcputils/files/store.py
get
async
Fetch the bytes at path.
A bare token without / is treated as a legacy blob id (a
standalone pre-shared-container Files container) and fetched from that
layout instead.
Source code in datarobot_genai/drmcputils/files/store.py
delete
async
Delete the blobs at paths; missing paths are silently ignored.
Like :meth:get, a bare token without / addresses a legacy
standalone container.
Source code in datarobot_genai/drmcputils/files/store.py
move
async
list
async
list(*, prefix: str | None = None, limit: int = DEFAULT_LIST_LIMIT, offset: int = 0) -> list[BlobRef]
List blobs under prefix (server-side filter; None = all).
prefix must be a directory prefix ending with / — the Files
API rejects anything else with a 400. limit=0 returns every match.
Returns [] when the shared container does not exist yet (nothing
was ever stored).
Source code in datarobot_genai/drmcputils/files/store.py
DataRobotFilesBlobStore
:class:BlobStore backed by one shared DataRobot Files container.
The container is found by the dr_panel_root marker tag (created on
first write; read paths never create it). The resolved SDK object is cached
per store instance — instances are built per request, so the cache never
outlives the requesting user's credentials.
Source code in datarobot_genai/drmcputils/files/store.py
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 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 | |