Skip to main content

MenteDB Python SDK

Python bindings for MenteDB, the mind database for AI agents. Built with PyO3 and maturin for native Rust performance from Python.

Installation

From PyPI

pip install mentedb

Prebuilt wheels are published for macOS arm64, Linux x86_64 and aarch64, and Windows x86_64 (Python 3.9+).

From source (development)

cd sdks/python
pip install maturin
maturin develop

On Debian and Ubuntu systems pip refuses system wide installs (PEP 668). Use a virtual environment or pipx:

python3 -m venv .venv && .venv/bin/pip install mentedb
# or: pipx install mentedb

Quick start

from mentedb import MenteDB, MemoryType, EdgeType

with MenteDB("./agent-memory") as db:
    # process_turn — the primary API, one call does everything
    result = db.process_turn(
        user_message="The deployment failed because the config was missing",
        assistant_response="I'll check the config setup.",
        turn_id=0,
    )
    # result.context — relevant memories for your prompt
    # result.facts_extracted — what was learned this turn
    # result.contradiction_count — conflicting beliefs detected
    # Optional kwargs: project_context, agent_id, session_id (tags stored
    # turns so injection recall can exclude the requesting session), user_id
    # (agent_id and user_id must be UUID strings)

    # Enrichment (LLM fact extraction, entity linking, community summaries,
    # user profile) is a separate call; see "Sleeptime enrichment" below.

    # Or use low-level APIs directly:

    # Store a memory
    mid = db.store(
        "The deployment failed because the config was missing",
        memory_type=MemoryType.EPISODIC,
        tags=["deployment", "config"],
    )

    # Recall memories with MQL
    result = db.recall("RECALL tag:deployment LIMIT 5")
    print(result.text)

    # Vector similarity search
    hits = db.search(embedding=[0.1] * 384, k=5)
    for hit in hits:
        print(f"{hit.id}: {hit.score:.4f}")

    # Relate memories
    mid2 = db.store("Always validate config before deploy", memory_type=MemoryType.PROCEDURAL)
    db.relate(mid, mid2, edge_type=EdgeType.CAUSED)

    # Forget a memory
    db.forget(mid)

MenteDB Cloud (hosted)

Prefer a managed API with no engine to run? Use MenteDBClient with an mdb_ key from app.mentedb.com. The verbs mirror the embedded client, so only the constructor changes.

from mentedb import MenteDBClient

client = MenteDBClient(api_key="mdb_...")

# Turn 0: tell it something.
client.process_turn("I switched from Postgres to SQLite for side projects", "Noted.", 0)

# Turn 1: it remembers.
result = client.process_turn("what database am I using for side projects?", "", 1)
for memory in result.context:
    print(memory.content)

# Also available: client.search(...), client.store(...),
# client.store_multimodal(data, media_type=...), client.forget(memory_id)

MenteDBClient is pure standard library (no extra dependencies) and talks to https://api.mentedb.com. process_turn uses the REST endpoint, while store, search, store_multimodal, and forget use the hosted MCP tools.

Claude memory tool backend

MemoryTool backs Claude's client side memory tool (memory_20250818) with a mentedb-server (or MenteDB Cloud, through MenteDBClient.memory_tool()). Each /memories file is a memory scoped to the agent. Standard library only:

from mentedb import MemoryTool

memory = MemoryTool("http://localhost:6677", token, agent_id="...")
# tools=[MemoryTool.TOOL] on the Messages API request, then each turn:
messages.append({"role": "user", "content": memory.results(response.content)})

See the memory tool guide and examples/memory_tool_agent.py.

Cognitive features

The SDK also exposes MenteDB cognitive subsystems for real time stream monitoring, conversation trajectory tracking, and pain signal management.

Sleeptime Enrichment

The embedded SDK does not enrich on its own. process_turn marks when enrichment is due; check db.needs_enrichment() and call db.run_enrichment() (for example from a background worker). The pipeline extracts semantic facts, links and deduplicates entities, groups them into communities with summaries, and builds a user profile, all of which feed later process_turn context retrieval.

Requires an LLM provider: set MENTEDB_LLM_PROVIDER (openai, anthropic or ollama) and MENTEDB_LLM_API_KEY. Without them the engine works normally and run_enrichment raises an error.

Cognitive subsystems

import uuid
from mentedb._mentedb_python import CognitionStream, TrajectoryTracker, PainRegistry

# Stream monitoring (fact ids must be UUID strings)
fact_id = str(uuid.uuid4())
stream = CognitionStream(buffer_size=500)
stream.feed_token("The")
stream.feed_token(" sky")
alerts = stream.check_alerts([(fact_id, "the sky is blue")])

# Trajectory tracking
tracker = TrajectoryTracker(max_turns=50)
tracker.record_turn("deployment", "investigating", ["which env?"])
context = tracker.get_resume_context()

# Pain registry
pain = PainRegistry(max_warnings=3)
pain.record_pain(str(uuid.uuid4()), 0.8, ["timeout", "deploy"], "deploy timed out")
warnings = pain.check_triggers(["deploy"])

API reference

MenteDB

Method Description
process_turn(user_message, assistant_response, turn_id, project_context, agent_id, session_id, user_id) Primary API. Process a conversation turn through the full cognitive pipeline
store(content, memory_type, embedding, agent_id, tags, created_at) Store a memory, returns its UUID
recall(query) Recall memories using MQL
search(embedding, k) Vector similarity search
search_text(query, k, tags, after, before) Similarity search with the configured embedding provider
get_memory(memory_id) Fetch one memory as a dict
relate(source, target, edge_type, weight, valid_from, valid_until) Add a relationship
forget(memory_id) Remove a memory
needs_enrichment() / run_enrichment(provider, current_turn) Check for and run sleeptime enrichment (needs an LLM)
close() Flush and close the database

Only one MenteDB instance can hold a data directory at a time; opening the same directory again raises a "locked by another process" error.

Types

MemoryType: episodic, semantic, procedural, anti_pattern, reasoning, correction

EdgeType: caused, before, related, contradicts, supports, supersedes, derived, part_of

License

Apache 2.0. See the repository root LICENSE file for details.

Metadata

Release files for mentedb 0.48.0

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

Built distributions (wheels)

Table of built distributions (wheels) for mentedb 0.48.0
File Actions
mentedb-0.48.0-cp39-abi3-win_amd64.whl CPython 3.9 abi3 Windows x86-64 Details for mentedb-0.48.0-cp39-abi3-win_amd64.whl
mentedb-0.48.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl CPython 3.9 abi3 Linux glibc 2.17+ x86-64 Details for mentedb-0.48.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
mentedb-0.48.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl CPython 3.9 abi3 Linux glibc 2.17+ ARM64 Details for mentedb-0.48.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
mentedb-0.48.0-cp39-abi3-macosx_11_0_arm64.whl CPython 3.9 abi3 macOS 11.0+ ARM64 Details for mentedb-0.48.0-cp39-abi3-macosx_11_0_arm64.whl

Total release size: 33.0 MB

Release files / mentedb-0.48.0-cp39-abi3-win_amd64.whl

Download URL mentedb-0.48.0-cp39-abi3-win_amd64.whl
Size 6.3 MB
Tags CPython 3.9 Windows x86-64 abi3
SHA-256 checksum
How to use checksums
5ddbd0af448926360eaed1aa42a185377eb8f1c5edd5106a5e659a0e8f8a8e02
BLAKE2b-256 checksum
How to use checksums
6d2701b257a78cba3e4852c624f339f66f36b9726982f7037d4aaf69ecbf822a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Release files / mentedb-0.48.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl

Download URL mentedb-0.48.0-cp39-abi3-manylinux2014_x86_64.manylinux_2_17_x86_64.whl
Size 10.0 MB
Tags CPython 3.9 Linux glibc 2.17+ x86-64 abi3
SHA-256 checksum
How to use checksums
0f82bb52f81d680dacf2e181465f235e7160e6f970070615945bede11864c551
BLAKE2b-256 checksum
How to use checksums
cb1005b2111e8477a4e93417e363e55494cec35bebeae6712c40780072596889
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Release files / mentedb-0.48.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl

Download URL mentedb-0.48.0-cp39-abi3-manylinux2014_aarch64.manylinux_2_17_aarch64.whl
Size 10.2 MB
Tags CPython 3.9 Linux glibc 2.17+ ARM64 abi3
SHA-256 checksum
How to use checksums
9bf3f3c8852a143f541d5c7a6bdc7628c461a54ad5b25f9adb80574e8cd94d2e
BLAKE2b-256 checksum
How to use checksums
a621b13d8e2c64b2bb256b352871428041b22ad5fec3cbbb976577f6a2e4ddfd
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Release files / mentedb-0.48.0-cp39-abi3-macosx_11_0_arm64.whl

Download URL mentedb-0.48.0-cp39-abi3-macosx_11_0_arm64.whl
Size 6.5 MB
Tags CPython 3.9 abi3 macOS 11.0+ ARM64
SHA-256 checksum
How to use checksums
94bed1087b0a0b86ef1de1cad0c3a9ad0a93e6496432cafd6faec28498b7ef31
BLAKE2b-256 checksum
How to use checksums
42b228b7644db15ad1abfcbafbe4fcfe429edccd58c1ea0795e8e58a069718b7
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

Security for mentedb 0.48.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

All 4 files in this release have been uploaded with provenance metadata.

Select from 4 files

Attestation for mentedb-0.48.0-cp39-abi3-win_amd64.whl

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Nov 9, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.48.0 This release

4 release files Full provenance

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