API Response Types¶
-
class
civis.response.
Response
(json_data, snake_case=True, headers=None)¶ Custom Civis response object.
Notes
The main features of this class are that it maps camelCase to snake_case at the top level of the json object and attaches keys as attributes. Nested object keys are not changed.
Attributes
json_data (dict | None) This is json_data as it is originally returned to the user without the key names being changed. See Notes. None is used if the original response returned a 204 No Content response. headers (dict) This is the header for the API call without changing the key names. calls_remaining (int) Number of API calls remaining before rate limit is reached. rate_limit (int) Total number of calls per API rate limit period.
-
class
civis.response.
PaginatedResponse
(path, initial_params, endpoint)¶ A response object that supports iteration.
Parameters: path : str
Make GET requests to this path.
initial_params : dict
Query params that should be passed along with each request. Note that if initial_params contains the keys page_num or limit, they will be ignored. The given dict is not modified.
endpoint : civis.base.Endpoint
An endpoint used to make API requests.
Notes
This response is returned automatically by endpoints which support pagination when the iterator kwarg is specified.
Examples
>>> client = civis.APIClient() >>> queries = client.queries.list(iterator=True) >>> for query in queries: ... print(query['id'])
-
class
civis.polling.
PollableResult
(poller, poller_args, polling_interval=None, api_key=None, client=None, poll_on_creation=True)¶ Bases:
civis.base.CivisAsyncResultBase
A class for tracking pollable results.
This class will begin polling immediately upon creation, and poll for job completion once every polling_interval seconds until the job completes in Civis.
Parameters: poller : func
A function which returns an object that has a
state
attribute.poller_args : tuple
The arguments with which to call the poller function.
polling_interval : int or float
The number of seconds between API requests to check whether a result is ready.
api_key : DEPRECATED str, optional
This is not used by PollableResult, but is required to match the interface from CivisAsyncResultBase.
client :
civis.APIClient
, optionalIf not provided, an
civis.APIClient
object will be created from theCIVIS_API_KEY
.poll_on_creation : bool, optional
If
True
(the default), it will poll upon callingresult()
the first time. IfFalse
, it will wait the number of seconds specified in polling_interval from object creation before polling.Examples
>>> client = civis.APIClient() >>> database_id = client.get_database_id("my_database") >>> cred_id = client.default_credential >>> sql = "SELECT 1" >>> preview_rows = 10 >>> response = client.queries.post(database_id, sql, preview_rows, >>> credential=cred_id) >>> job_id = response.id >>> >>> poller = client.queries.get >>> poller_args = (job_id, ) # (job_id, run_id) if poller requires run_id >>> polling_interval = 10 >>> poll = PollableResult(poller, poller_args, polling_interval)