Python client SDK for the Memory Governance Protocol
Project description
MGP Python SDK
Python client SDK for the Memory Governance Protocol.
Install
From the repository root:
python3 -m pip install ./sdk/python
Or for development with test dependencies:
cd sdk/python
python3 -m pip install -e ".[dev]"
If you're using the full repository toolchain, make install covers this automatically.
What It Includes
| Component | Description |
|---|---|
MGPClient |
Synchronous HTTP client for all protocol operations |
AsyncMGPClient |
Async client for async runtimes |
PolicyContextBuilder |
Helper for constructing policy context objects |
SearchQuery / AuditQuery |
Typed query builders |
| Auth helpers | ApiKeyAuth, BearerAuth, TLSConfig |
RetryConfig |
Retry configuration for transient failures |
| Pagination helpers | Iterators for search and audit result streams |
| Task polling | Helpers for async protocol operations |
| Error classes | Mapped from MGP protocol error codes |
Quick Example
from mgp_client import MGPClient, PolicyContextBuilder, SearchQuery
ctx = PolicyContextBuilder(
actor_agent="nanobot/main",
subject_id="user_123",
tenant_id="tenant_1",
)
with MGPClient("http://127.0.0.1:8080") as client:
# Write
client.write_memory(
ctx.build("write"),
{
"memory_id": "mem_1",
"subject": {"kind": "user", "id": "user_123"},
"scope": "user",
"type": "preference",
"content": {
"statement": "User prefers dark mode.",
"preference_key": "theme",
"preference_value": "dark",
},
"source": {"kind": "human", "ref": "chat:1"},
"created_at": "2026-03-17T12:00:00Z",
"backend_ref": {"tenant_id": "tenant_1"},
"extensions": {},
},
)
# Search
result = client.search_memory(
ctx.build("search"),
SearchQuery(
query_text="What does the user prefer for theme?",
intent_type="preference_lookup",
keywords=["dark", "theme"],
target_memory_types=["preference"],
),
)
print(result.data["results"])
Async Usage
from mgp_client import AsyncMGPClient, BearerAuth, PolicyContextBuilder
ctx = PolicyContextBuilder(
actor_agent="runtime/agent",
subject_id="user_123",
tenant_id="tenant_1",
)
async with AsyncMGPClient(
"http://127.0.0.1:8080",
auth=BearerAuth("secret-token"),
) as client:
capabilities = await client.get_capabilities()
print(capabilities["manifest"]["backend_kind"])
response = await client.export_memories(
ctx.build("read"),
{"execution_mode": "async", "limit": 100},
)
task = await client.wait_for_task(response.data["task"]["task_id"])
print(task["status"])
Auth And Retry
from mgp_client import ApiKeyAuth, MGPClient, RetryConfig, TLSConfig
client = MGPClient(
"https://gateway.example.com",
auth=ApiKeyAuth("gateway-api-key"),
tls=TLSConfig(verify=True),
retry=RetryConfig(max_attempts=3, backoff_seconds=0.2),
)
Pagination
for item in client.iter_search_results(
ctx.build("search"),
SearchQuery(query_text="preferences", limit=50),
):
print(item["memory"]["memory_id"])
Surface Coverage
- Core memory operations (write, search, get, update, expire, revoke, delete, purge)
- Lifecycle operations (initialize, capabilities)
- Batch write
- Export / import / sync
- Audit query
- Async task polling
Notes
- This SDK is transport-focused and independent of the reference gateway implementation.
write_memory()accepts canonical memory objects;write_candidate()acceptsMemoryCandidatepayloads.- Search and get responses include
consumable_text,return_mode, andredaction_info— runtimes should prefer those fields over assuming rawmemory.contentis always prompt-safe. - The SDK can be used against any gateway that implements the MGP HTTP binding.
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file mgp_client-0.1.1.tar.gz.
File metadata
- Download URL: mgp_client-0.1.1.tar.gz
- Upload date:
- Size: 14.3 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
9bed0bfc150cd8991ea66cd713d6db9c46d710a1bfef3519019dd1f69c551550
|
|
| MD5 |
81ebfbdb3d1a7ce2c72fba9bdc764ad3
|
|
| BLAKE2b-256 |
9b4ef1ca569ac420df7a4ad929d1fa09fd74363d16e66683f2aeb768635233c4
|
Provenance
The following attestation bundles were made for mgp_client-0.1.1.tar.gz:
Publisher:
publish-mgp-client.yml on HKUDS/MGP
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mgp_client-0.1.1.tar.gz -
Subject digest:
9bed0bfc150cd8991ea66cd713d6db9c46d710a1bfef3519019dd1f69c551550 - Sigstore transparency entry: 1350527366
- Sigstore integration time:
-
Permalink:
HKUDS/MGP@798a48f423f5e16dc11161e124cb75c01872a7af -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/HKUDS
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-mgp-client.yml@798a48f423f5e16dc11161e124cb75c01872a7af -
Trigger Event:
release
-
Statement type:
File details
Details for the file mgp_client-0.1.1-py3-none-any.whl.
File metadata
- Download URL: mgp_client-0.1.1-py3-none-any.whl
- Upload date:
- Size: 16.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.12
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
cffb349a82014782b34e74a092efbd4309ce2a88600f6084ed32883b54346e5e
|
|
| MD5 |
737f9facc9899f97fe4f832337a51660
|
|
| BLAKE2b-256 |
ff0b24abf2e2d79aec51651ea1ac3d4de9bfa571c50e806d5537ae85f76d21b7
|
Provenance
The following attestation bundles were made for mgp_client-0.1.1-py3-none-any.whl:
Publisher:
publish-mgp-client.yml on HKUDS/MGP
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
mgp_client-0.1.1-py3-none-any.whl -
Subject digest:
cffb349a82014782b34e74a092efbd4309ce2a88600f6084ed32883b54346e5e - Sigstore transparency entry: 1350527494
- Sigstore integration time:
-
Permalink:
HKUDS/MGP@798a48f423f5e16dc11161e124cb75c01872a7af -
Branch / Tag:
refs/tags/v0.1.1 - Owner: https://github.com/HKUDS
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
publish-mgp-client.yml@798a48f423f5e16dc11161e124cb75c01872a7af -
Trigger Event:
release
-
Statement type: