Skip to main content

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


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

memg_sdk-0.1.0.tar.gz (1.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

memg_sdk-0.1.0-py3-none-any.whl (1.8 kB view details)

Uploaded Python 3

File details

Details for the file memg_sdk-0.1.0.tar.gz.

File metadata

  • Download URL: memg_sdk-0.1.0.tar.gz
  • Upload date:
  • Size: 1.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for memg_sdk-0.1.0.tar.gz
Algorithm Hash digest
SHA256 2ca04cb99f927d9537c5d70d61b51efa459898a3078200ddb82b189ee56a7a6b
MD5 78e897f8ddd4e0570eef59c6b58e9999
BLAKE2b-256 0b1912c22efbcbdb1e7148ab9c09b272ae0a9c49ea81902a4489ebbde4abc8db

See more details on using hashes here.

File details

Details for the file memg_sdk-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: memg_sdk-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 1.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.9.6

File hashes

Hashes for memg_sdk-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 40fb21b0bc90e68799fedacc8eb7f97de67d9d98cf0c39c84cac24737f022d50
MD5 fe15908d2d1db1e5ccc579f455d8e4f7
BLAKE2b-256 a6e2f639d88dce25fee597199c91b57e63e3acbc316878e5ada9c9e5450e572d

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page