Skip to main content

Python client SDK for the 1MBrain REST API — portable memory layer for AI agents.

Project description

1MBrain Python SDK

Python client for the 1MBrain REST API — a portable, holographic 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) list[RecallResult]
forget (memory_id, *, agent_id) bool
associate (source_id, target_id, *, strength, origin, agent_id) AssociateResult

Development

pip install -e ".[dev]"
pytest

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

onemillionbrain-0.1.1.tar.gz (12.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

onemillionbrain-0.1.1-py3-none-any.whl (12.8 kB view details)

Uploaded Python 3

File details

Details for the file onemillionbrain-0.1.1.tar.gz.

File metadata

  • Download URL: onemillionbrain-0.1.1.tar.gz
  • Upload date:
  • Size: 12.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.17.0 {"ci":null,"cpu":"AMD64","implementation":{"name":"CPython","version":"3.11.0"},"installer":{"name":"hatch","version":"1.17.0"},"openssl_version":"OpenSSL 1.1.1q 5 Jul 2022","python":"3.11.0","system":{"name":"Windows","release":"10"}} HTTPX2/2.4.0

File hashes

Hashes for onemillionbrain-0.1.1.tar.gz
Algorithm Hash digest
SHA256 f5d01bc37487f254976bb1d4b60edd2ed6b341b4d281a59e6169eb4c0358fc74
MD5 105ca548e53543fb7ce4c97cd755d4e3
BLAKE2b-256 bc778adcc1d606a0ef5543c60ce39ec22fe9a94b60e3fd85a8afd9ef9e56465a

See more details on using hashes here.

File details

Details for the file onemillionbrain-0.1.1-py3-none-any.whl.

File metadata

  • Download URL: onemillionbrain-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 12.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: Hatch/1.17.0 {"ci":null,"cpu":"AMD64","implementation":{"name":"CPython","version":"3.11.0"},"installer":{"name":"hatch","version":"1.17.0"},"openssl_version":"OpenSSL 1.1.1q 5 Jul 2022","python":"3.11.0","system":{"name":"Windows","release":"10"}} HTTPX2/2.4.0

File hashes

Hashes for onemillionbrain-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 42f42a6337f2cf1ac99187eecd2f8ba54016e604c13be3d1af300c453af1ae32
MD5 490ad0c7e8e1507ca00ff3794b80f126
BLAKE2b-256 720cccd2bdc0d2809f5871e0ae3a8b2d1cec3a85930ec5f66eeef5f7b977adb2

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page