Skip to main content

Python SDK for MemWal — Privacy-first AI memory with Ed25519 signing

Project description

memwal

Python SDK for MemWal — Privacy-first AI memory with Ed25519 signing.

All data processing (encryption, embedding, Walrus storage) happens server-side in a TEE. The SDK signs requests with your Ed25519 delegate key and sends text over HTTPS.

Installation

pip install memwal

With optional integrations:

pip install memwal[langchain]   # LangChain support
pip install memwal[openai]      # OpenAI SDK support
pip install memwal[all]         # Everything

Quick Start

Set your environment variables first:

export MEMWAL_KEY="your-ed25519-delegate-key-hex"
export MEMWAL_ACCOUNT_ID="0x-your-memwal-account-id"
export MEMWAL_SERVER_URL="https://relayer.memwal.ai"

Async (recommended)

import asyncio
import os
from memwal import MemWal

async def main():
    memwal = MemWal.create(
        key=os.environ["MEMWAL_KEY"],
        account_id=os.environ["MEMWAL_ACCOUNT_ID"],
        server_url=os.environ.get("MEMWAL_SERVER_URL", "https://relayer.memwal.ai"),
    )

    # Store a memory
    result = await memwal.remember("I'm allergic to peanuts")
    print(result.blob_id)

    # Recall memories
    matches = await memwal.recall("food allergies")
    for memory in matches.results:
        print(f"{memory.text} (relevance: {1 - memory.distance:.2f})")

    # Analyze conversation for facts
    analysis = await memwal.analyze("I love coffee and live in Tokyo")
    for fact in analysis.facts:
        print(fact.text)

    await memwal.close()

asyncio.run(main())

Sync

import os
from memwal import MemWalSync

client = MemWalSync.create(
    key=os.environ["MEMWAL_KEY"],
    account_id=os.environ["MEMWAL_ACCOUNT_ID"],
    server_url=os.environ.get("MEMWAL_SERVER_URL", "https://relayer.memwal.ai"),
)

result = client.remember("I'm allergic to peanuts")
matches = client.recall("food allergies")
client.close()

Context Manager

import os
from memwal import MemWal

async with MemWal.create(
    key=os.environ["MEMWAL_KEY"],
    account_id=os.environ["MEMWAL_ACCOUNT_ID"],
) as memwal:
    await memwal.remember("I prefer dark mode")

AI Middleware

LangChain

import os
from langchain_openai import ChatOpenAI
from langchain_core.messages import HumanMessage
from memwal import with_memwal_langchain

llm = ChatOpenAI(model="gpt-4o")
smart_llm = with_memwal_langchain(
    llm,
    key=os.environ["MEMWAL_KEY"],
    account_id=os.environ["MEMWAL_ACCOUNT_ID"],
    server_url=os.environ.get("MEMWAL_SERVER_URL", "https://relayer.memwal.ai"),
    max_memories=5,
    min_relevance=0.3,
)

# Memories are automatically recalled and injected
response = await smart_llm.ainvoke([HumanMessage("What are my food allergies?")])

OpenAI SDK

import os
from openai import AsyncOpenAI
from memwal import with_memwal_openai

client = AsyncOpenAI()
smart_client = with_memwal_openai(
    client,
    key=os.environ["MEMWAL_KEY"],
    account_id=os.environ["MEMWAL_ACCOUNT_ID"],
    server_url=os.environ.get("MEMWAL_SERVER_URL", "https://relayer.memwal.ai"),
)

# Memories are automatically recalled and injected
response = await smart_client.chat.completions.create(
    model="gpt-4o",
    messages=[{"role": "user", "content": "What are my food allergies?"}],
)

API Reference

MemWal.create(key, account_id, server_url?, namespace?)

Create a new async client.

Methods

Method Description
await remember(text, namespace?) Store a memory
await recall(query, limit?, namespace?) Search memories
await analyze(text, namespace?) Extract and store facts
await ask(question, limit?, namespace?) Ask a question answered using memories
await restore(namespace, limit?) Restore a namespace
await health() Check server health
await remember_manual(opts) Store with pre-computed vector
await recall_manual(opts) Search with pre-computed vector
await get_public_key_hex() Get Ed25519 public key

Authentication

Every request is signed with Ed25519:

message = f"{timestamp}.{method}.{path}.{sha256(body)}.{nonce}.{account_id}"

Headers sent: x-public-key, x-signature, x-timestamp, x-nonce, x-delegate-key, x-account-id.

License

MIT

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

memwal-0.1.0.dev1.tar.gz (35.1 kB view details)

Uploaded Source

Built Distribution

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

memwal-0.1.0.dev1-py3-none-any.whl (20.1 kB view details)

Uploaded Python 3

File details

Details for the file memwal-0.1.0.dev1.tar.gz.

File metadata

  • Download URL: memwal-0.1.0.dev1.tar.gz
  • Upload date:
  • Size: 35.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for memwal-0.1.0.dev1.tar.gz
Algorithm Hash digest
SHA256 5530416c5fba2d9e4a12f604f5aba53a712846d1e3db9d777a583206c4560444
MD5 5dbf7e79bb6e8f935e0fa82a1bb82ff7
BLAKE2b-256 bd00a65326eefa9ede1431dc03ca32483e93094d2e846694de440afbc6e864a9

See more details on using hashes here.

Provenance

The following attestation bundles were made for memwal-0.1.0.dev1.tar.gz:

Publisher: release-python-sdk.yml on MystenLabs/MemWal

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

File details

Details for the file memwal-0.1.0.dev1-py3-none-any.whl.

File metadata

  • Download URL: memwal-0.1.0.dev1-py3-none-any.whl
  • Upload date:
  • Size: 20.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.12

File hashes

Hashes for memwal-0.1.0.dev1-py3-none-any.whl
Algorithm Hash digest
SHA256 426f07903643d7f5b7304addf216fcece2f1f8ecd7ca33d103dc8f30f0321289
MD5 31cb5a425b0150278ecddebf4c7b5ff6
BLAKE2b-256 9cf0c4ac53f54bb74d7fb221d3022806fbf6b377a841d0754ae9822aa7000c0a

See more details on using hashes here.

Provenance

The following attestation bundles were made for memwal-0.1.0.dev1-py3-none-any.whl:

Publisher: release-python-sdk.yml on MystenLabs/MemWal

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