Skip to main content

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")

Release files for memg-sdk 0.2.0

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

Source distribution (sdist)

Source distribution for memg-sdk 0.2.0
File Size Uploaded
memg_sdk-0.2.0.tar.gz 1.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for memg-sdk 0.2.0
File Interpreter ABI Platform
memg_sdk-0.2.0-py3-none-any.whl Python 3 none any Details

Total release size: 3.7 kB

Release files / memg_sdk-0.2.0.tar.gz

Download URL memg_sdk-0.2.0.tar.gz
Size 1.9 kB
Tags Source
SHA-256 checksum
How to use checksums
e836111691f4d7a4f3ac1012967365cec3bea233881fd6b68cca6b12b13fbfe4
BLAKE2b-256 checksum
How to use checksums
1129a393d0e4e80a7cfe54ab40ebacbf783b2b41de4fa6a4c1907f279b32560e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release files / memg_sdk-0.2.0-py3-none-any.whl

Download URL memg_sdk-0.2.0-py3-none-any.whl
Size 1.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
b1e7eea95a591b340e721f6588f6e1ebe5d5e3f75e533b4edf0102e361b79520
BLAKE2b-256 checksum
How to use checksums
f4bd0dddc0b0b63828b21fe2451d0845e77bdbb72fb51f004fc57823790a7020
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.2.0 CPython/3.9.6

Release history Release notifications | RSS feed

This release

0.2.0 This release

2 release files

0.1.0

2 release files

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