Request Client
- class lbox.request_client.RequestClient(sdk_version, api_key=None, endpoint='https://api.labelbox.com/graphql', enable_experimental=False, app_url='https://app.labelbox.com', rest_endpoint='https://api.labelbox.com/api/v1')[source]
Bases:
object
A Labelbox request client.
Contains info necessary for connecting to a Labelbox server (URL, authentication key).
- execute(query=None, params=None, data=None, files=None, timeout=60.0, experimental=False, error_log_key='message', raise_return_resource_not_found=False, error_handlers: Dict[str, Callable[[Response], None]] | None = None)[source]
Sends a request to the server for the execution of the given query.
Checks the response for errors and wraps errors in appropriate exceptions.LabelboxError subtypes.
- Parameters:
query (str) – The query to execute.
params (dict) – Query parameters referenced within the query.
data (str) – json string containing the query to execute
files (dict) – file arguments for request
timeout (float) – Max allowed time for query execution, in seconds.
raise_return_resource_not_found – By default the client relies on the caller to raise the correct exception when a resource is not found. If this is set to True, the client will raise a ResourceNotFoundError exception automatically. This simplifies processing. We recommend to use it only of api returns a clear and well-formed error when a resource not found for a given query.
error_handlers (dict) – A dictionary mapping graphql error code to handler functions. Allows a caller to handle specific errors reporting in a custom way or produce more user-friendly readable messages.
- Example - custom error handler:
>>> def _raise_readable_errors(self, response): >>> errors = response.json().get('errors', []) >>> if errors: >>> message = errors[0].get( >>> 'message', json.dumps([{ >>> "errorMessage": "Unknown error" >>> }])) >>> errors = json.loads(message) >>> error_messages = [error['errorMessage'] for error in errors] >>> else: >>> error_messages = ["Uknown error"] >>> raise LabelboxError(". ".join(error_messages))
- Returns:
dict, parsed JSON response.
- Raises:
exceptions.AuthenticationError – If authentication failed.
exceptions.InvalidQueryError – If query is not syntactically or semantically valid (checked server-side).
exceptions.ApiLimitError – If the server API limit was exceeded. See “How to import data” in the online documentation to see API limits.
exceptions.TimeoutError – If response was not received in timeout seconds.
exceptions.NetworkError – If an unknown error occurred most likely due to connection issues.
exceptions.LabelboxError – If an unknown error of any kind occurred.
ValueError – If query and data are both None.