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.
It is not on PyPI yet. Install it from a checkout of this repository:
pip install ./clients/python
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
addis safe when every message has amessage_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_idfrom your application's authenticated session, never from a model's tool arguments. Hand the model aclient.for_user(user_id)view, whose user cannot be changed. - Give an agent's key only
MemoryReadandMemoryWrite. AddMemoryDeleteonly if the agent may delete memories. Never give itUserDeleteor admin scopes, and do not exposeforget_useras 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.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| memquira-0.1.0.tar.gz | 22.5 kB | With provenance | Details for memquira-0.1.0.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| memquira-0.1.0-py3-none-any.whl | Python 3 | none | any | Details for memquira-0.1.0-py3-none-any.whl |
Total release size: 42.4 kB
Release files / memquira-0.1.0.tar.gz
| Download URL | memquira-0.1.0.tar.gz |
|---|---|
| Size | 22.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
03102880def070f632e5f8c973c039aaf10decf052b06574279767a6fc9de995
|
|
BLAKE2b-256 checksum How to use checksums |
e9039bd49f34b1905645c13d38c49490bf5d7239dd7110ca30c44af43f84bc5c
|
| 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 2, 2026.
Transparency logRelease files / memquira-0.1.0-py3-none-any.whl
| Download URL | memquira-0.1.0-py3-none-any.whl |
|---|---|
| Size | 20.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
2f15dc8d073e6142592c383a2d857ea48bff6701236ed150b87710eaede6d207
|
|
BLAKE2b-256 checksum How to use checksums |
c1433fc12731df3d0cb970fe23ade4f64dd0ae5a8d23c436266e54d8b1e6df07
|
| 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 2, 2026.
Transparency logSecurity for memquira 0.1.0
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.
Attestation for memquira-0.1.0.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 2, 2026.
Transparency logA 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.