Skip to main content

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 if history_storage='file'): Path to the JSON file for storing history.
  • sqlite_path (str, required if history_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. Raises IndexError if out of range.

Development

  1. Create a virtual environment:
    python -m venv .venv
    
  2. Activate the virtual environment:
    • On Windows:
      .venv\Scripts\activate
      
    • On macOS/Linux:
      source .venv/bin/activate
      
  3. 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):

  1. Make sure you have the latest build tools:
    pip install --upgrade build
    
  2. Build the wheel file:
    python -m build --wheel
    
    This will create a .whl file in the dist/ directory.
  3. (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

nexamem-0.1.3.tar.gz (9.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

nexamem-0.1.3-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

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

Hashes for nexamem-0.1.3.tar.gz
Algorithm Hash digest
SHA256 15ad7e8b400efbf61528c714db79611d641a4dec9cf87ba762946e36f47c6869
MD5 56bed14d93fecc297877aaac27d73613
BLAKE2b-256 0ef46fe8e5cc04699fbdf37ab2338535c655f4914c8e94da271f31afc7040fa9

See more details on using hashes here.

Provenance

The following attestation bundles were made for nexamem-0.1.3.tar.gz:

Publisher: python-publish-to-test.yml on microsoft/nexamem

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

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

Hashes for nexamem-0.1.3-py3-none-any.whl
Algorithm Hash digest
SHA256 fc449ba9a992ab9aabfa700ba6449bc276aa03f9e525d871c3eb52c34e93b875
MD5 48467606ca6d59e0219eec159e27ec59
BLAKE2b-256 6209d271361deb6aa5add56721a030af48501b5ddcbe07e158864b9b3f08069b

See more details on using hashes here.

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

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page