MemMachine REST Client - A lightweight Python client library for MemMachine memory system
Project description
MemMachine Client
A Python client library for the MemMachine memory system.
Features
- Simple API: Easy-to-use interface
- Memory Management: Add and search episodic and profile memories
- Context Awareness: Automatic context retrieval for better responses
- Error Handling: Robust error handling with retry mechanisms
- Type Safety: Full type hints for better development experience
Installation
# Install from source (for development)
pip install -e .
# Or install dependencies
pip install requests urllib3
Quick Start
Basic Usage
from memmachine_client import MemMachineClient
# Initialize client
client = MemMachineClient(
base_url="http://localhost:8080",
timeout=30
)
# Create a memory instance
memory = client.memory(
group_id="my_group",
agent_id="my_agent",
user_id="user123",
session_id="session456"
)
# Add memories
memory.add("I like pizza", metadata={"type": "preference"})
memory.add("I work as a software engineer", metadata={"type": "fact"})
# Search memories
results = memory.search("What do I like to eat?")
print(results)
API Reference
MemMachineClient
The main client class for interacting with MemMachine.
Constructor
MemMachineClient(
api_key: Optional[str] = None,
base_url: str = "http://localhost:8080",
timeout: int = 30,
max_retries: int = 3,
**kwargs
)
Methods
memory(group_id, agent_id, user_id, session_id)- Create a Memory instancehealth_check()- Check server health
Memory
Interface for managing episodic and profile memory.
Methods
add(content, producer, produced_for, episode_type, metadata)- Add a memorysearch(query, limit, filter_dict)- Search memoriesget_context()- Get current context
Examples
Basic Memory Operations
from memmachine_client import MemMachineClient
client = MemMachineClient(base_url="http://localhost:8080")
# Create memory instance
memory = client.memory(
group_id="demo_group",
agent_id="demo_agent",
user_id="user123",
session_id="demo_session"
)
# Add memories with metadata
memory.add("I like pizza", metadata={"type": "preference", "category": "food"})
memory.add("I work as a software engineer", metadata={"type": "fact", "category": "work"})
# Search memories
results = memory.search("What do I like to eat?")
print(f"Episodic memory: {results.get('episodic_memory', [])}")
print(f"Profile memory: {results.get('profile_memory', [])}")
# Search with filters
work_results = memory.search("Tell me about work", filter_dict={"category": "work"})
print(f"Work results: {work_results}")
Multiple Users
from memmachine_client import MemMachineClient
client = MemMachineClient(base_url="http://localhost:8080")
# Create memory instances for multiple users
users = ["alice", "bob", "charlie"]
memories = {}
for user in users:
memories[user] = client.memory(
group_id="team_group",
agent_id="team_agent",
user_id=user
)
# Add user-specific memories
memories["alice"].add("I'm a frontend developer", metadata={"role": "frontend"})
memories["bob"].add("I'm a backend developer", metadata={"role": "backend"})
memories["charlie"].add("I'm a DevOps engineer", metadata={"role": "devops"})
# Search across users
for user, memory in memories.items():
results = memory.search("What is your role?")
print(f"{user}: {results}")
Error Handling
from memmachine_client import MemMachineClient
try:
client = MemMachineClient(base_url="http://localhost:8080")
# Check server health
health = client.health_check()
print(f"Server health: {health}")
# Create memory instance
memory = client.memory(
group_id="demo_group",
agent_id="demo_agent",
user_id="user123"
)
# Add memory
memory.add("Test memory")
except Exception as e:
print(f"Error: {e}")
Context Manager Usage
from memmachine_client import MemMachineClient
# Use client as context manager
with MemMachineClient(base_url="http://localhost:8080") as client:
memory = client.memory(
group_id="demo_group",
agent_id="demo_agent",
user_id="user123"
)
memory.add("This is a test memory")
results = memory.search("test")
print(f"Results: {results}")
# Client is automatically closed
Configuration
Environment Variables
MEMORY_BACKEND_URL: Base URL for MemMachine server (default: http://localhost:8080)MEMORY_API_KEY: API key for authentication (optional for local development)
Client Configuration
client = MemMachineClient(
api_key="your_api_key", # Optional
base_url="http://localhost:8080",
timeout=30, # Request timeout in seconds
max_retries=3 # Maximum retries for failed requests
)
Running Examples
# Start MemMachine server first
python -m memmachine_server.server.app
# Run examples
python examples/memmachine_client_example.py
Contributing
Contributions are welcome! Please feel free to submit issues and pull requests.
License
This project is licensed under the same license as MemMachine.
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 memmachine_client-0.3.7.tar.gz.
File metadata
- Download URL: memmachine_client-0.3.7.tar.gz
- Upload date:
- Size: 56.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
a22296cc5040e9f6c6e0c4e47bbe28d1c5cda93a2300afa4e5955986311f23fe
|
|
| MD5 |
aa7552fa5de0ffb13b63172382d05997
|
|
| BLAKE2b-256 |
1e43f243b87732652115e58bb2047baceb89037c912ee3c7e050c67a3add004b
|
Provenance
The following attestation bundles were made for memmachine_client-0.3.7.tar.gz:
Publisher:
pypi-publish.yml on MemMachine/MemMachine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
memmachine_client-0.3.7.tar.gz -
Subject digest:
a22296cc5040e9f6c6e0c4e47bbe28d1c5cda93a2300afa4e5955986311f23fe - Sigstore transparency entry: 1424193973
- Sigstore integration time:
-
Permalink:
MemMachine/MemMachine@01182818ca7fdf367d1167909ffe42b15f877cb5 -
Branch / Tag:
refs/tags/v0.3.7 - Owner: https://github.com/MemMachine
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@01182818ca7fdf367d1167909ffe42b15f877cb5 -
Trigger Event:
release
-
Statement type:
File details
Details for the file memmachine_client-0.3.7-py3-none-any.whl.
File metadata
- Download URL: memmachine_client-0.3.7-py3-none-any.whl
- Upload date:
- Size: 30.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
0dd0f7808d444f8fdff4125ce5f3e34fd18889bd4cc05713763744d0bdd8cecd
|
|
| MD5 |
a2409d3d1eefabdf37173dfc0d0a0890
|
|
| BLAKE2b-256 |
ac4c3af2d17da1b44a00085863fd8dbf4880acdad2114963db016c779748f37e
|
Provenance
The following attestation bundles were made for memmachine_client-0.3.7-py3-none-any.whl:
Publisher:
pypi-publish.yml on MemMachine/MemMachine
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
memmachine_client-0.3.7-py3-none-any.whl -
Subject digest:
0dd0f7808d444f8fdff4125ce5f3e34fd18889bd4cc05713763744d0bdd8cecd - Sigstore transparency entry: 1424194257
- Sigstore integration time:
-
Permalink:
MemMachine/MemMachine@01182818ca7fdf367d1167909ffe42b15f877cb5 -
Branch / Tag:
refs/tags/v0.3.7 - Owner: https://github.com/MemMachine
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
pypi-publish.yml@01182818ca7fdf367d1167909ffe42b15f877cb5 -
Trigger Event:
release
-
Statement type: