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.2.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.2-py3-none-any.whl (7.9 kB view details)

Uploaded Python 3

File details

Details for the file nexamem-0.1.2.tar.gz.

File metadata

  • Download URL: nexamem-0.1.2.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.2.tar.gz
Algorithm Hash digest
SHA256 f0df4b6b784df620fdd26e7049bc25b6cce241082f9ce65b9fa853ff954854a0
MD5 33420e27ef7712333c65be34943759a9
BLAKE2b-256 c002377f4d1fbacbb0888981b0280d13353c6b82d0cf23cabb97a21dc93bdc7b

See more details on using hashes here.

Provenance

The following attestation bundles were made for nexamem-0.1.2.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.2-py3-none-any.whl.

File metadata

  • Download URL: nexamem-0.1.2-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.2-py3-none-any.whl
Algorithm Hash digest
SHA256 6dcab1d3b8e5ea009c6abdf4fdd5c0f70f21d969e732343fdeedd0fb19b6a124
MD5 62d5c0b0faed2ceee88882f06a016c2c
BLAKE2b-256 4f5e5291205553d01719db48c7f51ea08ccf0dfb0b7a0e1f631716994371e031

See more details on using hashes here.

Provenance

The following attestation bundles were made for nexamem-0.1.2-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