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
pip install memorysync
For a reproducible build, pin a minor range in your project file:
# requirements.txtmemorysync>=1.0,<2.0
# poetrypoetry 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
python -c "from memorysync import MemorySyncClient, __version__; print(__version__)"
Getting an API key
- Open the dashboard and go to
Settings → API Keys. - Click Create key. Give it a name that says where it will be used.
- Copy the key shown once — the dashboard never shows it again.
- Paste it into your secret manager. Never commit it to git.
Building the client
import osfrom memorysync import MemorySyncClientclient = MemorySyncClient(api_key=os.environ["MEMORYSYNC_API_KEY"],base_url="https://api.memorysync.io",end_user_id="user_123", # required for API-key authproject_id=os.getenv("MEMORYSYNC_PROJECT_ID"), # optionaltimeout=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
| Argument | Type | Default | When to set it |
|---|---|---|---|
| api_key | str | — (required) | Always. |
| base_url | str | — (required) | Per-environment URL: staging vs production. |
| project_id | str | None | None | When the same key is shared across projects and you want to lock this client to one. |
| end_user_id | str | None | None | Required 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.) |
| timeout | float | 30.0 | Tighten 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.
# .env.stagingMEMORYSYNC_API_KEY=ms_test_...MEMORYSYNC_BASE_URL=https://staging.api.memorysync.io# .env.productionMEMORYSYNC_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.
from memorysync import MemorySyncClientfrom 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/exportprint("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.