Skip to main content

etchmem

Python SDK for etchmem-server — the Knowledge Consolidation Engine for AI agents.

Your agents' daily activity is full of hard-won facts — deals signed, decisions made, preferences learned. etchmem-server turns that stream of raw signals into a clean, typed, versioned knowledge base: one consolidated belief per fact, with confidence, provenance, conflict status, and full version history — queryable at any point in time.

This package is the REST client. One dependency (httpx), sync and async, fully typed responses.

pip install etchmem

Note on MCP: etchmem-server also exposes an MCP interface at /mcp with the same operations as tools. MCP clients (Claude, agent frameworks, IDEs) connect to it directly over the MCP protocol — no SDK needed. This package is for REST integrations only.


Quickstart

Run the server (see the etchmem-server repo — docker compose up), then:

from etchmem import EtchMem

mem = EtchMem("http://localhost:8000")   # default; also reads ETCHMEM_BASE_URL

# Deposit a raw signal — no pre-structuring needed
mem.remember(
    "Acme signed the Q3 renewal at $40k. Maria approved the discount.",
    source="agent-33",
    scope="sales",
)

# Semantic recall over consolidated beliefs
for hit in mem.recall("what did Acme sign?", top_k=5):
    print(f"[{hit.origin}] {hit.content}  (confidence={hit.confidence})")

Async

from etchmem import AsyncEtchMem

async with AsyncEtchMem("http://localhost:8000") as mem:
    await mem.remember("...", source="agent-33", scope="sales")
    hits = await mem.recall("what did Acme sign?")

API surface

The SDK mirrors the seven REST endpoints one-to-one:

Method Endpoint Returns
remember(data, *, source, scope, extract_mode="deferred", metadata=None) POST /remember RememberResult
recall(query, *, scope=None, source=None, top_k=5, include_signals=True, as_of=None) POST /recall RecallResponse (iterable of RecallResult)
sleep() POST /sleep SleepResult
export() POST /export ExportResult (list of Etch)
history(etch_id) GET /etch/{id}/history History (iterable of EtchVersion)
stats() GET /stats Stats
health() GET /health Health

All responses are plain dataclasses — see etchmem/models.py.

remember

extract_mode="immediate" marks the signal urgent (claims extracted on the next worker tick); "deferred" (default) batches it cheaply. Deposits are idempotent — identical content returns stored=False.

recall with time-travel

Pass as_of (ISO-8601) to recall what the system believed at that moment — for auditing decisions or incident forensics:

hits = mem.recall("Acme contract value", as_of="2026-06-01T00:00:00Z")

sleep

The server consolidates on its own cadence. mem.sleep() forces one pipeline tick now (batch → extract claims → fold into etches) — useful in tests and demos:

tick = mem.sleep()
print(tick.etches_formed, tick.etches_updated, tick.contested)

history

Every belief change writes an immutable version snapshot:

for v in mem.history(etch_id):
    print(v.version, v.current_value, v.status, v.confidence)

Configuration

Parameter Env var Default
base_url ETCHMEM_BASE_URL http://localhost:8000
api_key ETCHMEM_API_KEY none (sent as Authorization: Bearer … when set)
timeout 30 s

You can also inject your own httpx.Client / httpx.AsyncClient via the client parameter (custom TLS, proxies, retries).

Errors

All SDK errors derive from EtchMemError:

  • ConnectionError — server unreachable (network / timeout)
  • APIError — non-2xx response (.status_code, .detail), with subclasses NotFoundError (404), AuthenticationError (401/403), ServerError (5xx)
from etchmem import EtchMem, NotFoundError

try:
    mem.history("no-such-etch")
except NotFoundError as e:
    print(e.detail)

Development

pip install -e ".[dev]"
python -m pytest tests/

Releasing to PyPI: see PIP-DEPLOY.md.

License

MIT

Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

etchmem-0.2.1.tar.gz (15.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

etchmem-0.2.1-py3-none-any.whl (14.7 kB view details)

Uploaded Python 3

File details

Details for the file etchmem-0.2.1.tar.gz.

File metadata

  • Download URL: etchmem-0.2.1.tar.gz
  • Upload date:
  • Size: 15.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for etchmem-0.2.1.tar.gz
Algorithm Hash digest
SHA256 44ad6430c6721debf4c124fb7b8cfb7b0593a1e4fd10649e1bc8e7e108e539ad
MD5 b4c590de3d4757dfbb8c708174796d3e
BLAKE2b-256 f2420f0e67bfeb36b5631251f00f7984a1674848eff90304e8af5a02f450a1ec

See more details on using hashes here.

File details

Details for the file etchmem-0.2.1-py3-none-any.whl.

File metadata

  • Download URL: etchmem-0.2.1-py3-none-any.whl
  • Upload date:
  • Size: 14.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.11

File hashes

Hashes for etchmem-0.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 a6204fde2ce68009f8c0829a8b9fecf0477d2015dd57f5df8d5fed2e961efb91
MD5 1f4c2363bb6f2a0e4de6d1c2455c7d44
BLAKE2b-256 4d4c89c0275dbcd46a719e3ada4fd57e71c898a15406e33afa0f199779a7c024

See more details on using hashes here.

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 files

0.2.0

2 files

0.1.6

2 files

0.1.5

2 files

0.1.4

2 files

0.1.3

2 files

0.1.2

2 files

0.1.1

2 files

0.1.0

2 files

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page