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
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)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| memochain-0.1.1.tar.gz | 3.8 kB | Without provenance | Details for memochain-0.1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| memochain-0.1.1-py3-none-any.whl | Python 3 | none | any | Details for memochain-0.1.1-py3-none-any.whl |
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
|
Security for memochain 0.1.1
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.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.