NexaMem - A Python package to store and manage chatbot conversation history.
Project description
NexaMem
A simple Python package to store and manage AI memory. Designed for easy integration with Python projects.
Features
- Store, retrieve, and manage chatbot conversation history
- Simple API for integration with LLM-based chatbots
Installation
pip install nexamem
(FOR TESTING)
pip install -i https://test.pypi.org/simple/ nexamem
OR with GitHub
pip install git+https://github.com/microsoft/nexamem.git
uv add git+https://github.com/microsoft/nexamem.git
OR with GitHub branch?
pip install git+https://github.com/microsoft/nexamem.git@branch_or_tag_name
uv add git+https://github.com/microsoft/nexamem.git@branch_or_tag_name
Usage
Before using NexaMem, initialize the configuration with your preferred storage backend:
from nexamem import initialize, get_config, ChatHistory
# Example: In-memory storage (default)
initialize({
"history_storage": "memory",
"debug": True # Optional: enable debug output
})
# Example: File-based storage
initialize({
"history_storage": "file",
"file_path": "./chat_history.json",
"debug": False
})
# Example: SQLite storage
initialize({
"history_storage": "sqlite",
"sqlite_path": "./chat_history.db",
"debug": False
})
print(get_config()) # View current configuration
history = ChatHistory()
history.add_message('user', 'Hello!')
history.add_message('bot', 'Hi! How can I help you?')
print(history.get_history())
Configuration Options
history_storage(str, required): Storage backend. One of'memory','file', or'sqlite'.file_path(str, required ifhistory_storage='file'): Path to the JSON file for storing history.sqlite_path(str, required ifhistory_storage='sqlite'): Path to the SQLite database file.debug(bool, optional): Enable debug output (default:False).
API Methods
initialize(config: dict): Initialize the library with configuration.get_config() -> dict: Get the current configuration.ChatHistory.add_message(role: str, content: str): Add a message to the history.ChatHistory.get_history() -> list: Retrieve the conversation history.ChatHistory.clear(): Clear the conversation history.ChatHistory.query_sqlite(where: str = "", params: tuple = ()) -> list: Query SQLite history (only if using SQLite backend).ChatHistory.get_message_at(index: int) -> dict: Retrieve the message at the specified index in the conversation history. RaisesIndexErrorif out of range.
Development
- Create a virtual environment:
python -m venv .venv
- Activate the virtual environment:
- On Windows:
.venv\Scripts\activate
- On macOS/Linux:
source .venv/bin/activate
- On Windows:
- Install dependencies:
pip install -e . pip install -r requirements.txt
Testing
pytest
Building a Binary Distribution
To build a binary wheel (for manual installation or distribution):
- Make sure you have the latest build tools:
pip install --upgrade build
- Build the wheel file:
python -m build --wheel
This will create a.whlfile in thedist/directory. - (Optional) Install the built wheel manually:
pip install dist/nexamem-*.whl
For more details, see the Python Packaging User Guide.
License
This project is licensed under the MIT License.
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
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 nexamem-0.1.3.tar.gz.
File metadata
- Download URL: nexamem-0.1.3.tar.gz
- Upload date:
- Size: 9.1 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
15ad7e8b400efbf61528c714db79611d641a4dec9cf87ba762946e36f47c6869
|
|
| MD5 |
56bed14d93fecc297877aaac27d73613
|
|
| BLAKE2b-256 |
0ef46fe8e5cc04699fbdf37ab2338535c655f4914c8e94da271f31afc7040fa9
|
Provenance
The following attestation bundles were made for nexamem-0.1.3.tar.gz:
Publisher:
python-publish-to-test.yml on microsoft/nexamem
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nexamem-0.1.3.tar.gz -
Subject digest:
15ad7e8b400efbf61528c714db79611d641a4dec9cf87ba762946e36f47c6869 - Sigstore transparency entry: 233376794
- Sigstore integration time:
-
Permalink:
microsoft/nexamem@5ea42ee66be7fe867433111c6c1ff0c70b53bef0 -
Branch / Tag:
refs/tags/0.1.3 - Owner: https://github.com/microsoft
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish-to-test.yml@5ea42ee66be7fe867433111c6c1ff0c70b53bef0 -
Trigger Event:
push
-
Statement type:
File details
Details for the file nexamem-0.1.3-py3-none-any.whl.
File metadata
- Download URL: nexamem-0.1.3-py3-none-any.whl
- Upload date:
- Size: 7.9 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
fc449ba9a992ab9aabfa700ba6449bc276aa03f9e525d871c3eb52c34e93b875
|
|
| MD5 |
48467606ca6d59e0219eec159e27ec59
|
|
| BLAKE2b-256 |
6209d271361deb6aa5add56721a030af48501b5ddcbe07e158864b9b3f08069b
|
Provenance
The following attestation bundles were made for nexamem-0.1.3-py3-none-any.whl:
Publisher:
python-publish-to-test.yml on microsoft/nexamem
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
nexamem-0.1.3-py3-none-any.whl -
Subject digest:
fc449ba9a992ab9aabfa700ba6449bc276aa03f9e525d871c3eb52c34e93b875 - Sigstore transparency entry: 233376802
- Sigstore integration time:
-
Permalink:
microsoft/nexamem@5ea42ee66be7fe867433111c6c1ff0c70b53bef0 -
Branch / Tag:
refs/tags/0.1.3 - Owner: https://github.com/microsoft
-
Access:
private
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish-to-test.yml@5ea42ee66be7fe867433111c6c1ff0c70b53bef0 -
Trigger Event:
push
-
Statement type: