Skip to main content

1MBrain Python SDK

Python client for the 1MBrain REST API — a portable, semantic graph memory layer for AI agents.

Installation

# Sync client (zero extra dependencies — uses stdlib urllib)
pip install onemillionbrain

# Async client (requires httpx)
pip install onemillionbrain[async]

Quick Start

Sync

from onemillionbrain import OneMBrainClient

client = OneMBrainClient(
    api_url="http://localhost:3001",
    api_key="your-api-key",
    agent_id="my-agent",
)

# Store a memory
memory = client.remember("User prefers Bahasa Indonesia as primary language", type="semantic")
print(memory.id)

# Search memories
results = client.recall("language preference", limit=5)
for r in results:
    print(f"[{r.score:.3f}] {r.memory.content}")

# Create an explicit association
client.associate(results[0].memory.id, results[1].memory.id, strength=0.8)

# Forget a memory
client.forget(memory.id)

Async

import asyncio
from onemillionbrain import AsyncOneMBrainClient

async def main():
    async with AsyncOneMBrainClient(
        api_url="http://localhost:3001",
        api_key="your-api-key",
        agent_id="my-agent",
    ) as client:
        memory = await client.remember("User asked about pricing on 2026-06-10", type="episodic")
        results = await client.recall("pricing questions")
        await client.forget(memory.id)

asyncio.run(main())

Agent Integration

To ensure your LLM agent knows exactly how and when to use 1MBrain, the SDK exports a pre-written AGENT_SYSTEM_PROMPT. Inject this into your agent's system instructions.

from onemillionbrain import AGENT_SYSTEM_PROMPT

system_instruction = f"""
You are a helpful AI assistant.
{AGENT_SYSTEM_PROMPT}
"""

# Pass system_instruction to LangChain, OpenAI, Anthropic, etc.

LangChain Integration

from langchain.tools import tool
from onemillionbrain import OneMBrainClient

brain = OneMBrainClient(
    api_url="http://localhost:3001",
    api_key="your-api-key",
    agent_id="langchain-agent",
)

@tool
def remember_tool(content: str) -> str:
    """Store something in long-term memory."""
    memory = brain.remember(content, type="episodic")
    return f"Stored memory: {memory.id}"

@tool
def recall_tool(query: str) -> str:
    """Search long-term memory."""
    results = brain.recall(query, limit=5)
    if not results:
        return "No memories found."
    return "\n".join(f"- {r.memory.content}" for r in results)

API Reference

OneMBrainClient(api_url, api_key, agent_id=None)

Parameter Type Description
api_url str Base URL of the 1MBrain API (e.g. http://localhost:3001)
api_key str Your API key (passed as X-API-Key header)
agent_id str Default agent namespace (can be overridden per call)

Methods

Method Signature Returns
remember (content, *, type, importance, tags, metadata, agent_id) Memory
recall (query, *, limit, type, tags, max_hops, activation_threshold, blend_weight, agent_id, cross_agent) list[RecallResult]
forget (memory_id, *, agent_id) bool
associate (source_id, target_id, *, strength, origin, agent_id) AssociateResult

Development

pip install -e ".[dev]"
pytest

Metadata

Release files for onemillionbrain 0.1.10

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for onemillionbrain 0.1.10
File Size Uploaded
onemillionbrain-0.1.10.tar.gz 12.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for onemillionbrain 0.1.10
File Interpreter ABI Platform
onemillionbrain-0.1.10-py3-none-any.whl Python 3 none any Details

Total release size: 27.0 kB

Release files / onemillionbrain-0.1.10.tar.gz

Download URL onemillionbrain-0.1.10.tar.gz
Size 12.7 kB
Tags Source
SHA-256 checksum
How to use checksums
bbddd3600704744bd7ab7d7374b762fa412d6261a0b41d55ea8b0e7a23609df3
BLAKE2b-256 checksum
How to use checksums
4ad5d553c8addbe9bb712979d7786a5e1762dca6dd72318ab1da13c3df207cf2
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.0

Release files / onemillionbrain-0.1.10-py3-none-any.whl

Download URL onemillionbrain-0.1.10-py3-none-any.whl
Size 14.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
315ddf2d4a80b3a6516358bcc007ae506c6128a848c21ec38631c87bc077476f
BLAKE2b-256 checksum
How to use checksums
626ac0b5ed85c03be6ce75f8271f24476f45195abee7670b12bb097c04ad6a2f
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.11.0

Release history Release notifications | RSS feed

This release

0.1.10 This release

2 release files

0.1.9

2 release files

0.1.8

2 release files

0.1.7

2 release files

0.1.6

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page