Skip to main content

GitHub license


MemFuse Logo

MemFuse Python SDK
The official Python client for MemFuse, the open-source memory layer for LLMs.
Explore the Docs »

View Demo · Report Bug · Request Feature

Table of Contents
  1. About MemFuse
  2. Installation
  3. Quick Start
  4. Examples
  5. Documentation
  6. Community & Support
  7. License

About MemFuse

Large language model applications are inherently stateless by design. When the context window reaches its limit, previous conversations, user preferences, and critical information simply disappear.

MemFuse bridges this gap by providing a persistent, queryable memory layer between your LLM and storage backend, enabling AI agents to:

  • Remember user preferences and context across sessions
  • Recall facts and events from thousands of interactions later
  • Optimize token usage by avoiding redundant chat history resending
  • Learn continuously and improve performance over time

This repository contains the official Python SDK for seamless integration with MemFuse servers. For comprehensive information about the MemFuse server architecture and advanced features, please visit the MemFuse Server repository.

Recent Updates

  • Enhanced Testing: Comprehensive E2E testing with semantic memory validation
  • Better Error Handling: Improved error messages and logging for easier debugging
  • Prompt Templates: Structured prompt management system for consistent LLM interactions
  • Performance Benchmarks: MSC dataset accuracy testing with 95% validation threshold

Installation

Note: This is the standalone Client SDK repository. If you need to install and run the MemFuse server, which is essential to use the SDK, please visit the MemFuse Server repository.

You can install the MemFuse Python SDK using one of the following methods:

Option 1: Install from PyPI (Recommended)

pip install memfuse

Option 2: Install from Source

git clone https://github.com/memfuse/memfuse-python.git
cd memfuse-python
pip install -e .

Optional extras

Some features are optional and shipped as extras:

  • UI (Gradio demo UIs)

    • pip: pip install "memfuse[ui]"
    • poetry: add the ui extra
  • Full (includes UI)

    • pip: pip install "memfuse[full]"
    • poetry: add the full extra

The Gradio-based examples in examples/ require the ui extra. If you run those scripts without the extra installed, they will raise: RuntimeError('Install memfuse[ui] to use the demo UI.').

Quick Start

Here's a comprehensive example demonstrating how to use the MemFuse Python SDK with OpenAI:

from memfuse.llm import OpenAI
from memfuse import MemFuse
import os


memfuse_client = MemFuse(
  # api_key=os.getenv("MEMFUSE_API_KEY")
  # base_url=os.getenv("MEMFUSE_BASE_URL"),
)

memory = memfuse_client.init(
  user="alice",
  # agent="agent_default",
  # session=<randomly-generated-uuid>
)

# Initialize your LLM client with the memory scope
llm_client = OpenAI(
    api_key=os.getenv("OPENAI_API_KEY"),  # Your OpenAI API key
    memory=memory
)

# Make a chat completion request
response = llm_client.chat.completions.create(
    model="gpt-4o", # Or any model supported by your LLM provider
    messages=[{"role": "user", "content": "I'm planning a trip to Mars. What is the gravity there?"}]
)

print(f"Response: {response.choices[0].message.content}")
# Example Output: Response: Mars has a gravity of about 3.721 m/s², which is about 38% of Earth's gravity.

Contextual Follow-up

Now, ask a follow-up question. MemFuse will automatically recall relevant context from the previous conversation:

# Ask a follow-up question. MemFuse automatically recalls relevant context.
followup_response = llm_client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "What are some challenges of living on that planet?"}]
)

print(f"Follow-up: {followup_response.choices[0].message.content}")
# Example Output: Follow-up: Some challenges of living on Mars include its thin atmosphere, extreme temperatures, high radiation levels, and the lack of liquid water on the surface.

MemFuse automatically manages the retrieval of relevant information and storage of new memories from conversations within the specified memory scope.

Advanced Features

Memory Validation & Testing

The SDK includes comprehensive testing capabilities to validate memory accuracy:

  • E2E Memory Tests: Automated tests that verify conversational context retention
  • Semantic Similarity Validation: Uses RAGAS framework for intelligent response verification
  • Performance Benchmarks: MSC (Multi-Session Chat) dataset testing with accuracy metrics

Error Handling & Debugging

Enhanced error messages provide clear guidance:

  • Connection Issues: Helpful instructions for starting the MemFuse server
  • API Errors: Detailed error responses with actionable information
  • Logging: Comprehensive logging for troubleshooting and monitoring

Examples

Explore comprehensive examples in the examples/ directory of this repository, featuring:

  • Basic Operations: Fundamental usage patterns and asynchronous operations
  • Conversation Continuity: Maintaining context across multiple interactions
  • UI Integrations: Gradio-based chatbot implementations with streaming support

Documentation

  • Server Documentation: For detailed information about the MemFuse server architecture and advanced configuration, visit the MemFuse online documentation
  • SDK Documentation: Comprehensive API references and guides will be available soon

Community & Support

Join our growing community:

If MemFuse enhances your projects, please ⭐ star both the server repository and this SDK repository!

License

This MemFuse Python SDK is licensed under the Apache 2.0 License. See the LICENSE file for complete details.

Metadata

Release files for memfuse 0.3.3

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

Source distribution (sdist)

Source distribution for memfuse 0.3.3
File Size Uploaded
memfuse-0.3.3.tar.gz 45.2 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for memfuse 0.3.3
File Interpreter ABI Platform
memfuse-0.3.3-py3-none-any.whl Python 3 none any Details

Total release size: 103.5 kB

Release files / memfuse-0.3.3.tar.gz

Download URL memfuse-0.3.3.tar.gz
Size 45.2 kB
Tags Source
SHA-256 checksum
How to use checksums
4bc7a6df6aa316c168a7425bf4af5cb05d91eff05460ebb12c0b386d80ecf102
BLAKE2b-256 checksum
How to use checksums
6003c506ccaf6e7da1c9519cada608a6ca30b34249c0f4de5e0af90f39f67d47
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 10, 2025.

Transparency log

Release files / memfuse-0.3.3-py3-none-any.whl

Download URL memfuse-0.3.3-py3-none-any.whl
Size 58.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a90f411b39aa76124b65fde608268b164f285f3655b42f116bcefde972ffe70b
BLAKE2b-256 checksum
How to use checksums
89ab3cb21b14b8e898727c56175e6b82902c7767518853872a68bb93802c2a8e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/6.1.0 CPython/3.13.7

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.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Oct 10, 2025.

Transparency log

Release history Release notifications | RSS feed

This release

0.3.3 This release

2 release files

0.3.2

2 release files

0.2.0

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