Python SDK reference

Package layout and configuration for the Spectron client in surrealdb.

ItemValue
PyPI packagesurrealdb (Spectron client bundled with the driver)
Installpip install surrealdb
Importfrom surrealdb import Spectron, AsyncSpectron
Submodulesurrealdb.spectron (models, namespaces, errors)

On PyPI, spectron is a different project. Install surrealdb for SurrealDB and Spectron — not pip install spectron.

Spectron(context: str, endpoint: str, api_key: str,
timeout: float = 30.0, max_retries: int = 3)
AsyncSpectron(...) # same arguments; methods are async

Requests use Authorization: Bearer <api_key>. Optional on_behalf_of on every verb sets X-Spectron-On-Behalf-Of for delegation.

MethodHTTP
remember(...)POST /api/v1/{ctx}/facts
remember_many(...)POST /api/v1/{ctx}/facts/batch
recall(...)POST /api/v1/{ctx}/query
forget(...)POST /api/v1/{ctx}/forget
chat(...)POST /api/v1/{ctx}/chat (SSE when stream=True)
consolidate(...)POST /api/v1/{ctx}/consolidate
reflect(...)POST /api/v1/{ctx}/reflect
elaborate(...)POST /api/v1/{ctx}/elaborate
query_context(...)POST /api/v1/{ctx}/context
inspect(ref, ...)GET /api/v1/{ctx}/inspect
state()GET /api/v1/{ctx}/state
whoami()GET /api/v1/{ctx}/me
profile()GET /api/v1/{ctx}/profile
audit(...)GET /api/v1/{ctx}/audit
health()GET /api/v1/health (not context-scoped)
NamespaceMethods
documentsupload, get, delete, list, query, fetch_raw, reprocess, recompute_links, chunks
documents.keywordslist, get, search, for_document
sessionscreate, delete, context, turns
entitieslist, get, delete, history
scopesregister, list, delete, forget
principalslist, get, grant, revoke, effective
keyscreate, list, delete, rotate
traceslist, get, stats
lifecycledecay, expire, fsck

Full REST tables: REST API.

Import from surrealdb.spectron:

ModelUsed for
RememberResponse, RememberBatchResponse, ExtractionResultFact ingest
RecallResponse, RecallHitSemantic recall
ChatResponse, ChatChunkChat (streaming chunks)
ContextQueryResponseComposed context string
StateResponseWorking-memory snapshot
UploadResponse, Document, DocumentPage, Chunk, ChunkPageDocument corpus
DocumentQueryResponse, DocumentQueryHitDocument search
Keyword, KeywordSearchResponse, …Keyword index
Session, Turn, TurnListResponseSessions
EntityDetail, EntityListResponse, …Knowledge graph entities
WhoamiResponse, ProfileResponseCaller identity
TraceRecord, AuditResponse, FsckReportObservability / maintenance

Nested graph and extraction payloads may remain dict values where the server shape evolves (“slim model” convention).

ClassHTTP
SpectronErrorBase
SpectronAPIErrorAny non-2xx without a subclass (status_code, message, trace_id, body)
SpectronAuthError401
SpectronScopeError403
SpectronNotFoundError404

Errors and retries

Python SDK

Was this page helpful?