Artifacts¶
An artifact is a file (a PDF, dataset, image, …) attached to another entity. Every
artifact is UUID-addressed and bound to a parent via parent_urn — an article, a
guide, a textbook, or an FCTable.
What it is¶
Entity class |
|
Collection |
|
Endpoint |
|
Identifier |
UUID ( |
Belongs to |
a parent entity ( |
Field reference¶
Field |
Type |
Notes |
|---|---|---|
|
|
Read-only. |
|
|
Read-only — the owning entity. |
|
|
Read-only. |
|
|
|
|
|
|
|
|
Public/served URL. |
|
|
Backing object-store URL. |
|
|
MIME/type — required by the update schema. |
|
|
Bytes. |
|
|
|
|
|
Read-only. |
Uploading¶
Upload a file and create the artifact in a single request. file may be a path or an
open binary file object:
art = client.artifacts.upload(
"report.pdf",
parent_urn="urn:guide:national-dietary-guidelines-2023",
title="Source PDF",
description="Original published document",
language="en",
)
print(art.id, art.file_size)
Downloading¶
# Stream straight to a local path (creates parent dirs as needed)
path = client.artifacts.download_to(art.id, "./out/report.pdf")
# Or get the raw streamed requests.Response to handle yourself
resp = client.artifacts.download(art.id, stream=True)
for chunk in resp.iter_content(chunk_size=8192):
...
# The same methods exist on a loaded artifact:
art.download_to("./out/report.pdf")
art.download(stream=True)
Parent-bound artifacts¶
Any URN-backed entity exposes entity.artifacts, a proxy already scoped to that parent —
you don’t pass parent_urn:
guide = client.guides["national-dietary-guidelines-2023"]
# Upload under this guide
guide.artifacts.upload("appendix.pdf", title="Appendix")
# Iterate / look up this guide's artifacts
for a in guide.artifacts:
print(a.title, a.file_type, a.file_size)
When a parent entity’s API response already embeds its artifacts, the proxy uses those records directly (no extra request), and newly uploaded/created artifacts are folded back into the parent’s embedded list.
Updating an artifact¶
art.title = "Source PDF (revised)" # auto-syncs
Note
The server’s update schema requires file_type, so the client always includes it when
sending a partial artifact update — you don’t need to set it yourself.
Gotchas¶
Artifacts are addressed by UUID, not a slug or URN.
An artifact belongs to exactly one parent; fetching one through a parent-bound proxy validates the
parent_urnand raisesKeyErroron a mismatch.download()returns arequests.Response; usedownload_to()when you just want the bytes on disk.