Python SDK for the ai-memory HTTP API (persistent memory for AI agents).
Project description
ai-memory — Python SDK
Typed Python client for the ai-memory
HTTP API. Wraps the daemon's /api/v1/ surface with sync and async clients,
Pydantic v2 models that mirror the Rust structs, and HMAC-SHA256 webhook
verification.
Status: 0.6.0-alpha.0 — scaffolding, unpublished. API may change before
GA.
Install
# Not yet published; install from a local checkout:
pip install -e ./sdk/python
Requires Python 3.10+.
Quickstart
from ai_memory import AiMemoryClient, Tier
with AiMemoryClient(base_url="http://localhost:9077") as client:
created = client.store(
title="BIND9 build notes",
content="Use --with-openssl=/opt/openssl, disable DoH for the lab.",
tier=Tier.LONG,
tags=["dns", "bind9"],
)
print(created["id"])
hits = client.recall(context="how do I build BIND9?")
for memory in hits.memories:
print(memory.title, memory.confidence)
Async
import asyncio
from ai_memory import AsyncAiMemoryClient
async def main() -> None:
async with AsyncAiMemoryClient(base_url="http://localhost:9077") as client:
resp = await client.recall(context="hello")
for memory in resp.memories:
print(memory.title)
asyncio.run(main())
Authentication
API key
AiMemoryClient(base_url="https://memory.example.com", api_key="sk-...")
The key is sent as the X-API-Key header on every request. The server
exempts /api/v1/health from auth.
mTLS
AiMemoryClient(
base_url="https://memory.example.com",
verify="/etc/ssl/certs/server-ca.pem",
cert=("/etc/ssl/client/client.pem", "/etc/ssl/client/client.key"),
)
Agent identity (NHI)
Set agent_id to stamp the X-Agent-Id header on every request. The
server writes metadata.agent_id accordingly (see CLAUDE.md §Agent
Identity).
AiMemoryClient(base_url="http://localhost:9077", agent_id="ai:claude-opus-4.7@host")
All methods
| Method | Endpoint | Notes |
|---|---|---|
health() |
GET /api/v1/health |
Exempt from auth. |
metrics() |
GET /api/v1/metrics |
Prometheus text format. |
store(...) |
POST /api/v1/memories |
Upsert on (title, namespace). |
bulk_store([...]) |
POST /api/v1/memories/bulk |
Up to 1000 per call. |
get(id) |
GET /api/v1/memories/{id} |
Returns Memory. |
update(id, UpdateMemory) |
PUT /api/v1/memories/{id} |
Partial update. |
delete(id) |
DELETE /api/v1/memories/{id} |
|
promote(id) |
POST /api/v1/memories/{id}/promote |
Tier -> long. |
list(...) |
GET /api/v1/memories |
Filters: namespace, tier, tags, agent_id. |
search(q, ...) |
GET /api/v1/search |
FTS AND search. |
recall(context, ...) |
POST /api/v1/recall |
Hybrid semantic + FTS. |
forget(...) |
POST /api/v1/forget |
Bulk delete by pattern. |
link(a, b, relation) |
POST /api/v1/links |
related_to, supersedes, contradicts, derived_from. |
get_links(id) |
GET /api/v1/links/{id} |
|
stats() |
GET /api/v1/stats |
|
namespaces() |
GET /api/v1/namespaces |
|
gc() |
POST /api/v1/gc |
|
export() / import_() |
GET / `POST /api/v1/export |
import` |
subscribe(req) / unsubscribe(id) / subscriptions() |
/api/v1/subscriptions |
Webhook mgmt. |
notify(req) / inbox(...) |
/api/v1/notify, /api/v1/inbox |
Agent-to-agent messaging. |
grant(id, agent) / revoke(id, agent) |
`/api/v1/memories/{id}/grant | revoke` |
cluster(req) |
POST /api/v1/cluster |
Peer management. |
agents() / register_agent(...) |
/api/v1/agents |
NHI registry. |
Webhook verification
from ai_memory import verify_webhook_signature
def handle(request) -> None:
sig = request.headers["X-AI-Memory-Signature"]
if not verify_webhook_signature(request.body, sig, secret="..."):
raise PermissionError("bad signature")
...
body must be the raw bytes as received — do not re-encode a parsed JSON
payload; whitespace differences will break the HMAC.
Errors
All SDK errors derive from AiMemoryError:
| Exception | HTTP |
|---|---|
ValidationError |
400 |
AuthError |
401 |
ForbiddenError |
403 |
NotFoundError |
404 |
ConflictError |
409 |
RateLimitError |
429 |
ServerError |
5xx |
TransportError |
network failure |
License
Apache-2.0, see LICENSE.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file ai_memory_mcp-0.6.4.tar.gz.
File metadata
- Download URL: ai_memory_mcp-0.6.4.tar.gz
- Upload date:
- Size: 20.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
47c87a4e22d30d337cc8bdab6ad0ca36e6fa56b028f77108248b30482082a47e
|
|
| MD5 |
26fdec3d1467f9e6bbfc1548bb9ace8f
|
|
| BLAKE2b-256 |
530d3ea4967d7419aaffea573939d7bfca6ed69ac22e5a8c4edcea4f8c84a763
|
Provenance
The following attestation bundles were made for ai_memory_mcp-0.6.4.tar.gz:
Publisher:
publish-sdks.yml on alphaonedev/ai-memory-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ai_memory_mcp-0.6.4.tar.gz -
Subject digest:
47c87a4e22d30d337cc8bdab6ad0ca36e6fa56b028f77108248b30482082a47e - Sigstore transparency entry: 1440104272
- Sigstore integration time:
-
Permalink:
alphaonedev/ai-memory-mcp@0955a77acb343213e7852b1c448761dd1981ec72 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/alphaonedev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdks.yml@0955a77acb343213e7852b1c448761dd1981ec72 -
Trigger Event:
workflow_dispatch
-
Statement type:
File details
Details for the file ai_memory_mcp-0.6.4-py3-none-any.whl.
File metadata
- Download URL: ai_memory_mcp-0.6.4-py3-none-any.whl
- Upload date:
- Size: 21.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b9dcfbd58fff3f0b302a7e92d0e273c0644321b2ac1125c4ae55f465024e84fa
|
|
| MD5 |
93bb0e38ae72e1c06b40e91c8f43843e
|
|
| BLAKE2b-256 |
a526261efe969f73814bf05f9df8538fb98543f231e4ba2840ce7187f62c6a92
|
Provenance
The following attestation bundles were made for ai_memory_mcp-0.6.4-py3-none-any.whl:
Publisher:
publish-sdks.yml on alphaonedev/ai-memory-mcp
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
ai_memory_mcp-0.6.4-py3-none-any.whl -
Subject digest:
b9dcfbd58fff3f0b302a7e92d0e273c0644321b2ac1125c4ae55f465024e84fa - Sigstore transparency entry: 1440104289
- Sigstore integration time:
-
Permalink:
alphaonedev/ai-memory-mcp@0955a77acb343213e7852b1c448761dd1981ec72 -
Branch / Tag:
refs/heads/main - Owner: https://github.com/alphaonedev
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-sdks.yml@0955a77acb343213e7852b1c448761dd1981ec72 -
Trigger Event:
workflow_dispatch
-
Statement type: