Skip to main content

Memquira Python client

A small, typed client for the Memquira memory API, with synchronous and asynchronous versions. It covers the operations an application or agent needs:

  • store messages;
  • search memories;
  • build a prompt context;
  • list memories;
  • delete one memory;
  • erase a user.

Install it from PyPI:

pip install memquira

Python 3.10 or newer; the only dependency is httpx.

Quick start

Start a local server first; the Quick start runs one with mock models, no keys and no cost.

from memquira import Memquira

with Memquira("http://127.0.0.1:8080", api_key="memcore_dev_key", org_id="demo") as client:
    alice = client.for_user("alice")

    result = alice.add("I am vegetarian and I live in Lisbon.", session_id="chat-1")
    print(result.summary.added, [m.content for m in result.memories])

    for hit in alice.search("vegetarian Lisbon", limit=5):
        print(f"{hit.score:.3f}  {hit.content}")

    context = alice.context("Suggest a restaurant for tonight", token_budget=500)
    print(context.text)  # ready to place in a system prompt

memcore_dev_key is the fixed key of the local development stack, which uses dev authentication. Never use it anywhere else. With database authentication, create an application key with only the scopes it needs, as described in Getting started.

base_url, api_key and org_id can also come from MEMQUIRA_URL, MEMQUIRA_API_KEY and MEMQUIRA_ORG_ID:

client = Memquira()  # reads the three environment variables

Async

from memquira import AsyncMemquira

async with AsyncMemquira() as client:
    alice = client.for_user("alice")
    await alice.add("I prefer meetings after 2pm.")
    context = await alice.context("Schedule a call with this user")

Operations

Method Endpoint Scope
add(user_id, messages, *, session_id, session_timestamp, metadata) POST /api/v1/memories MemoryWrite
search(user_id, query, *, limit, memory_types, include_history, retrieval_mode) POST /api/v1/memories/search MemoryRead
context(user_id, query, *, token_budget, include_items, packing, exclude_message_ids) POST /api/v1/memories/context MemoryRead
list_memories(user_id, *, limit, cursor, memory_type, query), iter_memories(...) GET /api/v1/users/{user_id}/memories MemoryRead
delete(user_id, memory_id) DELETE /api/v1/users/{user_id}/memories/{memory_id} MemoryDelete
forget_user(user_id) DELETE /api/v1/users/{user_id} UserDelete
version(), ready() GET /api/v1/version, GET /health/ready none

Results are typed dataclasses (AddResult, SearchHit, MemoryContext, MemoryPage, ...). Each keeps the server's full JSON in raw, so fields added by newer servers are still available. The API reference describes every field.

add runs the server's language model to extract memories, so it takes seconds, not milliseconds. In a chat application, store the finished turn after replying, not before.

Messages and safe retries

messages can be a string (one user message), a Message, a dict, or a list of them. A Message or a string gets a unique message_id when it is created:

from memquira import Message

turn = [Message("user", "We moved the launch to March."), Message("assistant", "Noted.")]
client.add("alice", turn, session_id="chat-7")

The server stores a message with a given message_id once. Sending the same Message objects again is a safe retry: the server answers with the first call's result and stores nothing new. Reusing an id for a different message is rejected with ConflictError (MESSAGE_ID_CONFLICT).

Do not send the same messages from two places at once; resend them only after the first attempt has failed.

The client retries automatically, up to max_retries times (default 2):

  • 429: always, after the server's Retry-After.
  • 503: only for requests that are safe to repeat. Reads and deletes are always safe (deleting something already deleted succeeds again), and add is safe when every message has a message_id.
  • Connection failures before the request was sent: always.
  • Timeouts and dropped connections after sending: only for requests that are safe to repeat.

The client never waits longer than max_retry_wait seconds (default 30). A longer Retry-After is raised as RateLimitError with retry_after set.

Errors

Exception When
BadRequestError 400: invalid request
AuthenticationError 401: missing, unknown or revoked key
PermissionDeniedError 403: missing scope or wrong organization
NotFoundError 404: no such memory for this user
ConflictError 409: for example MESSAGE_ID_CONFLICT
RateLimitError 429: rate limit or quota; see retry_after
ServiceUnavailableError 503: overloaded, draining or recovering; retry later
ServerError other 5xx, including model-provider failures (502)
TransportError no HTTP response: connection refused, timeout

All of them derive from MemquiraError. APIError subclasses carry status_code, code, message, request_id and details.

Using it in an agent

Memquira keys belong to an organization, not to an end user. Whoever chooses user_id can read that user's memories, so:

  • Take user_id from your application's authenticated session, never from a model's tool arguments. Hand the model a client.for_user(user_id) view, whose user cannot be changed.
  • Give an agent's key only MemoryRead and MemoryWrite. Add MemoryDelete only if the agent may delete memories. Never give it UserDelete or admin scopes, and do not expose forget_user as a tool.

For Claude Code and other MCP clients there is a ready-made MCP server built on this client: integrations/mcp-python.

Development

cd clients/python
pip install -e ".[test]"
pytest                      # unit tests against a mocked transport
ruff check . && ruff format --check . && mypy

tests/test_e2e_local.py runs the client against a real server. It is skipped unless MEMQUIRA_E2E_URL, MEMQUIRA_E2E_API_KEY and MEMQUIRA_E2E_ORG_ID are set. Point it at a server with mock models, such as the local Docker stack. It writes and then erases its own test users.

Metadata

Release files for memquira 0.1.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for memquira 0.1.1
File Size Uploaded Provenance Actions
memquira-0.1.1.tar.gz 22.4 kB With provenance Details for memquira-0.1.1.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for memquira 0.1.1
File Interpreter ABI Platform Actions
memquira-0.1.1-py3-none-any.whl Python 3 none any Details for memquira-0.1.1-py3-none-any.whl

Total release size: 42.4 kB

Release files / memquira-0.1.1.tar.gz

Download URL memquira-0.1.1.tar.gz
Size 22.4 kB
Tags Source
SHA-256 checksum
How to use checksums
96c01931263db44220086bde63fae4d7f0975f0635203b1f3379eb53dded641d
BLAKE2b-256 checksum
How to use checksums
dcfbdd4e7a648a1aa6731635c7b984b77b7926590ad0956fbac35f87d04e58ab
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.

Transparency log

Release files / memquira-0.1.1-py3-none-any.whl

Download URL memquira-0.1.1-py3-none-any.whl
Size 19.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
9232d38f78d8ab36a5fb9b8142134fab1f73ebf49a7223b34d2827f93a686321
BLAKE2b-256 checksum
How to use checksums
805836a90956cf35d1c91568361be12c8797c808c5acc465eec53f4550d2f1f0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via twine/7.0.0 CPython/3.13.16

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.

Transparency log

Security for memquira 0.1.1

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

Full provenance

Both files in this release have been uploaded with provenance metadata.

Select from 2 files

Attestation for memquira-0.1.1.tar.gz

PyPI Publish Attestation

PyPI verified that this artifact, at this checksum, originated from the publisher listed below.

Signed by GitHub Actions, verified by PyPI on Dec 3, 2026.

Transparency log

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

0.1.1 This release

2 release files Full provenance

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