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.
Release files for mgp-client 0.1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| mgp_client-0.1.1.tar.gz | 14.3 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mgp_client-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 30.3 kB
Release files / mgp_client-0.1.1.tar.gz
| Download URL | mgp_client-0.1.1.tar.gz |
|---|---|
| Size | 14.3 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
9bed0bfc150cd8991ea66cd713d6db9c46d710a1bfef3519019dd1f69c551550
|
|
BLAKE2b-256 checksum How to use checksums |
9b4ef1ca569ac420df7a4ad929d1fa09fd74363d16e66683f2aeb768635233c4
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 Apr 21, 2026.
Transparency logRelease files / mgp_client-0.1.1-py3-none-any.whl
| Download URL | mgp_client-0.1.1-py3-none-any.whl |
|---|---|
| Size | 16.0 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
cffb349a82014782b34e74a092efbd4309ce2a88600f6084ed32883b54346e5e
|
|
BLAKE2b-256 checksum How to use checksums |
ff0b24abf2e2d79aec51651ea1ac3d4de9bfa571c50e806d5537ae85f76d21b7
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
Yes |
| Uploaded via |
twine/6.1.0 CPython/3.13.12
|
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 Apr 21, 2026.
Transparency log