A lightweight library to add memory to stateless LLM APIs
Project description
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 usagegroq_chat_example.py— Chat example using Groq integration
To test locally:
python examples/groq_chat_example.py
License
MIT
Author
Yash Thapliyal – GitHub
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 memochain-0.1.1.tar.gz.
File metadata
- Download URL: memochain-0.1.1.tar.gz
- Upload date:
- Size: 3.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
f296eafa07e9f8ec5b72868e49c73d598071102339e912e39b4fb4ca09d86c1d
|
|
| MD5 |
7702b0c717b8e4fe162c97319cdfba3b
|
|
| BLAKE2b-256 |
f90be0a8c77221c4995f12aa7122acfb592de29af7589d80e6fb27dbd240c1e5
|
File details
Details for the file memochain-0.1.1-py3-none-any.whl.
File metadata
- Download URL: memochain-0.1.1-py3-none-any.whl
- Upload date:
- Size: 5.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
90abfd8aeb21057b040e1e6af0a0545a01a7ff8bf27c5b068c498f16c11ef69a
|
|
| MD5 |
49967ce9644e91873b2887e60699946c
|
|
| BLAKE2b-256 |
61b043f4142c1d9411f0b874b09c9c98a7f6d6a1953f1b57da8694a7f3da8e09
|