MemorySync
SDKs · Python

Python Control Plane

Use ControlPlaneClient for trusted account, organization, billing, session, project, export, integration, API-key, and webhook workflows. Protected methods use a bearer access token—not a memory API key.

Choose the correct credential

Python authentication boundary

MemorySyncClient

Memory data plane.

  • Uses api_key.
  • Uses project and end-user scope.
  • Does not accept a bearer access token.

ControlPlaneClient

Administrative control plane.

  • Uses access_token for protected methods.
  • May use project scope where supported.
  • Does not send X-End-User-ID.

Create a protected client

control_plane.py
import os
from memorysync import ControlPlaneClient
with ControlPlaneClient(
"https://api.memorysync.io",
access_token=os.environ["MEMORYSYNC_ACCESS_TOKEN"],
project_id=os.environ.get("MEMORYSYNC_PROJECT_ID"),
) as control:
projects = control.list_projects()
for project in projects:
print(project["id"], project["name"])

Curated control-plane methods

AreaMethods
API keysbulk_revoke_api_keys, test_api_key
Authenticationsignup, login, refresh, logout, me, logout_all
Billingget_current_plan
Sessionslist_sessions, revoke_session
Integrationslist_integrations
Organizationscreate_organization, list_organizations
Projectslist_projects, create_project, rename_project, archive_project, unarchive_project, delete_project
Exportscreate_export, list_exports, get_export, cancel_export, retry_export, get_export_download_url
Webhookscreate_webhook, list_webhooks, get_webhook, get_webhook_event_types, get_webhook_health, update_webhook, delete_webhook, pause_webhook, resume_webhook, rotate_webhook_secret, test_webhook, replay_webhook_deliveries, list_webhook_deliveries, get_latest_webhook_delivery, list_recent_webhook_deliveries, get_webhook_delivery, retry_webhook_delivery

Login does not configure the client

login.py
import os
from memorysync import ControlPlaneClient
with ControlPlaneClient("https://api.memorysync.io") as control:
result = control.login(
"developer@example.com",
os.environ["MEMORYSYNC_PASSWORD"],
)
if result.get("mfa_required"):
print("Complete the configured MFA flow")
elif "tokens" in result:
access_token = result["tokens"]["access_token"]
# Store and use tokens only in an approved secure context.

Apply project scope explicitly

project_scope.py
with ControlPlaneClient(
"https://api.memorysync.io",
access_token=os.environ["MEMORYSYNC_ACCESS_TOKEN"],
project_id="project_default",
) as control:
default_hooks = control.list_webhooks()
selected_hooks = control.list_webhooks(project_id="project_selected")

Project-aware methods can use the client default or a non-empty per-call override. Resolve either value from authorized server state.

Create webhooks from trusted input

create_webhook.py
created = control.create_webhook(
"Memory events",
"https://hooks.example.com/memorysync",
["memory.created"],
project_id="project_selected",
)
print(created["id"])
# Treat a returned webhook secret as a secret and do not log it.

Use the async control-plane client

async_control_plane.py
import os
from memorysync import AsyncControlPlaneClient
async with AsyncControlPlaneClient(
"https://api.memorysync.io",
access_token=os.environ["MEMORYSYNC_ACCESS_TOKEN"],
) as control:
sessions = await control.list_sessions()
print(len(sessions["sessions"]))

Operation reference

Was this page helpful?