Installation
Install brain-db-sdk, its zero dependencies, the Python floor, and how to import each of the three tiers.
Install
pip install brain-db-sdkPython>= 3.10requiredpyproject.toml declares requires-python = ">=3.10".
Dependenciescbor2 >= 5.9requiredExactly one — cbor2, for the wire tier's CBOR payloads. >=5.9 is a
security floor, not a feature one: 5.6–5.8 let a peer crash the client
with a deeply nested payload. CRC32C is pure Python. The HTTP tier adds
nothing: it is built on urllib.request, so a program that only talks to
the edge pulls in no third-party code at all.
Typingpy.typedoptionalThe package ships inline type hints. from __future__ import annotations
throughout, so the annotations work on every supported version.
Imports
Three tiers, three entry points:
# Wire tier — synchronous
from brain_db_sdk import (
BrainClient,
ClientConfig,
Auth,
Pool,
EncodeBuilder,
RecallBuilder,
ForgetBuilder,
WaitMode,
RecallScope,
new_id,
derive_space_id,
)
# Wire tier — asyncio
from brain_db_sdk import AsyncBrainClient, AsyncPool, AsyncSubscription
# or: from brain_db_sdk.aio import AsyncBrainClient
# HTTP tier
from brain_db_sdk import BrainHttpClient, BrainHttpError
# or: from brain_db_sdk.http import BrainHttpClient
# Errors
from brain_db_sdk import (
BrainError,
ProtocolError,
ConnectionClosed,
BrainTimeout,
VersionMismatch,
ServerError,
ActAsDenied,
is_retryable,
)
from brain_db_sdk.errors import LlmCredentialMissing, LlmCredentialUnavailableTwo different `with_retry`s
brain_db_sdk.retry.with_retry (synchronous) and
brain_db_sdk.aio.with_retry (a coroutine) are different functions. The
synchronous one is re-exported at the package root; the asyncio twin is
reachable only through brain_db_sdk.aio, so a bare
from brain_db_sdk import with_retry always gives you the blocking one.
Versioning
__version__ is read from the installed distribution metadata rather than
hardcoded:
import brain_db_sdk
print(brain_db_sdk.__version__)It falls back to "0.0.0+unknown" only when running from a source tree with
nothing installed. Reading it from the distribution is deliberate: the
attribute used to be hardcoded, and said 0.1.0 while the package shipped as
0.3.1 — so anything branching on it, a compatibility check or a bug report
or a telemetry tag, read a version that had not existed for two releases. It
cannot disagree with pyproject.toml now. Rust and TypeScript expose the same
number as SDK_VERSION.
The package is pre-1.0. Minor versions may change shapes; pin an exact version in production.
All three SDKs target Brain wire protocol version 1 — the version byte
in the BRN0 header, advertised as supported_versions = [1] in HELLO. A
server that negotiates any other version raises VersionMismatch rather than
being best-effort decoded.
Verify the install
from brain_db_sdk import BrainHttpClient
import os
brain = BrainHttpClient(api_key=os.environ["BRAIN_API_KEY"])
print(brain.whoami())
print(brain.capabilities())whoami is the cheapest round trip that proves the key, the base URL and the
network path all work at once.
Was this page helpful?