Learn how to use supermemory with Python
api_key
keyword argument,
we recommend using python-dotenv
to add SUPERMEMORY_API_KEY="My API Key"
to your .env
file
so that your API Key is not stored in source control.
AsyncSupermemory
instead of supermemory
and use await
with each API call:
model.to_json()
model.to_dict()
python.analysis.typeCheckingMode
to basic
.
bytes
, or a PathLike
instance or a tuple of (filename, contents, media type)
.
PathLike
instance, the file contents will be read asynchronously automatically.
supermemory.APIConnectionError
is raised.
When the API returns a non-success status code (that is, 4xx or 5xx
response), a subclass of supermemory.APIStatusError
is raised, containing status_code
and response
properties.
All errors inherit from supermemory.APIError
.
Status Code | Error Type |
---|---|
400 | BadRequestError |
401 | AuthenticationError |
403 | PermissionDeniedError |
404 | NotFoundError |
422 | UnprocessableEntityError |
429 | RateLimitError |
>=500 | InternalServerError |
N/A | APIConnectionError |
max_retries
option to configure or disable retry settings:
timeout
option,
which accepts a float or an httpx.Timeout
object:
APITimeoutError
is thrown.
Note that requests that time out are retried twice by default.
logging
module.
You can enable logging by setting the environment variable SUPERMEMORY_LOG
to info
.
debug
for more verbose logging.
None
means null
or missingnull
, or missing entirely; in either case, its value is None
in this library. You can differentiate the two cases with .model_fields_set
:
.with_raw_response.
to any HTTP method call, e.g.,
APIResponse
object.
The async client returns an AsyncAPIResponse
with the same structure, the only difference being await
able methods for reading the response content.
.with_streaming_response
.with_streaming_response
instead, which requires a context manager and only reads the response body once you call .read()
, .text()
, .json()
, .iter_bytes()
, .iter_text()
, .iter_lines()
or .parse()
. In the async client, these are async methods.
client.get
, client.post
, and other
http verbs. Options on the client will be respected (such as retries) when making this request.
extra_query
, extra_body
, and extra_headers
request
options.
response.unknown_prop
. You
can also get all the extra fields on the Pydantic model as a dict with
response.model_extra
.
with_options()
:
.close()
method if desired, or with a context manager that closes when exiting.