Skip to main content

MemoChain

MemoChain is a lightweight Python library for adding memory to stateless LLM APIs. It allows developers to easily store and retrieve conversation history across sessions with minimal setup.

Key features:

  • Supports any LLM API (OpenAI, DeepSeek, Claude, Mistral, etc.)
  • Built-in Groq integration
  • Local JSON-based storage (no external DB or backend)
  • Session-based memory tracking
  • Clean, modular design for easy use in any project

Installation

pip install memochain

Quickstart

Use with your own LLM (e.g. OpenAI)

from memochain.memory_store import load_context, append_to_history
import openai

openai.api_key = "your-openai-api-key"
session_id = "demo-session"

append_to_history(session_id, "user", "Tell me a joke.")
history = load_context(session_id)

response = openai.ChatCompletion.create(
    model="gpt-3.5-turbo",
    messages=history
)

assistant_msg = response["choices"][0]["message"]["content"]
append_to_history(session_id, "assistant", assistant_msg)

print("Assistant:", assistant_msg)

Use with built-in Groq support

from memochain.groq_client import GroqLLMClient
from memochain.memory_store import append_to_history, get_session_history

session_id = "groq-session"
client = GroqLLMClient()

append_to_history(session_id, "user", "Who won the World Cup in 2022?")
history = get_session_history(session_id)
response = client.chat(history)

append_to_history(session_id, "assistant", response)
print("Assistant:", response)

How It Works

MemoChain stores all message history locally in:

  • .memochain_history.json — stores conversation history per session
  • .memochain_sessions.json — tracks active session IDs

This allows memory persistence across runs without a backend or database.


Example Scripts

See the examples/ folder:

  • custom_llm_openai_example.py — OpenAI API usage
  • groq_chat_example.py — Chat example using Groq integration

To test locally:

python examples/groq_chat_example.py

License

MIT


Author

Yash Thapliyal – GitHub

Metadata

Release files for memochain 0.1.1

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

Source distribution (sdist)

Source distribution for memochain 0.1.1
File Size Uploaded
memochain-0.1.1.tar.gz 3.8 kB Details

Built distribution (wheel)

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

Total release size: 8.9 kB

Release files / memochain-0.1.1.tar.gz

Download URL memochain-0.1.1.tar.gz
Size 3.8 kB
Tags Source
SHA-256 checksum
How to use checksums
f296eafa07e9f8ec5b72868e49c73d598071102339e912e39b4fb4ca09d86c1d
BLAKE2b-256 checksum
How to use checksums
f90be0a8c77221c4995f12aa7122acfb592de29af7589d80e6fb27dbd240c1e5
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.7

Release files / memochain-0.1.1-py3-none-any.whl

Download URL memochain-0.1.1-py3-none-any.whl
Size 5.1 kB
Tags Python 3
SHA-256 checksum
How to use checksums
90abfd8aeb21057b040e1e6af0a0545a01a7ff8bf27c5b068c498f16c11ef69a
BLAKE2b-256 checksum
How to use checksums
61b043f4142c1d9411f0b874b09c9c98a7f6d6a1953f1b57da8694a7f3da8e09
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.7

Release history Release notifications | RSS feed

This release

0.1.1 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