Skip to main content

memorysync

Official Python client for the MemorySync API. Sync and async, no surprises.

pip install memorysync

Quick start

from memorysync import MemorySyncClient

ms = MemorySyncClient(
    api_key="...",
    base_url="https://api.memorysync.io",
    project_id="proj_xxxxxxxxxxxxxxxx",   # optional
    end_user_id="user_42",                 # optional
)

ms.add("User prefers dark mode.")

result = ms.query("ui preferences", k=5)
for m in result.memories:
    print(m.id, m.text)

Async usage

import asyncio
from memorysync import AsyncMemorySyncClient

async def main():
    async with AsyncMemorySyncClient(api_key="...", base_url="...") as ms:
        result = await ms.query("ui preferences", k=5)
        print(result.memories)

asyncio.run(main())

Use MemorySyncClient as a context manager when you want deterministic connection cleanup:

with MemorySyncClient(api_key="...", base_url="...") as ms:
    ms.add("...")

Configuration

Argument Required Description
api_key yes Sent as X-API-Key. Provision in your MemorySync dashboard.
base_url yes Deployment URL of your MemorySync instance.
project_id no Pin every request to a project (X-Project-ID). Format: proj_ + 16 hex chars.
end_user_id no Identify which of your users this client speaks for (X-End-User-ID).
timeout no Per-request timeout in seconds. Default 30.0.
transport no Inject a custom httpx transport (tests, retries, proxies).

end_user_id can also be passed per-call on add() to override the client default.

Methods

Every method maps 1:1 to a real HTTP route. The two clients share the same surface; only the call style differs (sync vs await).

Method Route
add(text, **opts) POST /memory/add
bulk_add(items, *, deduplicate=True) POST /memory/bulk-add
query(query, *, k=None, ...) POST /memory/query
get(memory_id) GET /memory/{id}
update(memory_id, **fields) PATCH /memory/{id}
forget(memory_ids, *, reason=None) DELETE /memory/forget
summarize(memory_ids, *, lossless=False) POST /memory/summarize
compose(prompt_template, *, recall_k=None) POST /memory/compose
export_all() GET /memory/export
create_relation(from_id, **opts) POST /memory/{id}/relations

add returns one of two shapes

add() runs through MemorySync's extraction pipeline, so input that carries no high-value content is intentionally skipped. Branch on the type of the result:

from memorysync import AddSkippedResponse, Memory

result = ms.add("User prefers dark mode.")
if isinstance(result, AddSkippedResponse):
    print("skipped:", result.reason)
else:
    assert isinstance(result, Memory)
    print(result.id, result.text)

Control-plane client

Dashboard and administrative routes use bearer authentication, not the memory client's API key. Tokens are never persisted or refreshed automatically. Responses are typed dictionaries with snake_case keys, including routes whose wire response uses camelCase.

import os
from memorysync import ControlPlaneClient

with ControlPlaneClient(
    "https://api.memorysync.io",
    access_token=os.environ["MEMORYSYNC_ACCESS_TOKEN"],
    project_id="project_abc123",  # optional X-Project-ID default
) as control:
    members = control.list_team_members()
    hooks = control.list_webhooks()

# Login is the only operation that does not require a configured token.
with ControlPlaneClient("https://api.memorysync.io") as control:
    login = control.login("developer@example.com", os.environ["MEMORYSYNC_PASSWORD"])

AsyncControlPlaneClient exposes the same methods with await and aclose(). Both clients accept base_url, optional access_token, optional project_id, timeout, and an injectable sync/async httpx transport. Project-scoped operations accept a per-call project_id override.

Method HTTP route
bulk_revoke_api_keys POST /org/api-keys/bulk-revoke
test_api_key POST /org/api-keys/{key_id}/test
login POST /auth/login
get_current_plan GET /org/billing/current-plan
list_team_members GET /admin/team/members
suspend_team_member PATCH /admin/team/members/{member_id}
remove_team_member DELETE /admin/team/members/{member_id}
list_sessions GET /auth/sessions
revoke_session POST /auth/sessions/{session_id}/revoke
list_audit_events GET /admin/audit-logs
list_integrations GET /api/v1/integrations/catalog
create_organization POST /organizations
list_organizations GET /organizations
list_organization_members delegates to list_team_members
get_organization_settings GET /admin/tenant-settings
list_projects GET /org/projects
create_webhook POST /org/webhooks
list_webhooks GET /org/webhooks
update_webhook PATCH /org/webhooks/{endpoint_id}
delete_webhook DELETE /org/webhooks/{endpoint_id}
test_webhook POST /org/webhooks/{endpoint_id}/test
replay_webhook_deliveries POST /org/webhooks/{endpoint_id}/replay
list_webhook_deliveries GET /org/webhooks/{endpoint_id}/deliveries

Errors

Every non-2xx response raises a typed subclass of MemorySyncError:

Class When
AuthError 401 / 403 — bad key, missing scope.
ValidationError 400 / 409 / 422.
NotFoundError 404 — record not visible to the caller.
RateLimitError 429 — read err.retry_after_seconds.
ServerError 5xx.
MemorySyncError Network errors, timeouts, anything else.

Every error carries status_code, response, and the server-issued request_id (when present) for support escalation.

import time
from memorysync import RateLimitError

try:
    ms.add("...")
except RateLimitError as e:
    time.sleep(e.retry_after_seconds)

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

memorysync-1.7.1.tar.gz (34.4 kB view details)

Uploaded Source

Built Distribution

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

memorysync-1.7.1-py3-none-any.whl (36.7 kB view details)

Uploaded Python 3

File details

Details for the file memorysync-1.7.1.tar.gz.

File metadata

  • Download URL: memorysync-1.7.1.tar.gz
  • Upload date:
  • Size: 34.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.5

File hashes

Hashes for memorysync-1.7.1.tar.gz
Algorithm Hash digest
SHA256 c2a295877533852200f4aa9c7afedd2648f1245e3c634987fde4affe64eb3b63
MD5 a83d6c5340024987c43b8b7045e3792c
BLAKE2b-256 aed2c2228e2c46e64319bb49922f753f4e3d8ceacc51c14b11972f6b3f9c2715

See more details on using hashes here.

File details

Details for the file memorysync-1.7.1-py3-none-any.whl.

File metadata

  • Download URL: memorysync-1.7.1-py3-none-any.whl
  • Upload date:
  • Size: 36.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/7.0.0 CPython/3.11.5

File hashes

Hashes for memorysync-1.7.1-py3-none-any.whl
Algorithm Hash digest
SHA256 af608d0d5138bb1d1dd85c234e48e724bfd4b8eec934cb235a567964830a5b02
MD5 85914e692dd3063185e231972cc27456
BLAKE2b-256 0170f80700ff6289b1177a13b661a8e307b40bbcc323a50b116d55783318ff2a

See more details on using hashes here.

Release history Release notifications | RSS feed

1.9.2

2 files

1.9.1

2 files

1.9.0

2 files

1.8.0

2 files

1.7.3

2 files

1.7.2

2 files

This release

1.7.1 This release

2 files

1.7.0

2 files

1.6.0

2 files

1.5.0

2 files

1.4.0

2 files

1.3.0

2 files

1.2.0

2 files

1.1.1

2 files

1.1.0

2 files

1.0.1

2 files

1.0.0

2 files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page