Quickstart¶
- You need two things from your Volumes contact: an API key and the API endpoint (a URL). The SDK has no built-in endpoint.
- Make both available to your code, preferably through the environment:
export VOLUMES_API_KEY="<your API key>"
export VOLUMES_BASE_URL="<the API endpoint you were given>"
- Use the client:
import volumes
with volumes.Client() as client:
captures = client.list_captures()
print(f"{len(captures)} captures available")
if captures:
capture_id = captures[0].capture_id
print(client.get_frame_sync(capture_id).rows[:3])
print(client.get_scene_summary(capture_id))
Treat the API key like a password: keep it out of source control and logs.
The client sends it only in the Authorization header. It never appears in
repr() output, in what an exception says about itself (its message and
attributes, and those of the exceptions chained to it), or in the local
variables of the SDK's own stack frames (which is what error reporters and
pytest --showlocals print). That also holds when a misbehaving server or
proxy sends the key back in a response, in whatever letter case.
One thing is worth knowing about chained errors. When a request fails without
a response, the httpx error is chained to the SDK's (error.__cause__), and
an httpx error keeps the request that failed. The SDK removes the
Authorization header from that request before chaining the error, so
error.__cause__.request.headers does not hold the key. Each attempt is sent
with a request of its own, so retries are unaffected; if you pass your own
http_client and keep the request objects it sends, expect the ones that
failed to have lost that header. What the HTTP libraries' own stack frames
held at the moment of the failure is outside the SDK's reach.
A complete script¶
The script below lists the captures your key can read and saves each one's two files to disk, exactly as served. Fill in the two values at the top and run it.
"""Download frame_sync.csv and scene_summary.json for every capture this key can read.
pip install volumes
then fill in API_KEY and BASE_URL with the two values you were given.
"""
from pathlib import Path
import volumes
API_KEY = "<your API key>"
BASE_URL = "<the API endpoint you were given>"
OUT_DIR = Path("data")
client = volumes.Client(api_key=API_KEY, base_url=BASE_URL)
captures = client.list_captures()
print(f"{len(captures)} capture(s)")
for capture in captures:
folder = OUT_DIR / capture.capture_id
folder.mkdir(parents=True, exist_ok=True)
frame_sync = client.get_frame_sync(capture.capture_id)
(folder / "frame_sync.csv").write_bytes(frame_sync.content)
summary = client.get_scene_summary(capture.capture_id)
(folder / "scene_summary.json").write_bytes(summary.content)
print(capture.capture_id, len(frame_sync.rows), "rows, schema", summary.get("schema_version"))
client.close()