Python SDK
Reference for the Smritea Python SDK. Install it, create a client, and call add, search, get and delete.
The Python SDK is the smritea-sdk package. It gives you a synchronous SmriteaClient with four calls: add, search, get and delete. It needs Python 3.9 or later.
Install
pip install smritea-sdkImport the client and the scope type from smritea:
from smritea import MemoryScope, SmriteaClientCreate a client
SmriteaClient takes your API key and your app ID. You must pass both. Create them in the dashboard; see Create an app and API key.
| Argument | Type | Default | Description |
|---|---|---|---|
api_key | str | none | The API key, in the form smrt_<prefix>_<secret>. |
app_id | str | none | The app ID, in the form app_.... |
base_url | str | https://api-us.smritea.ai | The host for your region. See Regions. |
max_retries | int | 2 | Retries after a rate limit. 0 turns retries off. |
trace_id | str or None | None | A trace ID to send with each call. A bad value raises ValueError. |
http_client | urllib3.PoolManager or None | None | Your own HTTP client. Set timeouts and proxies here. |
The client has no timeout argument. Set a timeout on the http_client you pass in.
Methods
The table lists the client methods and what each one returns.
| Method | Returns | Description |
|---|---|---|
add(content, *, scope, metadata, event_occurred_at, relative_standing) | MemoryCreationResult | Extracts and stores memories from the text. |
search(query, *, ...) | list[SearchResult] | Finds memories that match the query. |
get(memory_id) | Memory | Returns one memory by ID. |
delete(memory_id) | None | Deletes one memory by ID. |
The get_all method exists but raises NotImplementedError. Use search to find memories.
Add options
The table lists the options that add accepts.
| Option | Type | Description |
|---|---|---|
scope | MemoryScope | Who and what the memory belongs to. |
metadata | dict | Values must be strings, integers or floats. |
event_occurred_at | str | An RFC 3339 string, such as 2026-11-05T10:00:00Z. Smritea uses it to resolve words like "yesterday" and to date the memory. |
relative_standing | RelativeStanding | The importance and decay settings for the memory. |
Build a RelativeStanding with importance, decay_factor and decay_function. Import it from smritea.types, because the top-level package does not export it. importance ranges from 0 to 1. decay_factor is 0 or higher. decay_function takes exponential, gaussian or linear. Decay affects quick_search, context_aware_search and deep_search with temporal or rrf_temporal; importance affects deep_search with rrf or rrf_temporal.
Search options
The table lists the options that search accepts.
| Option | Type | Description |
|---|---|---|
scope | MemoryScope | Limits results to this scope. |
speaker_actor_id | str | Who is asking. It never filters results. |
limit | int | Most results to return. Omit it to use the app default. |
method | str | quick_search, deep_search or context_aware_search. |
reranker_type | str | Applies to deep_search only. See Search methods and rerankers. |
graph_depth | int | A value from 1 to 5. |
valid_at | str | An RFC 3339 time. Returns memories valid at that moment. |
from_time, to_time | str | An RFC 3339 range. Use either one alone for an open range. |
metadata_filter | dict | See Filter by metadata. |
You cannot combine valid_at with from_time or to_time.
Memory scope
MemoryScope decides who a memory belongs to. Every field is optional. See Memory scope for the rules.
| Field | Description |
|---|---|
actor_id | The actor's ID, up to 64 characters. Set it with actor_type. |
actor_type | user, agent or system. |
actor_name | A display name, up to 255 characters. Used by add only. |
conversation_id | A conversation ID, up to 64 characters. |
source_type | conversation, document or api. Defaults to api. |
participant_ids | A list of one or more IDs. Search only. |
Results
search returns a list of SearchResult. Each one has a score and a memory.
| Field | Description |
|---|---|
score | The relevance score. |
memory.content | The memory text. |
memory.id | The memory ID. |
memory.metadata | The metadata you stored. |
memory.scope | The scope fields of the memory. |
memory.active_from, memory.active_to | When the memory is valid. |
add returns a MemoryCreationResult.
| Field | Description |
|---|---|
memories | The memories the call stored. Empty when explicit_skip is true. |
facts_extracted | How many facts the text held. |
skipped_count | How many facts the call skipped. |
updated_count | How many existing memories the call updated. |
explicit_skip | True when nothing was worth storing. |
get returns a Memory. It has id, app_id, content, created_at, updated_at, active_from, active_to, metadata and scope.
Exceptions
Every error derives from SmriteaError. The SDK picks the class from the HTTP status.
| Exception | HTTP status | When |
|---|---|---|
SmriteaBadRequestError | 400 | A parameter is invalid. |
SmriteaUnauthorizedError | 401 | The API key is missing or wrong. |
SmriteaPaymentRequiredError | 402 | Your plan quota has run out. |
SmriteaForbiddenError | 403 | The key cannot do this. |
SmriteaNotFoundError | 404 | The memory does not exist. |
SmriteaConflictError | 409 | The request conflicts with current state. |
SmriteaUnprocessableError | 422 | The request is well formed but not allowed. |
SmriteaTooManyRequestsError | 429 | You hit a rate limit. |
SmriteaError | other | Any other failure, including 5xx. |
Each exception has http_status, code, retryable, body and request_id. SmriteaTooManyRequestsError also has retry_after, in seconds.
The SDK retries a 429 up to max_retries times. It never retries a 402. For every code, see Errors and codes.
Example
This script stores a memory, searches for it and handles the failures.
import os
from smritea import (
MemoryScope,
SmriteaClient,
SmriteaError,
SmriteaPaymentRequiredError,
SmriteaTooManyRequestsError,
)
client = SmriteaClient(
api_key=os.environ["SMRITEA_API_KEY"],
app_id=os.environ["SMRITEA_APP_ID"],
)
alice = MemoryScope(actor_id="alice", actor_type="user")
try:
client.add("Alice is vegetarian and loves hiking", scope=alice)
results = client.search("What does Alice eat?", scope=alice)
for r in results:
if r.memory:
print(f"{r.score:.2f} {r.memory.content}")
except SmriteaPaymentRequiredError:
print("Plan quota used up (402)")
except SmriteaTooManyRequestsError as e:
print(f"Rate limited. Retry in {e.retry_after}s")
except SmriteaError as e:
print(e.http_status, e.code, e.request_id)Don't see your language? Request it on GitHub. Search existing requests first and add a 👍 if yours is there. That helps the Smritea team rank requests.
Last updated on



