MemorySyncMemorySync
Python SDK

Install & Auth

Installing the Python client is one pip command. The hard part is wiring credentials cleanly: this page walks through pinning a version, where to put your API key, and how to confirm the client is reaching the right environment before you ship anything.

Install from PyPI

BASH
pip install memorysync

For a reproducible build, pin a minor range in your project file:

BASH
# requirements.txt
memorysync>=1.0,<2.0
BASH
# poetry
poetry add "memorysync>=1.0,<2.0"

Transitive dependencies are pulled in automatically by pip. If your environment pins an older incompatible version of anything we need, the install command will tell you the required range.

Verify the install in 30 seconds

BASH
python -c "from memorysync import MemorySyncClient, __version__; print(__version__)"

Getting an API key

  1. Open the dashboard and go to Settings → API Keys.
  2. Click Create key. Give it a name that says where it will be used.
  3. Copy the key shown once — the dashboard never shows it again.
  4. Paste it into your secret manager. Never commit it to git.

Building the client

PYTHON
import os
from memorysync import MemorySyncClient
client = MemorySyncClient(
api_key=os.environ["MEMORYSYNC_API_KEY"],
base_url="https://api.memorysync.io",
end_user_id="user_123", # required for API-key auth
project_id=os.getenv("MEMORYSYNC_PROJECT_ID"), # optional
timeout=15.0, # seconds; default 30
)

Every argument except api_key and base_url is optional. Constructor errors are raised eagerly — a missing key fails at construction time, not on the first call.

Every constructor argument explained

ArgumentTypeDefaultWhen to set it
api_keystr— (required)Always.
base_urlstr— (required)Per-environment URL: staging vs production.
project_idstr | NoneNoneWhen the same key is shared across projects and you want to lock this client to one.
end_user_idstr | NoneNoneRequired when authenticating with an API key. Identifies which of your end users the request belongs to; sent as the X-End-User-ID header. The server returns 400 MISSING_END_USER_ID without it. (Dashboard JWT sessions ignore this.)
timeoutfloat30.0Tighten for interactive paths; loosen for batch workers.

Splitting staging and production cleanly

Use a different API key and a different base_url per environment. Do not switch between them inside one process.

BASH
# .env.staging
MEMORYSYNC_API_KEY=ms_test_...
MEMORYSYNC_BASE_URL=https://staging.api.memorysync.io
# .env.production
MEMORYSYNC_API_KEY=ms_live_...
MEMORYSYNC_BASE_URL=https://api.memorysync.io

A safe “hello world” call

Run this once after you wire credentials. It does not write anything; it only verifies that the key is valid and the URL is reachable.

PYTHON
from memorysync import MemorySyncClient
from memorysync.errors import AuthError, MemorySyncError
# All three of api_key, base_url, and end_user_id are needed against a real key.
client = MemorySyncClient(
api_key=...,
base_url=...,
end_user_id="user_123",
)
try:
print(client.export_all().user_id) # GET /memory/export
print("OK")
except AuthError:
print("Invalid key")
except MemorySyncError as e:
print("Cannot reach API:", e)
finally:
client.close()

Rotating a leaked key

  • Create a new key in the dashboard, deploy it to your secret manager.
  • Restart your services so they pick the new value up.
  • Once you have confirmed the new key is in use, delete the old key from the dashboard. Old keys are revoked immediately.