CrazyMemory Python SDK
The official Python SDK for CrazyMemory (Neural Fabric X) - The Universal Memory Layer for AI Agents.
Installation
pip install crazymemory
Or with MCP support:
pip install crazymemory[mcp]
Quick Start
from crazymemory import CrazyMemory
# Initialize the client
memory = CrazyMemory(
api_url="http://localhost:8000",
api_key="cm_your_api_key_here" # Get from https://app.crazymemory.ai/api-keys
)
# Store a memory
memory.store(
content="User prefers dark mode in all applications",
metadata={"type": "preference", "category": "ui"}
)
# Search memories
results = memory.search("user preferences", limit=5)
for result in results:
print(result.content)
# Get context for a prompt
context = memory.get_context(
query="What are the user's UI preferences?",
max_tokens=2000
)
print(context)
One-Line Integration
Make any AI "CrazyMemory-aware" with a single decorator:
from crazymemory import fabric_aware
@fabric_aware
def my_ai_function(prompt):
# Your AI logic here
# Context is automatically injected
return response
# Or use the quick sync helper
from crazymemory import quick_sync
# Sync before starting a conversation
context = quick_sync("What should I know about this user?")
Core Features
Memory Operations
from crazymemory import CrazyMemory
memory = CrazyMemory()
# Store with metadata
memory.store(
content="API uses port 8765",
metadata={
"type": "fact",
"project": "neural-fabric",
"tags": ["api", "config"]
}
)
# Semantic search
results = memory.search("configuration settings")
# Get recent memories
recent = memory.get_recent(limit=10)
# Update a memory
memory.update("mem_abc123", content="Updated content")
# Delete a memory
memory.delete("mem_abc123")
Context Building
# Build context for AI prompts
context = memory.build_context(
query="Help me with authentication",
max_tokens=4000,
include_recent=True
)
# NFP (Neural Fabric Protocol) context
nfp_context = memory.get_nfp_context(
query="What are the coding standards?",
agent_id="my-agent",
include_project=True
)
Agent Management
# Register your agent
memory.register_agent(
agent_id="my-python-agent",
name="Python Assistant",
capabilities=["code_generation", "debugging"]
)
# Add notes for other agents
memory.add_agent_note(
agent_id="my-python-agent",
content="Currently working on auth module",
type="current_work"
)
# Get notes from all agents
notes = memory.get_agent_notes()
Conflict Detection
# Check for conflicts before storing
conflicts = memory.check_conflicts(
content="We should use Redux for state management"
)
if conflicts.has_conflicts:
print("Warning: This conflicts with existing memories!")
for conflict in conflicts.items:
print(f" - {conflict.content}")
else:
memory.store(content="We should use Redux for state management")
Sync Operations
# Manual sync
memory.sync(direction="bidirectional")
# Get sync status
status = memory.get_sync_status()
print(f"Last sync: {status.last_sync}")
print(f"Cloud connected: {status.cloud_connected}")
MCP Integration
Use CrazyMemory as an MCP server with Claude Desktop:
from crazymemory import install_mcp_server
# Install to Claude Desktop configuration
install_mcp_server()
Or use the MCP client directly:
from crazymemory import MCPClient
mcp = MCPClient()
# Call MCP tools
result = await mcp.call_tool("fabric_search", {"query": "user preferences"})
Configuration
from crazymemory import CrazyMemory
memory = CrazyMemory(
base_url="http://localhost:8765", # API endpoint
api_key="your-api-key", # Optional API key
timeout=30, # Request timeout
auto_sync=True # Auto-sync on changes
)
Environment Variables
export CRAZYMEMORY_URL="http://localhost:8765"
export CRAZYMEMORY_API_KEY="your-api-key"
Examples
Conversation Memory
from crazymemory import CrazyMemory
memory = CrazyMemory()
# At the start of a conversation, get context
context = memory.build_context("Starting new coding session")
# During the conversation, store important information
memory.store(
content="User wants to build a REST API with FastAPI",
metadata={"type": "requirement", "session": "current"}
)
# At the end, sync everything
memory.sync()
Multi-Agent Workflow
from crazymemory import CrazyMemory
# Agent 1: Cursor
cursor_memory = CrazyMemory()
cursor_memory.register_agent("cursor", "Cursor IDE")
cursor_memory.store(
content="Implementing user authentication",
metadata={"agent": "cursor", "type": "current_work"}
)
# Agent 2: Claude (later)
claude_memory = CrazyMemory()
claude_memory.register_agent("claude", "Claude Chat")
# Claude can see what Cursor was working on
context = claude_memory.build_context("What was the last task?")
# Returns: "Cursor was implementing user authentication..."
API Reference
CrazyMemory Class
| Method | Description |
|---|---|
store(content, metadata) |
Store a new memory |
search(query, limit, filter) |
Semantic search |
get_recent(limit) |
Get recent memories |
update(id, content, metadata) |
Update a memory |
delete(id) |
Delete a memory |
build_context(query, max_tokens) |
Build context for prompts |
register_agent(agent_id, name) |
Register an agent |
add_agent_note(agent_id, content) |
Add agent note |
check_conflicts(content) |
Check for conflicts |
sync(direction) |
Sync with cloud |
Requirements
- Python 3.8+
requestslibrary- Optional:
mcplibrary for MCP integration
License
MIT License - see LICENSE for details.
Links
Metadata
Release files for crazymemory 1.0.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| crazymemory-1.0.0.tar.gz | 11.6 kB | Without provenance | Details for crazymemory-1.0.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| crazymemory-1.0.0-py3-none-any.whl | Python 3 | none | any | Details for crazymemory-1.0.0-py3-none-any.whl |
Total release size: 21.3 kB
Release files / crazymemory-1.0.0.tar.gz
| Download URL | crazymemory-1.0.0.tar.gz |
|---|---|
| Size | 11.6 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
97f8151a705e97248015ee2fec49b159561021142fb09b09536f3fe2002fc915
|
|
BLAKE2b-256 checksum How to use checksums |
65ace19a50c2f5cb1326a4adccbe696702e61b67c90fcf610ff1716e44bed580
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|
Release files / crazymemory-1.0.0-py3-none-any.whl
| Download URL | crazymemory-1.0.0-py3-none-any.whl |
|---|---|
| Size | 9.6 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
a656ef3aefaddfeb7509c992c1e7ebb60123ca9c7a433b80b4c6ab2726b9bf2f
|
|
BLAKE2b-256 checksum How to use checksums |
8e4ce35e166175756dfe81f877b453d740dd80d12c85291ada00c54208d220cb
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/6.2.0 CPython/3.14.0
|
Security for crazymemory 1.0.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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
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.