mapi-sdk
Python client for mapi — memory for AI agents.
pip install mapi-sdk
Quick start
from mapi_sdk import Mapi
client = Mapi(api_key="sm_...") # or set MAPI_API_KEY
client.spaces.get_or_create("ada")
client.memories.add("Prefers window seats", space="ada", tags=["travel"])
for hit in client.search.execute("seating preference", space="ada"):
print(round(hit.score, 3), hit.content)
Async is the same surface, awaited:
from mapi_sdk import AsyncMapi
async with AsyncMapi() as client:
await client.memories.add("Allergic to shellfish", space="ada")
hits = await client.search.execute("allergies", space="ada")
A space is one person's memory. Pass its slug or its id — slugs resolve once and cache, so the readable name costs one request per process rather than one per call.
Resources
| namespace | what it does |
|---|---|
client.memories |
add, add_many, get, list, delete, erase, context, lineage, versions, relate, relations |
client.search |
execute |
client.spaces |
list, get, create, get_or_create, delete |
client.graph |
get |
client.add(...) and client.query(...) exist as shortcuts for the two calls
that make up most usage.
Why a memory is not just a row
ctx = client.memories.context(memory_id, space="ada")
ctx.is_current # False if something replaced it
ctx.current_head # what replaced it
ctx.replaced # what it replaced
ctx.derived_from # the episodes it was computed from
ctx.contradicts # what disagrees with it
Superseded memories are excluded from search by default. They are still stored and still reachable — returning one beside its replacement is how an agent states last month's answer with this month's confidence.
Writing well
from datetime import UTC, datetime
client.memories.add(
"Ran the charity 5K in 27:12",
space="ada",
occurred_at=datetime(2023, 5, 20, tzinfo=UTC), # when it HAPPENED
tags=["running"],
extract=True, # also store the atomic claims this states
detect_conflicts=True, # flag anything it disagrees with
)
occurred_at is event time, not write time. Leaving it out makes a backfill
look like it all happened today, which breaks every "what order did these
come in" question afterwards.
extract=True spends a model call to decompose the text into standalone
claims, stored alongside the original with derived_from edges back to it.
Measured on LongMemEval it helps questions about what is true and hurts
questions about what happened, so it is a choice rather than an upgrade.
Errors
from mapi_sdk import NotFoundError, RateLimitError
try:
client.search.execute("anything", space="nope")
except NotFoundError as exc:
print(exc.request_id) # quote this when reporting a problem
AuthenticationError, PermissionError_, NotFoundError, ConflictError,
ValidationError, RateLimitError, ServerError, ConnectionError_ — all
subclasses of MapiError, all carrying the server's request_id.
429 and gateway errors retry automatically with jittered backoff. 500 does
not: a request that made the server throw will usually throw again, and
retrying only hides it.
Configuration
| argument | default |
|---|---|
api_key |
MAPI_API_KEY |
base_url |
the hosted service |
timeout |
30s |
max_retries |
3 |
The only dependency is httpx. Responses are plain dataclasses, each keeping
.raw, so a field added server-side is reachable the day it ships.
MIT licensed.
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 mapi_sdk-0.1.0.tar.gz.
File metadata
- Download URL: mapi_sdk-0.1.0.tar.gz
- Upload date:
- Size: 15.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
76c4c5d6f6e285c0ae956490aaf5d4b300aad561377b4f0f7d90e082b8c4021e
|
|
| MD5 |
02d4a0caea0cd8c1b62c1fd2a684e780
|
|
| BLAKE2b-256 |
d5f5b94ce0bf5a55d3dce87ec9c14e818cc4b83f2f159f66619fa03a9ff58437
|
File details
Details for the file mapi_sdk-0.1.0-py3-none-any.whl.
File metadata
- Download URL: mapi_sdk-0.1.0-py3-none-any.whl
- Upload date:
- Size: 14.6 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/7.0.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
77e4e4037a5f2c8091918d7ee32c6829eacb5678035d419f0f2a53fba4a72fd6
|
|
| MD5 |
91f5b75f5798f4919392a612c0c2faa8
|
|
| BLAKE2b-256 |
2af7807e9c4abcacb6de57b95a8a827e1420ea26415de3a12404e8c77b2a4855
|