Client
psengine.sandbox.client
¶
SandboxClient
¶
SandboxClient(
api_token: str | None = None,
http_proxy: str = None,
https_proxy: str = None,
verify: str | bool = None,
auth: tuple[str, str] = None,
cert: str | tuple[str, str] | None = None,
timeout: int = None,
retries: int = None,
backoff_factor: int = None,
status_forcelist: list = None,
pool_max_size: int = None,
)
Bases: BaseHTTPClient
Recorded Future Sandbox API client.
| PARAMETER | DESCRIPTION |
|---|---|
api_token
|
The Sandbox API token. Defaults to RF_SANDBOX_TOKEN environment variable.
TYPE:
|
http_proxy
|
An HTTP proxy URL.
TYPE:
|
https_proxy
|
An HTTPS proxy URL.
TYPE:
|
verify
|
An SSL verification flag or path to CA bundle.
TYPE:
|
auth
|
Basic Auth credentials.
TYPE:
|
cert
|
Client certificates.
TYPE:
|
timeout
|
A request timeout. Defaults to 120.
TYPE:
|
retries
|
A number of retries. Defaults to 5.
TYPE:
|
backoff_factor
|
A backoff factor. Defaults to 1.
TYPE:
|
status_forcelist
|
A list of status codes to force a retry. Defaults to [502, 503, 504].
TYPE:
|
pool_max_size
|
The maximum number of connections in the pool. Defaults to 120.
TYPE:
|
Source code in psengine/sandbox/client.py
backoff_factor
instance-attribute
¶
http_proxy
instance-attribute
¶
https_proxy
instance-attribute
¶
pool_max_size
instance-attribute
¶
status_forcelist
instance-attribute
¶
status_forcelist = (
status_forcelist
if status_forcelist is not None
else client_status_forcelist
)
call
¶
call(
method: str,
url: str,
data: dict | list[dict] | bytes | None = None,
*,
params: dict | None = None,
headers: dict | None = None,
**kwargs,
) -> Response
Invoke an HTTP request using the requests library.
| PARAMETER | DESCRIPTION |
|---|---|
method
|
An HTTP method.
TYPE:
|
url
|
A URL to make the request to.
TYPE:
|
data
|
A request body.
TYPE:
|
params
|
HTTP query parameters.
TYPE:
|
headers
|
If specified, overrides default headers and does not set the token.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValueError
|
If method is not one of GET, PUT, POST, DELETE, HEAD, OPTIONS, PATCH. |
HTTPError
|
If the response status is not 2xx. |
JSONDecodeError
|
If the response contains malformed JSON. |
ConnectTimeout
|
If the connection to the server times out. |
ConnectionError
|
If the request fails before completing. |
ReadTimeout
|
If the server did not send any data in time. |
| RETURNS | DESCRIPTION |
|---|---|
Response
|
A requests.Response object. |
Source code in psengine/base_http_client.py
can_connect
¶
Check if the client can reach the specified API URL.
| PARAMETER | DESCRIPTION |
|---|---|
method
|
An HTTP method.
TYPE:
|
url
|
A URL to test.recordedfuture.com.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if connection returns status 200, else False. |
Source code in psengine/base_http_client.py
request
¶
request(
method: str,
url: str,
data: dict | list[dict] | bytes | None = None,
*,
params: dict | None = None,
headers: dict | None = None,
content_type_header: str | None = 'application/json',
**kwargs,
) -> Response
Perform an HTTP request.
| PARAMETER | DESCRIPTION |
|---|---|
method
|
An HTTP method, one of GET, PUT, POST, DELETE, HEAD, OPTIONS, PATCH.
TYPE:
|
url
|
A URL to make the request to.
TYPE:
|
data
|
A request body.
TYPE:
|
params
|
HTTP query parameters.
TYPE:
|
headers
|
If specified, it overrides default headers and does not set the token.
TYPE:
|
content_type_header
|
Content-Type header value.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValidationError
|
If method is not one of GET, PUT, POST, DELETE, HEAD, OPTIONS, PATCH. |
| RETURNS | DESCRIPTION |
|---|---|
Response
|
A requests.Response object. |
Source code in psengine/sandbox/client.py
request_paged
¶
request_paged(
method: str,
url: str,
data: dict | list[dict] | bytes | None = None,
*,
params: dict | None = None,
headers: dict | None = None,
content_type_header: str | None = 'application/json',
max_results: int = DEFAULT_PAGE_LIMIT,
results_per_page: int | None = Field(
ge=1, le=MAXIMUM_SAMPLES, default=SAMPLES_PER_PAGE
),
**kwargs,
) -> list
Perform a paged HTTP request, following next offsets until max_results is reached.
| PARAMETER | DESCRIPTION |
|---|---|
method
|
An HTTP method, one of GET, PUT, POST, DELETE, HEAD, OPTIONS, PATCH.
TYPE:
|
url
|
A URL to make the request to.
TYPE:
|
data
|
A request body.
TYPE:
|
params
|
HTTP query parameters.
TYPE:
|
headers
|
If specified, it overrides default headers and does not set the token.
TYPE:
|
content_type_header
|
Content-Type header value.
TYPE:
|
results_per_page
|
The number of samples per page for pagination.
TYPE:
|
| RAISES | DESCRIPTION |
|---|---|
ValidationError
|
If method is not one of GET, PUT, POST, DELETE, HEAD, OPTIONS, PATCH. |
| RETURNS | DESCRIPTION |
|---|---|
list
|
Result rows accumulated across all fetched pages. |
Source code in psengine/sandbox/client.py
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 205 206 207 208 | |
set_urllib_log_level
¶
Set log level for urllib3 library.
| PARAMETER | DESCRIPTION |
|---|---|
level
|
A log level to be set: CRITICAL, ERROR, WARNING, INFO, DEBUG, NOTSET.
TYPE:
|
Source code in psengine/base_http_client.py
is_api_token_format_valid
¶
Check if the token format is valid.
The function performs a simple regex check but does not validate the token against the API.
| PARAMETER | DESCRIPTION |
|---|---|
token
|
A Recorded Future API token.
TYPE:
|
| RETURNS | DESCRIPTION |
|---|---|
bool
|
True if the token format is valid, False otherwise. |