The Spectron client ships inside the main SurrealDB Python package (surrealdb). Install one package and import Spectron or AsyncSpectron alongside the database driver.
Package naming: On PyPI, the Spectron client ships in the
surrealdbpackage alongside the database driver — usepip install surrealdb. The bare namespectronbelongs to an unrelated project; do not install it for SurrealDB Spectron.
Installation
Python 3.10+ recommended.
Clients
Spectron is synchronous (uses requests). AsyncSpectron is async (uses aiohttp). Both expose the same method names — add await on the async client.
Both clients are pinned to one context and call /api/v1/{context}/…. Pass context, endpoint, and api_key explicitly — the SDK does not read environment variables.
Scope
On the wire, scope is a ScopeSet: an ordered array of slash-path strings (for example ["org/acme/user/alice"]). Register paths with spectron scopes create before first use — see Contexts and scope.
The Python client accepts:
A single path:
scope="org/acme/user/alice"A list of paths:
scope=["org/acme/user/alice"]
| Argument | Default | Description |
|---|---|---|
context | required | Context id, e.g. "acme-prod". |
endpoint | required | Spectron host URL, e.g. "https://api.spectron.example". |
api_key | required | Bearer token (Authorization: Bearer …). |
timeout | 30.0 | Per-request timeout in seconds. |
max_retries | 3 | Retries for GETs and idempotent writes. |
Remember (facts)
remember and remember_many send an Idempotency-Key header (derived from method, path, body, and a 30-second bucket) so safe retries collapse server-side.
Recall and context
Optional filters include labels, lens, scope_view (strict | merged | crossTeam), temporal bounds (as_of, valid_from, …), and geo location.
Documents
Chat (including streaming)
Other verbs and namespaces
Top-level methods: consolidate, reflect, elaborate, forget, state, whoami, profile, inspect, audit, health.
Grouped resources: memory.documents, memory.sessions, memory.entities, memory.scopes, memory.principals, memory.keys, memory.traces, memory.lifecycle.
→ Full method tables: Python SDK reference
Response types
Typed dataclasses include RememberResponse, RecallResponse, RecallHit, ChatResponse, Document, Chunk, StateResponse, and others. Import from surrealdb.spectron when you need explicit types:
Harness adapter (zero prompt change)
For LangChain-style apps that should auto-record every turn:
CLI alternative
The spectron binary exposes the same operations without the SDK: