Skip to main content

Official Python client for LongMemory.io

Project description

# LongMemory Python Client

The official Python client for [LongMemory.io](https://longmemory.io).  
**Add infinite long-term memory to your AI agents with one line of code.**


## 📦 Installation

```bash
pip install longmemory

🚀 Quick Start

The fastest way to use LongMemory is to set your keys as environment variables. This keeps your code clean and secure.

# Set these in your terminal or .env file
export LONGMEMORY_API_KEY="sk_live_..."
export LONGMEMORY_USER_ID="user_123"

Then, using the library is incredibly simple:

from longmemory import LongMemory

# 1. Initialize (Automatically loads keys from Env Vars)
client = LongMemory()

# 2. Add Memory (Stored forever)
client.add("My favorite food is Pizza.")
client.add("I am allergic to peanuts.")

# 3. Retrieve Context
context = client.get("What can I eat?")
print(context)
# Output: {'text': 'My favorite food is Pizza. I am allergic to peanuts.', ...}

🔌 Configuration

You can configure the client using Environment Variables (Recommended) or by passing arguments directly.

Option 1: Environment Variables

Variable Description
LONGMEMORY_API_KEY Your LongMemory.io API Key.
LONGMEMORY_USER_ID Default user ID for all operations.
LLM_MODEL Default LLM to use for .ask() (e.g., gpt-4).
LLM_API_KEY API Key for the LLM provider.

Option 2: Explicit Initialization

Useful if you are fetching keys from a secret manager (like AWS Secrets Manager).

client = LongMemory(
    api_key="sk_live_...",
    user_id="alice_123",
    llm_model="claude-3-opus",
    llm_api_key="sk-ant-...",
    verbose=True  # Prints logs to terminal
)

🤖 Advanced Usage

1. The .ask() Proxy

Instead of handling the LLM logic yourself, you can let LongMemory proxy the request. We retrieve the context, construct the prompt, and call the LLM securely on your behalf.

# Proxies the question to claude-3-opus (or your configured model)
answer = client.ask("What should I order for dinner?")
print(answer)
# "You should order a Pizza, but make sure it has no peanuts."

2. Switching Models On-the-Fly

You can switch models for specific queries without creating a new client.

# Use a cheaper model for simple tasks
client.ask("Summarize this", model="gpt-3.5-turbo")

# Use a smarter model for complex reasoning
client.ask("Draft a legal contract", model="gpt-4o")

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

longmemory-0.1.0a1.tar.gz (4.4 kB view details)

Uploaded Source

Built Distribution

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

longmemory-0.1.0a1-py3-none-any.whl (4.8 kB view details)

Uploaded Python 3

File details

Details for the file longmemory-0.1.0a1.tar.gz.

File metadata

  • Download URL: longmemory-0.1.0a1.tar.gz
  • Upload date:
  • Size: 4.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for longmemory-0.1.0a1.tar.gz
Algorithm Hash digest
SHA256 7d4ae2c07a9eb54e1a08517e76bcf3f41c0c1863e6f38aab1921d3cdaa0530cd
MD5 c342d325f9db7500cdb7971bd495a3e1
BLAKE2b-256 f6484b92b12606e0c57cbe2696104924a5127cf7eb1ba914f73f20ffc36d56bb

See more details on using hashes here.

File details

Details for the file longmemory-0.1.0a1-py3-none-any.whl.

File metadata

  • Download URL: longmemory-0.1.0a1-py3-none-any.whl
  • Upload date:
  • Size: 4.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.14.2

File hashes

Hashes for longmemory-0.1.0a1-py3-none-any.whl
Algorithm Hash digest
SHA256 d9e7f641240ecb495a77e73c1f88ef203c8541e13bc68aa4fcffcc9645818b85
MD5 38b3f904c032c991be6d1ad4ff6ab518
BLAKE2b-256 f951aaeb93e7cee17fbf8d26496cd8a67868cfcdb5124e32d9048ec4188a7b5e

See more details on using hashes here.

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