Rapidata client
RapidataClient #
RapidataClient(
client_id: str | None = None,
client_secret: str | None = None,
environment: str | None = None,
oauth_scope: str = "openid roles email api",
cert_path: str | None = None,
token: dict | None = None,
token_file: str | None = None,
leeway: int = 60,
)
The Rapidata client is the main entry point for interacting with the Rapidata API. It allows you to create orders and validation sets.
Credentials are resolved in the following order:
- A
tokenortoken_filepassed explicitly to this constructor (or theRAPIDATA_TOKEN_FILEenvironment variable), which bypasses the token exchange entirely. client_id/client_secretpassed explicitly to this constructor.- The
RAPIDATA_CLIENT_ID/RAPIDATA_CLIENT_SECRETenvironment variables (useful for headless / container deployments). - Credentials stored under
~/.config/rapidata/credentials.json. - Interactive browser login, which then saves credentials to the file above so you don't have to log in again.
The environment argument follows the same pattern: when omitted
it falls back to the RAPIDATA_ENVIRONMENT environment variable,
and finally to the default "rapidata.ai".
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
client_id
|
str
|
The client ID for authentication. Falls back to
the |
None
|
client_secret
|
str
|
The client secret for authentication. Falls
back to the |
None
|
environment
|
str
|
The API endpoint. Falls back to the
|
None
|
oauth_scope
|
str
|
The scopes to use for authentication. In general this does not need to be changed. |
'openid roles email api'
|
cert_path
|
str
|
An optional path to a certificate file useful for development. |
None
|
token
|
dict
|
If you already have a token that the client should use for authentication. Important, if set, this needs to be the complete token object containing the access token, token type and expiration time. |
None
|
token_file
|
str
|
Path to a JSON file containing the token object described above (with an absolute |
None
|
leeway
|
int
|
How many seconds before its actual expiry a token is treated as expired — i.e. how early it is refreshed (or re-read from |
60
|
Attributes:
| Name | Type | Description |
|---|---|---|
order |
RapidataOrderManager
|
The RapidataOrderManager instance.
Deprecated: use |
validation |
ValidationSetManager
|
The ValidationSetManager instance. |
flow |
RapidataFlowManager
|
The RapidataFlowManager instance. |
audience |
RapidataAudienceManager
|
The RapidataAudienceManager instance. |
job |
JobManager
|
The JobManager instance. |
mri |
RapidataBenchmarkManager
|
The RapidataBenchmarkManager instance. |
signals |
RapidataSignalManager
|
The RapidataSignalManager instance for managing recurring audience-job schedules (signals) and observing their runs. |
context |
ContextManager
|
The ContextManager instance for shortening datapoint contexts against a question. |
Source code in src/rapidata/rapidata_client/rapidata_client.py
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 105 106 107 108 109 110 111 112 113 114 115 116 117 118 119 120 121 122 123 124 125 126 127 128 129 130 131 132 133 134 135 136 137 138 139 140 141 142 143 144 145 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 | |
get_token #
Return the complete token object this client authenticates with, refreshing it first if it has expired.
The returned dict has the shape expected by the token and
token_file constructor arguments (access_token, token_type
and an absolute expires_at timestamp), so it can be written to a
shared token file that other workers consume — see the Distributed
Training guide.
Source code in src/rapidata/rapidata_client/rapidata_client.py
set_token #
Replace the token this client authenticates with, effective from the next request.
The counterpart to get_token: inject a fresh token — obtained from
another client and distributed through a transport of your choice —
into a running client, without reconstructing it. Expects the complete
token object (access_token, token_type and an absolute
expires_at timestamp) — see the Distributed Training guide.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
token
|
dict
|
The complete token object to authenticate with. |
required |
Source code in src/rapidata/rapidata_client/rapidata_client.py
maintain_token_file #
Continuously write this client's token to path so that other
workers can authenticate from it via token_file — see the
Distributed Training guide.
Writes the file once immediately (creating the parent directory if
needed), then keeps rewriting it from a background daemon thread every
interval seconds. Writes are atomic, and a new token is only
fetched from the auth server shortly before the current one expires
(controlled by the client's leeway).
The file contains a bearer token — write it only to storage that the consuming workers alone can read.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
path
|
str
|
Where to write the token file. |
required |
interval
|
float
|
Seconds between rewrites. Defaults to 60. |
60
|
Returns:
| Type | Description |
|---|---|
Thread
|
threading.Thread: The daemon thread keeping the file fresh. Call
|
Source code in src/rapidata/rapidata_client/rapidata_client.py
reset_credentials #
Reset the credentials saved in the configuration file for the current environment.
Source code in src/rapidata/rapidata_client/rapidata_client.py
clear_all_caches #
Clear all caches for the client.