Python
The Raccoon AI Python library provides convenient access to the Raccoon AI REST API from any Python 3.8+ application. The library includes type definitions for all request params and response fields, and offers both synchronous and asynchronous clients powered by httpx.
Installation
Usage
While you can provide a secret_key
keyword argument,
we recommend using python-dotenv
to add RACCOON_SECRET_KEY="My Secret Key"
to your .env
file
so that your Secret Key is not stored in source control.
Async usage
Simply import AsyncRaccoonAI
instead of RaccoonAI
and use await
with each API call:
Functionality between the synchronous and asynchronous clients is otherwise identical.
Streaming responses
The async client uses the exact same interface.
Retries
Certain errors are automatically retried 2 times by default, with a short exponential backoff. Connection errors (for example, due to a network connectivity problem), 408 Request Timeout, 409 Conflict, 429 Rate Limit, and >=500 Internal errors are all retried by default.
You can use the max_retries
option to configure or disable retry settings:
Timeouts
By default, requests time out after 1 minute. You can configure this with a timeout
option,
which accepts a float or an httpx.Timeout
object:
On timeout, an APITimeoutError
is thrown.
Note that requests that time out are retried twice by default.
Advanced
Managing HTTP resources
By default the library closes underlying HTTP connections whenever the client is garbage collected. You can manually close the client using the .close()
method if desired, or with a context manager that closes when exiting.
Determining the installed version
If you’ve upgraded to the latest version but aren’t seeing any new features you were expecting then your python environment is likely still using an older version.
You can determine the version that is being used at runtime with:
Requirements
Python 3.8 or higher.
Was this page helpful?