Skip to main content
The Mem[v] SDK provides convenient access to the Mem[v] REST API from Python and TypeScript/JavaScript applications.

Installation

pip install memvai

Requirements

  • Python 3.9 or higher
  • Works with standard Python and async/await

Authentication

Get your API key from the Mem[v] Dashboard.

Set up your API key

export MEMV_API_KEY="your-api-key-here"
Or use a .env file:
MEMV_API_KEY=your-api-key-here
Never commit your API key to source control. Always use environment variables.

Quick start

import os
from memvai import Memv

# Initialize the client
client = Memv(
    api_key=os.environ.get("MEMV_API_KEY"),
)

# List all spaces
response = client.spaces.list()
for space in response.spaces:
    print(f"{space.name} ({space.id})")

Async usage

import os
import asyncio
from memvai import AsyncMemv

client = AsyncMemv(
    api_key=os.environ.get("MEMV_API_KEY"),
)

async def main():
    response = await client.spaces.list()
    for space in response.spaces:
        print(f"{space.name} ({space.id})")

asyncio.run(main())

Type support

from memvai import Memv
from memvai.types import SpaceListResponse

client = Memv()

# Full type hints with Pydantic models
response: SpaceListResponse = client.spaces.list()

Configuration options

Timeouts

from memvai import Memv

# Set default timeout (20 seconds)
client = Memv(timeout=20.0)

# Override per-request
client.with_options(timeout=5.0).spaces.list()
Default timeout is 60 seconds.

Retries

# Configure retries (default is 2)
client = Memv(max_retries=5)

# Disable retries
client = Memv(max_retries=0)

# Override per-request
client.with_options(max_retries=3).spaces.list()
Automatically retried errors:
  • Connection errors
  • 408 Request Timeout
  • 409 Conflict
  • 429 Rate Limit
  • 500+ Server errors

Logging

# Set via environment variable
import os
os.environ['MEMV_LOG'] = 'debug'  # or 'info'

# Or via client option
client = Memv(log_level='debug')

Runtime-specific usage

Deno

import Memv from 'npm:memvai';

const client = new Memv({
  apiKey: Deno.env.get('MEMV_API_KEY'),
});

Bun

import Memv from 'memvai';

const client = new Memv({
  apiKey: process.env.MEMV_API_KEY,
});

Cloudflare Workers

import Memv from 'memvai';

export default {
  async fetch(request: Request, env: Env): Promise<Response> {
    const client = new Memv({
      apiKey: env.MEMV_API_KEY,
    });

    const spaces = await client.spaces.list();
    return Response.json(spaces.spaces);
  },
};

Working with response objects

# Extract the data you need
response = client.spaces.create(name="My Space")
space_id = response.space.id

# Or unpack the object
space = response.space
print(space.id, space.name)

Next steps

Spaces

Create and manage memory spaces

Memories

Add and search memories

Files

Upload and manage files

Error handling

Handle errors and exceptions