Metadata-Version: 2.4
Name: localmem-memory
Version: 0.1.2
Summary: The localmem Memory API: memory of each of your customers, with the source and date of every fact. `localmem-memory login` pairs a terminal with a project.
License: Apache-2.0
Project-URL: Homepage, https://localmem.org/docs/memory-api/sdks
Keywords: memory,ai-agents,llm,customer-memory,localmem
Classifier: License :: OSI Approved :: Apache Software License
Requires-Python: >=3.9
Description-Content-Type: text/markdown
License-File: LICENSE
License-File: NOTICE
Dynamic: license-file

# localmem-memory

Memory of each of your customers, for your product and its AI agents. Your
backend sends what it learns about a customer (documents, notes, chat
turns, facts); localmem keeps it as facts, each with the document it came
from and the date it became true, and answers what is true now or on any
past date.

This is the Python SDK for the [localmem Memory API](https://localmem.org/memory).
It signs every request, retries safely and pairs your terminal for a key.
**Server-side only**: a key's secret must never reach a browser or an app.

- Python 3.9 or later, standard library only.
- [Quickstart](https://localmem.org/docs/memory-api/quickstart) ·
  [API reference](https://localmem.org/docs/memory-api) ·
  [Data contract](https://localmem.org/docs/memory-api/data-contract) ·
  [Pricing](https://localmem.org/pricing#memory-api-h)

## 1. Get a key

[Start building](https://app.localmem.org/sign-up?for=api) (sign up or sign
in, answer four questions). You get an account in test, a project and a
test key. Then, in your product's folder:

```sh
pip install localmem-memory
localmem-memory login
```

It prints a code such as `WDJB-MJHT` and opens `app.localmem.org/pair`.
Check the code matches, choose the project and approve. The terminal then
writes `LOCALMEM_PROJECT`, `LOCALMEM_KEY_ID` and `LOCALMEM_KEY_SECRET` into
`.env` (or the file `--env-file` names) and adds that file to `.gitignore`.
The code lasts 10 minutes. Options: `--env-file PATH`, `--device NAME`,
`--no-browser`.

Pairing gives **test** keys only. Live keys are made by an admin in the app
(Team → API) once your account is approved to go live.

## 2. Write and recall

```python
from localmem_memory import Memory

lm = Memory()  # reads the three variables from the environment

# One localmem customer per user or company of yours, made with your own id.
tenant = lm.customers.create("cust-42")["tenant"]

# A document is read by a model into facts, kept with the document as source.
lm.documents.send(tenant, "Ada Byron joined Acme as head of research on 3 March.",
                  as_of="2026-03-03T09:00:00Z")

# Everything known about Ada, each fact with its source and date.
facts = lm.recall(tenant, "Ada Byron")["facts"]

# What was true on a past date.
then = lm.search(tenant, "Who leads research?", at_time="2026-02-01T00:00:00Z")
```

## What you can call

| Call | What it does |
|---|---|
| `customers.create(ref, phi=None)` | Makes a customer (its own memory) for your id `ref`. The same `ref` again answers the same customer, so a retry is safe. Never put a name or other content in `ref`. |
| `customers.list()`, `customers.get(tenant)` | Your customers. |
| `customers.delete(tenant)` | Access stops at once; the [data contract](https://localmem.org/docs/memory-api/data-contract) says what follows. |
| `tenants` | The same group as `customers`, under the API's name. |
| `documents.send(tenant, text, title=, as_of=, tags=, external_ref=)` | Reads a document (at most 200 KB) into facts. Up to 20 KB answers with the facts written; above, it is read in the background and answers `{ status, follow }`. |
| `documents.wait(tenant, document_id)` | Waits for a background document to be written or failed. |
| `facts(tenant, facts=[...])` | Facts you extracted yourself; nothing goes to a model. |
| `write(tenant, content)` | A memory in your own words. |
| `search(tenant, query, k=, at_time=)` | Facts that answer a question, ranked, with their sources. |
| `recall(tenant, entity, at_time=)` | A subject's facts. Without `at_time`, its whole history: a replaced value carries `retired_at`. |
| `profile(tenant, scope=)` | A short summary of what is known, as Markdown. |
| `get(tenant, event_id)`, `forget(tenant, target_id)` | Read one memory; hide one from answers from now on. |
| `usage(from_=, to=)` | Documents, facts, writes, reads and tokens by customer and day. |

The [API reference](https://localmem.org/docs/memory-api) has every field
and answer.

## Errors and retries

A request that is not a success raises `LocalmemError` with `status`,
`error` (a code to act on, such as `monthly_limit`, `rate_limited` or
`no_tenant`), `message` (for people), `request_id` and `retry_after`.

The SDK sends an `Idempotency-Key` with every document, so a document sent
again after a timeout is read once. It retries a rate limit or a busy
server, and a timeout or server error when sending again cannot do the work
twice, waiting as `Retry-After` says (up to 60 seconds). A monthly limit is
not retried: its message says the limit and the date it resets. Quote
`request_id` when you write to support@localmem.org.

```python
Memory(timeout=120, max_retries=3)  # the defaults
```

## Test and live

A test key (`lm_test_…`) reaches only customers made with a test key; a live
key (`lm_live_…`) only live ones. Test is free, always, within small monthly
limits. Live starts once we approve your account, which you ask for in
Team → API. Health data waits for a business associate agreement: mark such
a customer `phi=True` and tell us before you go live.

## Licence

Apache-2.0 (see `LICENSE` and `NOTICE`). The licence covers this SDK, not
the localmem service, and grants no use of the localmem name.
