Memory layer for LLM applications
Project description
MemG Python SDK
Python SDK for MemG -- a pluggable memory layer for LLM applications.
Installation
pip install memg
# With provider extras
pip install memg[openai]
pip install memg[anthropic]
pip install memg[all]
Quick Start
Proxy Mode (simplest)
Redirect your LLM client through the MemG proxy. No extra code needed beyond wrapping:
from openai import OpenAI
from memg import MemG
client = OpenAI()
client = MemG.wrap(client, entity="user-123", mode="proxy")
# Use as normal -- MemG injects and extracts memories transparently
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "I love hiking in the mountains"}],
)
Client Mode (no proxy needed)
The SDK intercepts calls, queries the MCP server for relevant memories, injects them, and extracts new knowledge:
from openai import OpenAI
from memg import MemG
client = OpenAI()
client = MemG.wrap(client, entity="user-123", mode="client")
response = client.chat.completions.create(
model="gpt-4o",
messages=[{"role": "user", "content": "Remember I prefer dark roast coffee"}],
)
Direct Memory Operations
from memg import MemG
m = MemG()
# Add memories
m.add("user-123", "likes coffee")
m.add("user-123", ["works at Acme", "prefers dark mode"])
# Search
results = m.search("user-123", "coffee preferences")
for mem in results.memories:
print(f"{mem.content} (score={mem.score})")
# List
all_mems = m.list("user-123", type="identity")
# Delete
m.delete("user-123", memory_id="some-uuid")
m.delete_all("user-123")
m.close()
Modes
| Mode | Requires | How it works |
|---|---|---|
proxy |
MemG proxy running | Redirects LLM calls through the proxy via with_options() |
client |
MemG MCP server running | SDK intercepts calls, queries MCP for memories, injects context |
Configuration
Default URLs:
- MCP server:
http://localhost:8686 - Proxy:
http://localhost:8787/v1
Override via constructor or wrap():
m = MemG(mcp_url="http://custom:8686", proxy_url="http://custom:8787/v1")
MemG.wrap(client, mode="proxy", proxy_url="http://custom:8787/v1")
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 memg_sdk-0.2.0.tar.gz.
File metadata
- Download URL: memg_sdk-0.2.0.tar.gz
- Upload date:
- Size: 1.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
e836111691f4d7a4f3ac1012967365cec3bea233881fd6b68cca6b12b13fbfe4
|
|
| MD5 |
0ea8327ffd1ec73a6f688d380f0eca9e
|
|
| BLAKE2b-256 |
1129a393d0e4e80a7cfe54ab40ebacbf783b2b41de4fa6a4c1907f279b32560e
|
File details
Details for the file memg_sdk-0.2.0-py3-none-any.whl.
File metadata
- Download URL: memg_sdk-0.2.0-py3-none-any.whl
- Upload date:
- Size: 1.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.9.6
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
b1e7eea95a591b340e721f6588f6e1ebe5d5e3f75e533b4edf0102e361b79520
|
|
| MD5 |
cd38baee0cd85daee6a5ff4ce871c4b1
|
|
| BLAKE2b-256 |
f4bd0dddc0b0b63828b21fe2451d0845e77bdbb72fb51f004fc57823790a7020
|