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.
Metadata
Release files for mapi-sdk 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 | |
|---|---|---|---|
| mapi_sdk-0.1.1.tar.gz | 17.9 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| mapi_sdk-0.1.1-py3-none-any.whl | Python 3 | none | any | Details |
Total release size: 34.1 kB
Release files / mapi_sdk-0.1.1.tar.gz
| Download URL | mapi_sdk-0.1.1.tar.gz |
|---|---|
| Size | 17.9 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
066b419223c326d32c02e2e64964e7c5da3ba24d5be25de097fad404dc46343e
|
|
BLAKE2b-256 checksum How to use checksums |
67f91e53aa14c9c4c391901d6326ccadb482c34e142c0fedfce1cf45f283c90d
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.7
|
Release files / mapi_sdk-0.1.1-py3-none-any.whl
| Download URL | mapi_sdk-0.1.1-py3-none-any.whl |
|---|---|
| Size | 16.2 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
102e37726a115f39cc7c92623891701262a5b5c0a0e81730ade531ef8936e246
|
|
BLAKE2b-256 checksum How to use checksums |
55c3402a996469f08b06fc48514dd18d27a7389d3e48dd0ce32036dd30930b9c
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/7.0.0 CPython/3.13.7
|