Python SDK¶
The membrick Python package exposes the shared Rust Memory client. It connects to an existing project resident or to a remote HTTP service.
Install¶
The package includes the native binding and the Membrick CLI for supported platforms. You do not need to install or start a separate resident executable.
Connect to a project¶
Pass the project root to connect to its resident. Construction does not create project files. Use Memory.init(...) only when you intentionally want to initialize Membrick state:
from membrick import Memory
memory = Memory(path=".")
receipt = memory.add(
[{"role": "user", "content": "I prefer concise answers."}],
user_id="alice",
)
search = memory.search("How should answers be written?", user_id="alice")
print(search["search_id"], search["data"])
review = memory.review_search(search["search_id"], "alice")
search searches user-scoped memories. To search captured memories and workspace memory, use workspace_search with the provider identity. A project connection uses its connected root as the workspace; a remote connection must pass workspace explicitly:
matches = memory.workspace_search(
"What did we decide about the API?",
provider="codex",
top_k=5,
)
review = memory.review_search(
matches["search_id"],
provider="codex",
)
review_search also handles workspace searches. Supply provider instead of user_id; use workspace and session_id when needed. To page through unreviewed workspace searches, omit search_id and pass provider, optionally with cursor and page_size.
An add receipt includes the resolved request_id, user_id, and session_id. Keep the session ID to continue a conversation across calls:
conversation = memory.session("alice", receipt["session_id"])
conversation.add([{"role": "user", "content": "Use bullet points."}])
search = conversation.search("What answer format do I prefer?")
review = conversation.review_search(search["search_id"])
To create a new project intentionally, initialize it first:
Call close() on clients and sessions when they no longer need to keep the resident warm. Dropping the final handle releases its lease automatically. Later requests can start the resident again.
Connect to a remote service¶
Set base_url to use the HTTP API. Provide api_key when the server requires token authentication:
remote = Memory(
base_url="http://127.0.0.1:8080",
api_key="YOUR_SERVER_TOKEN",
)
search = remote.search("When is the launch?", user_id="alice")
review = remote.review_search(search["search_id"], "alice")
Memory is the same client for project and remote connections. Omitting both path and base_url is a configuration error; the package does not silently select the current directory.
IDs and errors¶
Every call takes an explicit user_id. The client generates a request ID for each new add. If the application persists request IDs to recover from an uncertain response, reuse the same ID only for the same user, session, and messages. MemoryError subclasses retain useful built-in exception types:
| Exception | Meaning |
|---|---|
RejectedError | The service definitively rejected the operation; includes .status for HTTP responses. |
UnavailableError | The service was unavailable before dispatch. |
UncertainError | The request may have been applied; check or retry with the same request ID. |
ConfigurationError | The client options or project setup are invalid. |
The synchronous binding releases the Python GIL while the client performs service work. See the shared Memory API contract for operation signatures and return values, and the Mem0-style adapter guide for its supported Python subset.