48
SDKsPython SDK
Use the official Python SDK for all SapixDB operations — no raw curl required.
Prerequisite: Lesson 5 complete
What you'll learn
- ✓pip install sapixdb
- ✓SapixClient(base_url, api_key)
- ✓client.agents('name').write({...})
- ✓client.agents('name').query({type, filter, limit})
- ✓client.agents('name').write_batch([...])
- ✓client.agents('name').stream() — SSE generator
Challenge
Rewrite the Lesson 5 challenge entirely using the Python SDK. No curl allowed.
Interactive Walkthrough
What you'll learn
Use the official Python SDK for all SapixDB operations — no raw curl required.
Install
pip install sapixdbConnect
`python
from sapixdb import SapixClient
client = SapixClient(
base_url="http://localhost:7475",
api_key="spx_root_YOUR_ROOT_KEY"
)
`
Write a record
result = client.agents("users").write({
"user_id": "usr_001",
"email": "alice@example.com",
"plan": "pro"
})
print(result.content_hash)Query
records = client.agents("users").query({
"type": "scan",
"limit": 10,
"filter": {"field": "plan", "op": "eq", "value": "pro"}
})
for r in records:
print(r.payload)Time travel
`python
import time
snapshot_hlc = int(time.time() * 1000) * 65536
# ... write more records ...
past_records = client.agents("users").query({
"type": "as_of",
"ts_hlc": snapshot_hlc,
"limit": 100
})
`
Batch write
client.agents("events").write_batch([
{"type": "page_view", "page": "/pricing"},
{"type": "click", "element": "cta"},
{"type": "form_submit"}
])Stream records (SSE)
for event in client.agents("orders").stream():
print(f"New order: {event.payload}")
# Press Ctrl+C to stopChallenge
Rewrite the Lesson 5 challenge entirely using the Python SDK. No curl allowed.
---