Python SDK
The hand-written Python client for Brain — two clients over one verb vocabulary, and every operation's reference page.
Two clients, one vocabulary
BrainHttpClientHTTP / JSON · synchronousTalks JSON to the Brain HTTP edge. Flat keyword arguments rather than
input objects — brain.encode(text=..., session=...).
BrainClientWire / BRN0 over TCP · synchronousThe binary protocol, demultiplexing on a reader thread. Takes request dataclasses, usually built with the builders.
AsyncBrainClientWire / BRN0 over TCP · asyncioThe same verbs with the same signatures, each a coroutine, demultiplexing on a reader task. See Sync vs async.
The synchronous client blocks the event loop when called from inside a
coroutine, and the async one needs a running loop. BrainHttpClient is a
third, separate thing — the hosted-edge REST client, not a transport choice
for the same API.
The client is flat. There are no namespaced resource objects and no separate query verb: the write verb is encode and the read verb is recall.
Install
pip install brain-db-sdkSee Installation for runtime and versioning notes.
Quickstart
import os
from brain_db_sdk import BrainHttpClient
brain = BrainHttpClient(
api_key=os.environ["BRAIN_API_KEY"],
base_url=os.environ.get("BRAIN_BASE_URL", "http://127.0.0.1:8080"),
)
brain.encode(text="I prefer dark mode and live in Berlin.")
answer = brain.recall(query="where does the user live?")
print(answer.answer_kind, answer.memories[0].text if answer.memories else None)recall never fabricates: the hit list is empty when Brain has nothing to
say.
Every operation
| Area | What it covers | Operations |
|---|---|---|
| Memory | The three verbs, plus the store-level operations and memory edges. | encode, recall, forget, encode_vector, memory_list, memory_inspect, graph_fetch, link, unlink |
| Spaces and sessions | Provision and erase the caller's space, and the sessions inside it. | create_space, list_spaces, delete_space, create_session, list_sessions, delete_session |
| Entities | The typed graph's identity layer — resolution, merging, lifecycle. | create_entity, get_entity, resolve_entity, list_entities, update_entity, rename_entity, merge_entities, unmerge_entity, tombstone_entity |
| Statements | Typed claims, their supersession chains, and three ways to retire one. | create_statement, get_statement, list_statements, supersede_statement, tombstone_statement, retract_statement, statement_history |
| Relations | Typed, directed, time-bounded edges between entities, and traversal. | create_relation, get_relation, list_relations, traverse_relations, supersede_relation, tombstone_relation |
| Schema | Declare the typed graph, and the extractors bound to it. | get_schema, validate_schema, upload_schema, replace_schema, drop_schema, list_schemas, list_extractors |
| Reasoning | Planning, inference, the procedural block, and query introspection. | plan, reason, materialize_procedural, query_explain, query_trace |
| Streams | The live change feed, and stream cancellation. | subscribe, cancel_stream |
| Transactions | Group wire writes into one atomic unit. | txn_begin, txn_commit, txn_abort |
| Credentials | Register and verify the LLM provider key extraction runs on. | put_llm_credential, get_llm_credential, test_llm_credential, verify_llm_credential, delete_llm_credential |
| Introspection | Who you are, what the server can do, and whether it is alive. | whoami, capabilities, ping |
Reading the reference
Each operation has one page covering both tiers. Where the two differ — a field name, an extra filter, a frame-level form — the page says so rather than splitting into two near-identical pages.
| Page | What it covers |
|---|---|
| Installation | Install, imports, runtime, versioning |
| HTTP client | Construction, auth, conventions |
| Wire client | Connect, config, act_as, multiplexing, pooling |
| Errors | Both taxonomies, the categories and the code families |
| Retries | What retries automatically, and what does not |
| Pagination | Cursors and frames |
Was this page helpful?