Client
psengine.rf_client
¶
RFClient
¶
RFClient(
api_token: Union[str, None] = None,
http_proxy: str = None,
https_proxy: str = None,
verify: Union[str, bool] = None,
auth: tuple[str, str] = None,
cert: Union[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 HTTP API client.
PARAMETER | DESCRIPTION |
---|---|
api_token
|
An RF API token. Defaults to RF_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/rf_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: Union[dict, list[dict], None] = None,
*,
params: Union[dict, None] = None,
headers: Union[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
is_authorized
¶
Check if the request is authorized to a given Recorded Future API endpoint.
PARAMETER | DESCRIPTION |
---|---|
method
|
An HTTP method.
TYPE:
|
url
|
A URL to perform the check against.
TYPE:
|
RETURNS | DESCRIPTION |
---|---|
bool
|
True if authorized, False otherwise. |
Source code in psengine/rf_client.py
request
¶
request(
method: str,
url: str,
data: Union[dict, list[dict], None] = None,
*,
params: Optional[dict] = None,
headers: Optional[dict] = None,
**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:
|
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/rf_client.py
request_paged
¶
request_paged(
method: str,
url: str,
max_results: int = 1000,
data: Union[dict, list[dict], None] = None,
*,
params: Union[dict, None] = None,
headers: Union[dict, None] = None,
results_path: Union[str, list[str]] = 'data',
offset_key: str = 'offset',
**kwargs,
) -> list[dict]
Perform a paged HTTP request.
Please note that some RF APIs cannot paginate through more than 1000 results and will
return an error (HTTP 400) if max_results
exceeds that. APIs such as Identity support
pagination beyond 1000 results.
PARAMETER | DESCRIPTION |
---|---|
method
|
An HTTP method: GET or POST.
TYPE:
|
url
|
A URL to make the request to.
TYPE:
|
max_results
|
The maximum number of results to return.
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:
|
results_path
|
Path to extract paged results from.
TYPE:
|
offset_key
|
Key to use for paging. Defaults to 'offset'.
TYPE:
|
Example
RAISES | DESCRIPTION |
---|---|
KeyError
|
If no results are found in the API response. |
ValueError
|
|
RETURNS | DESCRIPTION |
---|---|
list[dict]
|
Resulting data. |
Source code in psengine/rf_client.py
229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 280 281 282 283 284 285 286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 320 321 322 323 324 325 326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343 344 345 346 347 348 349 350 351 352 353 354 355 |
|
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. |