purra-mem0 · Python
English | 简体中文
Scoped memory, retrieval, and lifecycle management using the synchronous Mem0 OSS
Memory client. Requires Python 3.11+. SDK calls run in a worker thread.
Install
From the repository root:
python -m pip install . ./integrations/mem0/python
Managed callbacks use the native PurrA adapters included in this package; no LangChain installation is required.
Before importing Mem0, set MEM0_TELEMETRY=false and an application-owned
MEM0_DIR. Explicitly configure the LLM, embedder, vector_store, and
history_db_path. Hosted MemoryClient and AsyncMemory are not supported.
Save and read
The application supplies mem0_config, authenticated user_id, authorized
project_id, and a persistent journal_path:
from mem0 import Memory
from purra_mem0 import Mem0Memory, MemoryScope, MemorySource
sdk = Memory.from_config(mem0_config)
memory = Mem0Memory(
client=sdk,
scope=MemoryScope(user=user_id, project=project_id),
journal_path=journal_path,
)
async def save_preference():
saved = await memory.add(
"Reply in Chinese.",
source=MemorySource("preference:language", "1"),
key="preference:language:1",
)
return await memory.get(saved.ids[0])
add creates an active record by default; use state="pending" for review first.
get returns None for unavailable records. Updates, state changes, and deletions
require the current version and a stable operation key.
Connect to an Agent
from purra.retrieval import RetrieverTool
from purra_mem0 import MemoryContext
recall = RetrieverTool(
retriever=memory,
name="recallMemory",
description="Recall saved preferences and facts.",
)
context = MemoryContext(
memory=memory,
query=lambda request: request.latest_user_text(),
)
Register recall.registration in the Agent's tool catalog, or compose context
with its context providers. The memory instance already binds the scope.
For explicit record selection, use assemble_memory_context(memory, ids, allowance).
Managed model calls
Use the following configuration instead of a raw SDK client when calls need persistent budgets. Storage paths, embedding dimensions, and the budget key come from the application; the numeric limits below illustrate a budget configuration.
model_tasks is the runner supplied by a PurrA extension factory, and
model_request selects its model. The async embed(texts, signal) callback must
return EmbeddingResult with vectors and any reported input-token usage.
from purra_mem0 import (
MemoryBudget, MemoryProviders, create_managed_client, run_model,
)
client = create_managed_client(
embedding_dims=embedding_dimensions,
config={"vector_store": vector_store_config, "history_db_path": history_path},
)
providers = MemoryProviders(
budget=MemoryBudget(
key=budget_key,
max_llm_calls=4,
max_embedding_calls=64,
max_input_chars=100_000,
max_output_tokens=8192,
result_capacity_target_tokens=2048,
),
complete=run_model(model_tasks, model_request),
embed=embed,
)
memory = Mem0Memory(
client=client,
providers=providers,
scope=MemoryScope(user=user_id, project=project_id),
journal_path=journal_path,
allow_inference=True,
)
Use memory.budget_usage() to inspect admitted and reported usage. Raw SDK mode
reports internal usage as unknown.
Extract and review
With managed providers and allow_inference=True:
from purra_mem0 import MemoryWorkflow
workflow = MemoryWorkflow(memory)
async def capture(messages, source, operation_key):
return await workflow.capture(messages, source=source, key=operation_key)
This configuration reviews candidates and leaves them pending. To apply decisions,
pass an async policy(candidate, review) and a stable policy_revision to
MemoryWorkflow. Return an authorized MemoryResolution that retains the review
key, or None to leave the candidate pending.
To require authorization before messages can reach Mem0 or its providers, bind a host-issued grant to the exact capture intent:
from purra_mem0 import MemoryCaptureAuthorization, memory_capture_intent
capture_policy_id = "project-memory"
capture_policy_revision = "2026-09-09"
intent = memory_capture_intent(messages, source=source, metadata=metadata)
authorization = MemoryCaptureAuthorization(
intent_digest=intent,
policy_id=capture_policy_id,
policy_revision=capture_policy_revision,
principal_id=authenticated_user_id,
decision_id=host_decision_id,
)
workflow = MemoryWorkflow(
memory,
capture_policy_id=capture_policy_id,
capture_policy_revision=capture_policy_revision,
)
await memory.record_capture_authorization(
authorization,
key=f"capture-authorization:{host_decision_id}",
expires_at=capture_authorization_expires_at,
)
result = await workflow.capture(
messages, source=source, key=operation_key,
metadata=metadata, authorization=authorization,
)
The host owns authentication, eligibility and audit of the decision. Keep the authorization unchanged on retry. Missing or mismatched grants fail before the operation journal and Provider calls; changing a bound grant under the same key causes an idempotency conflict.
Call revoke_capture_authorization(policy_id, decision_id, key=...) to persist a
revocation. It prevents new extraction, review and activation under the decision
and hides records produced by it. Expiry only stops new processing. Neither path
physically deletes Mem0 content or history.
Lifecycle
Before shutdown, call await memory.drain() and memory.close(), then close SDK
and provider resources. For paging, withdrawal, evidence validation, and uncertain
writes, see the memory lifecycle guide.
Native managed providers
create_managed_client inject native LLM and Embedding adapters into a version-pinned, package-private Mem0 module. Calls retain the existing PurrA budget, cancellation and result validation. Explicit vector dimensions must agree; the managed path rejects LangChain vector stores. It neither patches the installed SDK nor starts a proxy server. See third-party notices. Raw SDK clients remain host-owned and do not acquire managed accounting automatically.
Host-controlled selection and relation proposals
MemoryContext(memory=memory, select_ids=host_select) accepts an async
host_select(request, signal) returning ordered memory IDs. Supply either
select_ids or the existing query, never both. The component rereads authorized
records, validates evidence, and fits complete records into the context budget.
The host owns retrieval combination, ordering, callback timeout and model costs.
propose_memory_relations(memory, refs, relations=allowed_names, extract=host_extract)
is exported from purra_mem0. Its async extractor receives (input, signal) and
returns objects with exactly from, to, relation, fromQuote, toQuote string
fields. IDs must match supplied MemoryRef revisions and quotes must occur in
those records. Returned immutable proposals do not write links or prove that a
relation is true. The host reviews proposals and explicitly calls memory.link.
No automatic model invocation, retry or adoption policy is installed.
Metadata
Release files for purra-mem0 1.0.2
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 |
|---|---|---|---|---|
| purra_mem0-1.0.2.tar.gz | 96.3 kB | With provenance | Details for purra_mem0-1.0.2.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| purra_mem0-1.0.2-py3-none-any.whl | Python 3 | none | any | Details for purra_mem0-1.0.2-py3-none-any.whl |
Total release size: 172.8 kB
Release files / purra_mem0-1.0.2.tar.gz
| Download URL | purra_mem0-1.0.2.tar.gz |
|---|---|
| Size | 96.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
b92ba3df25344b60730878241f1bfe58dc52e7a9352a14ab8f73c723c6feba2c
|
|
BLAKE2b-256 checksum How to use checksums |
c59c2b0133575e6c731e3d0bf1139f69190279b0cdf90039689d4af292a02b05
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 17, 2026.
Transparency logRelease files / purra_mem0-1.0.2-py3-none-any.whl
| Download URL | purra_mem0-1.0.2-py3-none-any.whl |
|---|---|
| Size | 76.4 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
05b921401e05cfee2be4638468453514ee45d8ab0d69f342460f82b51be67850
|
|
BLAKE2b-256 checksum How to use checksums |
df017d35d35c0b442291dececcb4a10eab500f1e91b7cc83531d5f8b3c1eb133
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/7.0.0 CPython/3.13.14
|
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 Oct 17, 2026.
Transparency logSecurity for purra-mem0 1.0.2
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
All 2 files in this release have been uploaded with provenance metadata.
Attestation for purra_mem0-1.0.2.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 Oct 17, 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.