Skip to main content

AI memory for every app. Store, search, and chat with persistent memory.

Project description

HeroBrain Python SDK

AI memory for every app. Give your AI persistent, searchable memory in 3 lines of code.

Install

pip install herobrain

Quick start

from herobrain import HeroBrainMemory

m = HeroBrainMemory(api_key="hb_...")

# Store a memory
m.add("User prefers dark mode and uses Python 3.12")

# Search memories
results = m.search("what programming language?")
print(results[0]["memory"]["content"])
# → "User prefers dark mode and uses Python 3.12"

# Chat with memory context
reply = m.chat("What do you know about my preferences?")
print(reply["response"])

That's it. HeroBrain handles embedding, dedup, hybrid search, and fact extraction automatically.

Configuration

from herobrain import HeroBrainMemory

# Pass the key directly
m = HeroBrainMemory(api_key="hb_...")

# Or set an environment variable
# export HEROBRAIN_API_KEY=hb_...
m = HeroBrainMemory()

# Self-hosted
m = HeroBrainMemory(
    api_key="hb_...",
    base_url="https://your-instance.example.com",
)

Memories

# Add a memory (auto-extracts facts, deduplicates, and classifies)
memories = m.add("I have a meeting with Jake tomorrow at 2pm")

# Add with options
memories = m.add(
    "Alice lives in Portland",
    agent_id="user-alice",       # isolate per user
    type="identity",             # semantic, episodic, identity, preference, task, procedural
    importance=0.9,
    metadata={"source": "onboarding"},
    expires_at="2026-12-31T00:00:00Z",  # auto-cleanup
)

# Search
results = m.search("where does alice live?", agent_id="user-alice")

# List all
all_memories = m.list(limit=50, agent_id="user-alice")

# Get one
memory = m.get("memory-uuid")

# Update
m.update("memory-uuid", content="Alice moved to Seattle")

# Delete
m.delete("memory-uuid")

# History (audit trail)
history = m.history("memory-uuid")

Chat

Memory-grounded conversations with streaming support.

# Simple chat
reply = m.chat("What meetings do I have?")
print(reply["response"])
print(reply["memoryReferences"])  # which memories were used

# Streaming
for event in m.chat_stream("Tell me about my week"):
    if event["type"] == "text":
        print(event["content"], end="", flush=True)

# Scoped to a user
reply = m.chat("What's my name?", agent_id="user-alice")

Multi-user / multi-agent

Use agent_id to isolate memory per user, agent, or session — just like Stripe uses customer_id.

# Each user gets their own memory space
m.add("Loves hiking", agent_id="user-42")
m.add("Prefers email", agent_id="user-42")

# Only searches user-42's memories
results = m.search("hobbies", agent_id="user-42")

# Chat with user-42's context only
reply = m.chat("What do I like?", agent_id="user-42")

Async

from herobrain import AsyncHeroBrainMemory

async def main():
    m = AsyncHeroBrainMemory(api_key="hb_...")
    
    memories = await m.add("User signed up for Pro plan")
    results = await m.search("plan")
    reply = await m.chat("What plan am I on?")
    
    await m.close()

Error handling

from herobrain import HeroBrainMemory, HeroBrainAuthError, HeroBrainRateLimitError

m = HeroBrainMemory(api_key="hb_...")

try:
    m.search("hello")
except HeroBrainAuthError:
    print("Bad API key")
except HeroBrainRateLimitError as e:
    print(f"Rate limited. Retry after {e.retry_after}s")

Get your API key

  1. Go to herobrain.app
  2. Create an account
  3. Go to API Keys and generate one
  4. pip install herobrain and start building

Links

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

herobrain-0.1.1.tar.gz (9.6 kB view details)

Uploaded Source

Built Distribution

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

herobrain-0.1.1-py3-none-any.whl (8.4 kB view details)

Uploaded Python 3

File details

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

File metadata

  • Download URL: herobrain-0.1.1.tar.gz
  • Upload date:
  • Size: 9.6 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for herobrain-0.1.1.tar.gz
Algorithm Hash digest
SHA256 3224d5740e2b2a5336434fdd8e13163f476ed2cc13ef3b1b89c23b29ce5cafd4
MD5 2ade973c1d6b80547f0771ae29308d7e
BLAKE2b-256 85cfc11c7b4f2334efe6d6b7e76b1af45cda36ef6b68c8d7b40ea477392d773f

See more details on using hashes here.

File details

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

File metadata

  • Download URL: herobrain-0.1.1-py3-none-any.whl
  • Upload date:
  • Size: 8.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.0

File hashes

Hashes for herobrain-0.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 857ffc9f680fa6319f461bc783d5d991a67ccab12a914c28c852270164c8d19c
MD5 de4762550ddfbad3cf8dd0009ee97585
BLAKE2b-256 9b5bd01fb5948c77e72f887163185657a5d0ae154a360c51bd7e4c9afe954c98

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