Quickstart: Python

The Python SDK is a hand-written sync and async client over httpx. It needs Python 3.9 or later and a running server.

⚠️

The SDK is named mnemo-ai-sdk and is not on PyPI yet. The package called mnemosyne-sdk on PyPI belongs to an unrelated project: do not install it.

Start a server and mint a key

Follow the Docker quickstart until curl http://localhost:3939/health/ready reports every check as ok, then mint a key:

docker compose exec server node scripts/create-api-key.cjs --label "python"

Install the SDK from the repository

pip install "git+https://github.com/lucasmailland/mnemosyne.git#subdirectory=packages/sdk-python"

First call

app.py
from mnemo import MnemosyneClient
 
client = MnemosyneClient(
    url="http://localhost:3939",
    api_key="mns_live_...",
)
 
client.create_fact("Acme prefers communication in Spanish.", tags=["language"])
 
result = client.recall("what language should we use with Acme?", top_k=3)
for hit in result["hits"]:
    print(hit["score"], hit["content"])

Every method returns a plain dict that matches the server’s JSON.

Async variant

AsyncMnemosyneClient has the same method names. Add await.

app_async.py
import asyncio
from mnemo import AsyncMnemosyneClient
 
async def main() -> None:
    async with AsyncMnemosyneClient(
        url="http://localhost:3939",
        api_key="mns_live_...",
    ) as client:
        result = await client.recall("what language should we use with Acme?", top_k=3)
        for hit in result["hits"]:
            print(hit["score"], hit["content"])
 
asyncio.run(main())

FastAPI integration

main.py
from fastapi import FastAPI, Depends
from mnemo import MnemosyneClient
 
app = FastAPI()
 
def get_memory():
    return MnemosyneClient(
        url="http://localhost:3939",
        api_key="mns_live_...",
    )
 
@app.post("/agents/recall")
def agent_recall(query: str, client: MnemosyneClient = Depends(get_memory)):
    return client.recall(query, top_k=5)

Constructor

MnemosyneClient(
    url,                      # required: server base URL
    api_key,                  # required: sent as a bearer token
    timeout=30.0,             # per-request timeout in seconds
    user_agent_suffix=None,   # appended to the User-Agent header
    max_retries=3,            # extra attempts on 429, 500, 502, 503 and 504
)

AsyncMnemosyneClient takes the same parameters.

LangChain and LlamaIndex

The package ships no LangChain or LlamaIndex adapter today. Call MnemosyneClient from your own retriever or memory class.