Official Python SDK for Memgraph - the memory graph for AI agents
Project description
Memgraph SDK
The official Python SDK for Memgraph -- the memory graph for AI agents.
Installation
pip install memgraph-sdk
For async support:
pip install "memgraph-sdk[async]"
Quick Start
from memgraph_sdk import MemgraphClient
client = MemgraphClient(
api_key="mg_your_api_key",
tenant_id="your-tenant-id",
)
# Store a memory
client.add(
text="User prefers dark mode and uses PyTorch.",
user_id="user_123",
)
# Search for relevant context
result = client.search(
query="What does this user prefer?",
user_id="user_123",
)
print(result)
Async Client
from memgraph_sdk import AsyncMemgraphClient
async with AsyncMemgraphClient(
api_key="mg_your_api_key",
tenant_id="your-tenant-id",
) as client:
await client.add("User prefers dark mode", user_id="user_123")
result = await client.search("user preferences", user_id="user_123")
Memory Intelligence API
# Memory health metrics
health = client.health(user_id="user_123")
# Detect contradictions
contradictions = client.contradictions(user_id="user_123")
# Evaluate retrieval quality
evaluation = client.evaluate(query="test query", user_id="user_123")
# Cognitive Integrity Score (0-100)
score = client.mcis(user_id="user_123")
# Run benchmarks
result = client.benchmark(scenario="contradiction_storm")
scenarios = client.benchmark_scenarios()
CLI
# Initialize Memgraph in your project
memgraph init
# Store a memory
memgraph remember "We decided to use PostgreSQL" -c decision
# Search memories
memgraph recall "database choice"
# Check connection
memgraph status
Configuration
The client reads the API URL from the MEMGRAPH_API_URL environment variable, defaulting to http://localhost:8001/v1. You can also pass it explicitly:
client = MemgraphClient(
api_key="mg_your_key",
tenant_id="your-tenant-id",
base_url="https://api.memgraph.ai/v1",
)
Examples
See the examples/ directory for complete integration examples:
- Quick Start -- Basic add and search
- Agent Integration -- OpenAI-powered agent with memory
- MCP Server -- Model Context Protocol server for Claude/Cursor
- LangChain -- LangChain integration
- OpenAI -- OpenAI integration
- Benchmarks -- Performance benchmarking
License
MIT License. See LICENSE for details.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file memgraph_sdk-0.1.0.tar.gz.
File metadata
- Download URL: memgraph_sdk-0.1.0.tar.gz
- Upload date:
- Size: 8.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
eaa00104de2639abd8d11a016cfb603ecba4b2d6e693b6c6e8139e8049b4e874
|
|
| MD5 |
346949b1444ba1f60156bbda63196414
|
|
| BLAKE2b-256 |
2f67d9be7c35290e4a678ba1403b32365d6d7e8471547350a445757247949796
|
File details
Details for the file memgraph_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: memgraph_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 11.5 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.13.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
959313c51588dadf4c8e5083375e143e557ff3a38c10b4b7c432e82ea9524a15
|
|
| MD5 |
614f178ecb76a8738ca8abb1d1d3dbdf
|
|
| BLAKE2b-256 |
313634f43a4e52027d9e6fbfe1a7fe260a2b2a07093f107ecf6f05d47d43c97c
|