datadog_api_client

api_client

class ApiClient(configuration: Configuration)

Bases: object

Generic API client for OpenAPI client library builds.

OpenAPI generic API client. This client handles the client- server communication, and is invariant across implementations. Specifics of the methods and models for each application are generated from the OpenAPI templates.

Parameters:
  • configuration – Configuration object for this client

  • header_name – A header to pass when making calls to the API.

  • header_value – A header value to pass when making calls to the API.

call_api(resource_path: str, method: str, path_params: Dict[str, Any] | None = None, query_params: List[Tuple[str, Any]] | None = None, header_params: Dict[str, Any] | None = None, body: Any | None = None, post_params: List[Tuple[str, Any]] | None = None, files: Dict[str, List[FileIO]] | None = None, response_type: Tuple[Any] | None = None, return_http_data_only: bool | None = None, collection_formats: Dict[str, str] | None = None, preload_content: bool = True, request_timeout: int | float | Tuple[int | float, int | float] | None = None, host: str | None = None, check_type: bool | None = None)

Makes the HTTP request (synchronous) and returns deserialized data.

Parameters:
  • resource_path – Path to method endpoint.

  • method – Method to call.

  • path_params – Path parameters in the url.

  • query_params – Query parameters in the url.

  • header_params – Header parameters to be placed in the request header.

  • body – Request body.

  • dict (post_params) – Request post form parameters, for application/x-www-form-urlencoded, multipart/form-data.

  • response_type – For the response, a tuple containing: valid classes a list containing valid classes (for list schemas) a dict containing a tuple of valid classes as the value Example values: (str,) (Pet,) (float, none_type) ([int, none_type],) ({str: (bool, str, int, float, date, datetime, str, none_type)},)

  • files (dict) – key -> field name, value -> a list of open file objects for multipart/form-data.

  • return_http_data_only (bool, optional) – response data without head status code and headers

  • collection_formats (dict, optional) – dict of collection formats for path, query, header, and post parameters.

  • preload_content (bool, optional) – if False, the urllib3.HTTPResponse object will be returned without reading/decoding response data. Default is True.

  • request_timeout – timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of (connection, read) timeouts.

  • check_type (bool, optional) – boolean describing if the data back from the server should have its type checked.

Returns:

the HTTP response.

deserialize(response_data: str, response_type: Any, check_type: bool | None)

Deserializes response into an object.

Parameters:
  • response_data – Response data to be deserialized.

  • response_type – For the response, a tuple containing: valid classes a list containing valid classes (for list schemas) a dict containing a tuple of valid classes as the value Example values: (str,) (Pet,) (float, none_type) ([int, none_type],) ({str: (bool, str, int, float, date, datetime, str, none_type)},)

  • check_type (bool) – boolean, whether to check the types of the data received from the server

Returns:

deserialized object.

files_parameters(files: Dict[str, List[FileIO]] | None = None)

Builds form parameters.

Parameters:

files – None or a dict with key=param_name and value is a list of open file objects

Returns:

List of tuples of form parameters with file data

parameters_to_multipart(params)

Get parameters as list of tuples, formatting as json if value is dict.

Parameters:

params – Parameters as list of two-tuples.

Returns:

Parameters as list of tuple or urllib3.fields.RequestField

parameters_to_tuples(params, collection_formats) List[Tuple[str, Any]]

Get parameters as list of tuples, formatting collections.

Parameters:
  • params – Parameters as dict or list of two-tuples

  • collection_formats (dict) – Parameter collection formats

Returns:

Parameters as list of tuples, collections formatted

classmethod sanitize_for_serialization(obj)

Prepares data for transmission before it is sent with the rest client. If obj is None, return None. If obj is str, int, long, float, bool, return directly. If obj is datetime.datetime, datetime.date convert to string in iso8601 format. If obj is list, sanitize each element in the list. If obj is dict, return the dict. If obj is OpenAPI model, return the properties dict. If obj is io.IOBase, return the bytes.

Parameters:

obj – The data to serialize.

Returns:

The serialized form of data.

select_header_accept(accepts: List[str]) str

Returns Accept based on an array of accepts provided.

Parameters:

accepts – List of headers.

Returns:

Accept (e.g. application/json).

select_header_content_type(content_types: List[str]) str

Returns Content-Type based on an array of content_types provided.

Parameters:

content_types – List of content-types.

Returns:

Content-Type (e.g. application/json).

property user_agent: str

User agent for this API client

class AsyncApiClient(configuration: Configuration)

Bases: ApiClient

class ThreadedApiClient(configuration: Configuration, pool_threads: int = 1)

Bases: ApiClient

property pool: ThreadPool

Create thread pool on first request avoids instantiating unused threadpool for blocking clients.

user_agent() str

Generate default User-Agent header.

configuration

class Configuration(host=None, api_key=None, api_key_prefix=None, access_token=None, username=None, password=None, discard_unknown_keys=True, disabled_client_side_validations='', server_index=None, server_variables=None, server_operation_index=None, server_operation_variables=None, ssl_ca_cert=None, compress=True, return_http_data_only=True, preload_content=True, request_timeout=None, check_input_type=True, check_return_type=True, spec_property_naming=False, enable_retry=False, retry_backoff_factor=2, max_retries=3)

Bases: object

Parameters:
  • host – Base url.

  • api_key – Dict to store API key(s). Each entry in the dict specifies an API key. The dict key is the name of the security scheme in the OAS specification. The dict value is the API key secret.

  • api_key_prefix – Dict to store API prefix (e.g. Bearer). The dict key is the name of the security scheme in the OAS specification. The dict value is an API key prefix when generating the auth data.

  • username – Username for HTTP basic authentication.

  • password – Password for HTTP basic authentication.

  • discard_unknown_keys

    Boolean value indicating whether to discard unknown properties. A server may send a response that includes additional properties that are not known by the client in the following scenarios:

    1. The OpenAPI document is incomplete, i.e. it does not match the server implementation.

    2. The client was generated using an older version of the OpenAPI document and the server has been upgraded since then.

    If a schema in the OpenAPI document defines the additionalProperties attribute, then all undeclared properties received by the server are injected into the additional properties map. In that case, there are undeclared properties, and nothing to discard.

  • disabled_client_side_validations (str) – Comma-separated list of JSON schema validation keywords to disable JSON schema structural validation rules. The following keywords may be specified: multipleOf, maximum, exclusiveMaximum, minimum, exclusiveMinimum, maxLength, minLength, pattern, maxItems, minItems. By default, the validation is performed for data generated locally by the client and data received from the server, independent of any validation performed by the server side. If the input data does not satisfy the JSON schema validation rules specified in the OpenAPI document, an exception is raised. If disabled_client_side_validations is set, structural validation is disabled. This can be useful to troubleshoot data validation problem, such as when the OpenAPI document validation rules do not match the actual API data received by the server.

  • server_index – Index to servers configuration.

  • server_variables – Mapping with string values to replace variables in templated server configuration. The validation of enums is performed for variables with defined enum values before.

  • server_operation_index – Mapping from operation ID to an index to server configuration.

  • server_operation_variables – Mapping from operation ID to a mapping with string values to replace variables in templated server configuration. The validation of enums is performed for variables with defined enum values before.

  • ssl_ca_cert – The path to a file of concatenated CA certificates in PEM format.

  • compress (bool) – Boolean indicating whether encoded responses are accepted or not.

  • return_http_data_only (bool) – Response data without head status code and headers. Default is True.

  • preload_content (bool) – If False, the urllib3.HTTPResponse object will be returned without reading/decoding response data. Default is True.

  • request_timeout (float/tuple) – Timeout setting for this request. If one number is provided, it will be total request timeout. It can also be a pair (tuple) of (connection, read) timeouts. Default is None.

  • check_input_type (bool) – Specifies if type checking should be done on the data sent to the server. Default is True.

  • check_return_type (bool) – Specifies if type checking should be done on the data received from the server. Default is True.

  • spec_property_naming (bool) – Whether names in properties are expected to respect the spec or use snake case.

  • enable_retry (bool) – If set, the client will retry requests on backend errors (5xx status codes), and 429. On 429 if will use the returned headers to wait until the next requests, otherwise it will retry using the backoff factor.

  • retry_backoff_factor (float) – Factor used to space out retried requests on backend errors.

  • max_retries (int) – The maximum number of times a single request can be retried.

Constructor.

auth_settings()

Gets Auth Settings dict for api client.

Returns:

The Auth Settings information dict.

property debug

Debug status.

Returns:

The debug status, True or False.

Return type:

bool

get_api_key_with_prefix(identifier, alias=None)

Gets API key (with prefix if set).

Parameters:
  • identifier – The identifier of apiKey.

  • alias – The alternative identifier of apiKey.

Returns:

The token for api key authentication.

get_basic_auth_token()

Gets HTTP basic authentication header (string).

Returns:

The token for basic HTTP authentication.

get_host_from_settings(index, variables=None, servers=None)

Gets host URL based on the index and variables.

Parameters:
  • index – Array index of the host settings.

  • variables – Hash of variable and the corresponding value.

  • servers – An array of host settings or None.

Returns:

URL based on host settings.

get_host_settings()

Gets an array of host settings

Returns:

An array of host settings

property host

Return generated host.

property logger_file

The logger file.

If the logger_file is None, then add stream handler and remove file handler. Otherwise, add file handler and remove stream handler.

Returns:

The logger_file path.

Return type:

str

property logger_format

The logger format.

The logger_formatter will be updated when sets logger_format.

Returns:

The format string.

Return type:

str

property retry_backoff_factor

Retry backoff factor.

Returns:

The backoff factor, float

Return type:

float

exceptions

exception ApiAttributeError(msg, path_to_item=None)

Bases: OpenApiException, AttributeError

Raised when an attribute reference or assignment fails.

Parameters:
  • msg (str) – The exception message.

  • path_to_item (list) – The path to the exception in the received_data dict. None if unset.

exception ApiException(status=None, reason=None, http_resp=None)

Bases: OpenApiException

exception ApiKeyError(msg, path_to_item=None)

Bases: OpenApiException, KeyError

Parameters:
  • msg (str) – The exception message.

  • path_to_item (list) – The path to the exception in the received_data dict. None if unset.

exception ApiTypeError(msg, path_to_item=None, valid_classes=None, key_type=None)

Bases: OpenApiException, TypeError

Raises an exception for TypeErrors.

Parameters:
  • msg (str) – The exception message.

  • path_to_item (list) – A list of keys an indices to get to the current_item None if unset.

  • valid_classes (tuple) – The primitive classes that current item should be an instance of None if unset.

  • key_type (bool) – False if our value is a value in a dict True if it is a key in a dict False if our item is an item in a list None if unset.

exception ApiValueError(msg, path_to_item=None)

Bases: OpenApiException, ValueError

Parameters:
  • msg (str) – The exception message.

  • path_to_item (list) – The path to the exception in the received_data dict. None if unset.

exception ForbiddenException(status=None, reason=None, http_resp=None)

Bases: ApiException

exception NotFoundException(status=None, reason=None, http_resp=None)

Bases: ApiException

exception OpenApiException

Bases: Exception

The base exception class for all OpenAPIExceptions

exception ServiceException(status=None, reason=None, http_resp=None)

Bases: ApiException

exception UnauthorizedException(status=None, reason=None, http_resp=None)

Bases: ApiException

render_path(path_to_item)

Returns a string representation of a path

model_utils

class ModelComposed(*args, **kwargs)

Bases: OpenApiModel

The parent class of models whose type == object in their swagger/openapi and have oneOf.

When one sets a property we use var_name_to_model_instances to store the value in the correct class instances + run any type checking + validation code. When one gets a property we use var_name_to_model_instances to get the value from the correct class instances. This allows multiple composed schemas to contain the same property with additive constraints on the value.

Variables:
  • _composed_schemas – Stores the oneOf classes.

  • _composed_instances – Stores a list of instances of the composed schemas defined in _composed_schemas. When properties are accessed in the self instance, they are returned from the self._data_store or the data stores in the instances in self._composed_schemas.

  • _var_name_to_model_instances – Map between a variable name on self and the composed instances (self included) which contain that data.

Parameters:
  • _check_type (bool) – If True, values for parameters in openapi_types will be type checked and a TypeError will be raised if the wrong type is input. Defaults to True.

  • _path_to_item (tuple/list) – This is a list of keys or values to drill down to the model in received_data when deserializing a response.

  • _spec_property_naming (bool) – True if the variable names in the input data are serialized names, as specified in the OpenAPI document. False if the variable names in the input data are pythonic names, e.g. snake case (default).

  • _configuration (Configuration) – The instance to use when deserializing a file_type parameter. If passed, type conversion is attempted If omitted no type conversion is done.

get(name, default=None)

Returns the value of an attribute or some default value if the attribute was not set.

get_oneof_instance()

Returns the oneOf instance

to_dict()

Returns the model properties as a dict

to_str()

Returns the string representation of the model

class ModelNormal(*args, **kwargs)

Bases: OpenApiModel

The parent class of models whose type == object in their swagger/openapi.

Parameters:
  • _check_type (bool) – If True, values for parameters in openapi_types will be type checked and a TypeError will be raised if the wrong type is input. Defaults to True.

  • _path_to_item (tuple/list) – This is a list of keys or values to drill down to the model in received_data when deserializing a response.

  • _spec_property_naming (bool) – True if the variable names in the input data are serialized names, as specified in the OpenAPI document. False if the variable names in the input data are pythonic names, e.g. snake case (default).

  • _configuration (Configuration) – The instance to use when deserializing a file_type parameter. If passed, type conversion is attempted If omitted no type conversion is done.

get(name, default=None)

Returns the value of an attribute or some default value if the attribute was not set.

to_dict()

Returns the model properties as a dict

to_str()

Returns the string representation of the model

class ModelSimple(*args, **kwargs)

Bases: OpenApiModel

The parent class of models whose type != object in their swagger/openapi.

Variables:

allowed_values – Set of allowed values.

Parameters:
  • _check_type (bool) – If True, values for parameters in openapi_types will be type checked and a TypeError will be raised if the wrong type is input. Defaults to True.

  • _path_to_item (tuple/list) – This is a list of keys or values to drill down to the model in received_data when deserializing a response.

  • _spec_property_naming (bool) – True if the variable names in the input data are serialized names, as specified in the OpenAPI document. False if the variable names in the input data are pythonic names, e.g. snake case (default).

  • _configuration (Configuration) – The instance to use when deserializing a file_type parameter. If passed, type conversion is attempted If omitted no type conversion is done.

get(name, default=None)

Returns the value of an attribute or some default value if the attribute was not set.

to_str()

Returns the string representation of the model

class OpenApiModel(*args, **kwargs)

Bases: object

The base class for all OpenAPIModels.

Variables:
  • attribute_map – The key is attribute name and the value is json key in definition.

  • validations – The key is the name of the attribute. The value is a dict that stores validations for max_length, min_length, max_items, min_items, exclusive_maximum, inclusive_maximum, exclusive_minimum, inclusive_minimum, and regex.

  • additional_properties_type – A tuple of classes accepted as additional properties values.

Parameters:
  • _check_type (bool) – If True, values for parameters in openapi_types will be type checked and a TypeError will be raised if the wrong type is input. Defaults to True.

  • _path_to_item (tuple/list) – This is a list of keys or values to drill down to the model in received_data when deserializing a response.

  • _spec_property_naming (bool) – True if the variable names in the input data are serialized names, as specified in the OpenAPI document. False if the variable names in the input data are pythonic names, e.g. snake case (default).

  • _configuration (Configuration) – The instance to use when deserializing a file_type parameter. If passed, type conversion is attempted If omitted no type conversion is done.

class UnparsedObject(*args, **kwargs)

Bases: ModelNormal

A model for an oneOf we don’t know about.

Parameters:
  • _check_type (bool) – If True, values for parameters in openapi_types will be type checked and a TypeError will be raised if the wrong type is input. Defaults to True.

  • _path_to_item (tuple/list) – This is a list of keys or values to drill down to the model in received_data when deserializing a response.

  • _spec_property_naming (bool) – True if the variable names in the input data are serialized names, as specified in the OpenAPI document. False if the variable names in the input data are pythonic names, e.g. snake case (default).

  • _configuration (Configuration) – The instance to use when deserializing a file_type parameter. If passed, type conversion is attempted If omitted no type conversion is done.

class UnsetType(value)

Bases: Enum

An enumeration.

allows_single_value_input(cls)

This function returns True if the input composed schema model or any descendant model allows a value only input.

attempt_convert_item(input_value, valid_classes, path_to_item, configuration, spec_property_naming, key_type=False, must_convert=False, check_type=True)
Parameters:
  • input_value – The data to convert.

  • valid_classes – The classes that are valid.

  • path_to_item (list) – The path to the item to convert.

  • configuration (Configuration) – The instance to use to convert files.

  • spec_property_naming (bool) – True if the variable names in the input data are serialized names as specified in the OpenAPI document. False if the variables names in the input data are python variable names in PEP-8 snake case.

  • key_type (bool) – If True we need to convert a key type (not supported)

  • must_convert (bool) – If True we must convert.

  • check_type (bool) – If True we check the type or the returned data in ModelComposed/ModelNormal/ModelSimple instances.

change_keys_js_to_python(input_dict, model_class)

Converts from javascript_key keys in the input_dict to python_keys in the output dict using the mapping in model_class. If the input_dict contains a key which does not declared in the model_class, the key is added to the output dict as is. The assumption is the model_class may have undeclared properties (additionalProperties attribute in the OAS document).

check_allowed_values(allowed_values, input_variable, input_values)

Raises an exception if the input_values are not allowed.

Parameters:
  • input_variable (str) – The name of the input variable.

  • input_values (list/str/int/float/date/datetime/uuid) – The values that we are checking to see if they are in allowed_values.

check_validations(validations, input_variable, input_values, configuration=None)

Raises an exception if the input_values are invalid.

Parameters:
  • validations (dict) – The validation dictionary.

  • input_variable (str) – The name of the input variable.

  • input_values (list/str/int/float/date/datetime/uuid) – The values that we are checking.

  • configuration (Configuration) – The configuration instance.

composed_model_input_classes(cls)

This function returns a list of the possible models that can be accepted as inputs.

deserialize_file(response_data, temp_folder_path, content_disposition=None)

Deserializes body to file.

Saves response body into a file in a temporary folder, using the filename from the Content-Disposition header if provided.

Parameters:
  • response_data (str) – The file data to write.

  • temp_folder_path (str) – The directory in which the client creates temporary files.

  • content_disposition (str) – The value of the Content-Disposition header.

Returns:

The deserialized file which is open. The user is responsible for closing and reading the file.

Return type:

file_type

deserialize_model(model_data, model_class, path_to_item, check_type, configuration, spec_property_naming)

Deserializes model_data to model instance.

Parameters:
  • model_data (int/str/float/bool/none_type/list/dict) – Data to instantiate the model.

  • model_class (OpenApiModel) – The model class.

  • path_to_item (list) – Path to the model in the received data.

  • check_type (bool) – Whether to check the data tupe for the values in the model.

  • configuration (Configuration) – The instance to use to convert files.

  • spec_property_naming (bool) – True if the variable names in the input data are serialized names as specified in the OpenAPI document. False if the variables names in the input data are python variable names in PEP-8 snake case.

Returns:

The model instance.

deserialize_primitive(data, klass, path_to_item)

Deserializes string to primitive type.

Parameters:

klass (str/class) – The class to convert to.

Return type:

int, float, str, bool, date, datetime, UUID

get_attribute_from_path(obj, path, default=None)

Return an attribute at path from the passed object.

get_discarded_args(self, composed_instances, model_args)

Gathers the args that were discarded by configuration.discard_unknown_keys

get_oneof_instance(cls, model_kwargs, constant_kwargs, model_arg=None)

Find the oneOf schema that matches the input data (e.g. payload). If exactly one schema matches the input data, an instance of that schema is returned. If zero or more than one schema match the input data, an exception is raised. In OAS 3.x, the payload MUST, by validation, match exactly one of the schemas described by oneOf.

Parameters:
  • cls – The class we are handling.

  • model_kwargs (dict) – var_name to var_value. The input data, e.g. the payload that must match a oneOf schema in the OpenAPI document.

  • constant_kwargs (dict) – var_name to var_value args that every model requires, including configuration, server and path to item.

  • model_arg (int, float, bool, str, date, datetime, ModelSimple, UUID, None) – The value to assign to a primitive class or ModelSimple class. Notes: - this is only passed in when oneOf includes types which are not object - None is used to suppress handling of model_arg, nullable models are handled in __new__

get_required_type_classes(required_types_mixed, spec_property_naming)

Converts the tuple required_types into a tuple and a dict described below.

Parameters:
  • required_types_mixed (tuple/list) – Will contain either classes or instance of list or dict.

  • spec_property_naming (bool) – if True these values came from the server, and we use the data types in our endpoints. If False, we are client side and we need to include oneOf classes inside the data types in our endpoints.

Return (valid_classes, dict_valid_class_to_child_types_mixed):

valid_classes (tuple): The valid classes that the current item should be. dict_valid_class_to_child_types_mixed (dict):

valid_class (class): This is the key. child_types_mixed (list/dict/tuple): Describes the valid child types.

Return type:

tuple

get_simple_class(input_value)

Returns an input_value’s simple class that we will use for type checking.

Parameters:

input_value (class/class_instance) – The item for which we will return the simple class.

get_valid_classes_phrase(input_classes)

Returns a string phrase describing what types are allowed.

is_json_validation_enabled(schema_keyword, configuration=None)

Returns True if JSON schema validation is enabled for the specified validation keyword. This can be used to skip JSON schema structural validation as requested in the configuration.

Parameters:
  • schema_keyword (string) – The name of a JSON schema validation keyword.

  • configuration (Configuration) – The configuration instance.

is_type_nullable(input_type)

Returns True if None is an allowed value for the specified input_type.

A type is nullable if at least one of the following conditions is True:

  1. The OAS ‘nullable’ attribute has been specified,

  2. The type is the ‘null’ type,

  3. The type is a oneOf composed schema, and a child schema is the ‘null’ type.

Parameters:

input_type (type) – The class of the input_value that we are checking.

Return type:

bool

is_valid_type(input_class_simple, valid_classes)
Parameters:
  • input_class_simple (class:) – The class of the input_value that we are checking.

  • valid_classes (tuple) – The valid classes that the current item should be.

Return type:

bool

model_to_dict(model_instance, serialize=True)

Returns the model properties as a dict.

Parameters:
  • model_instance – The model instance that will be converted to a dict.

  • serialize (bool) – If True, the keys in the dict will be values from attribute_map.

order_response_types(required_types)

Returns the required types sorted in coercion order.

Parameters:

required_types (list/tuple) – Collection of classes or instance of list or dict with class information inside it.

Returns:

Coercion order sorted collection of classes or instance of list or dict with class information inside it.

Return type:

list

remove_uncoercible(required_types_classes, current_item, spec_property_naming, must_convert=True)

Only keeps the type conversions that are possible.

Parameters:
  • required_types_classes (tuple) – Classes that are required, these should be ordered by COERCION_INDEX_BY_TYPE.

  • spec_property_naming (bool) – True if the variable names in the input data are serialized names as specified in the OpenAPI document. False if the variables names in the input data are python variable names in PEP-8 snake case.

  • current_item – The current item (input data) to be converted.

  • must_convert (bool) – If True the item to convert is of the wrong type and we want a big list of coercibles if False, we want a limited list of coercibles.

Returns:

The remaining coercible required types, classes only.

Return type:

list

set_attribute_from_path(obj, path, value, params_map)

Set an attribute at path with the given value.

type_error_message(var_value=None, var_name=None, valid_classes=None, key_type=None)
Parameters:
  • var_value – The variable which has the type error.

  • var_name (str) – The name of the variable which has the type error.

  • valid_classes (tuple) – The accepted classes for current_item’s value.

  • key_type (bool) – False if our value is a value in a dict True if it is a key in a dict False if our item is an item in a list.

validate_and_convert_types(input_value, required_types_mixed, path_to_item, spec_property_naming, check_type, configuration=None)

Raises a TypeError is there is a problem, otherwise returns value.

Parameters:
  • input_value – The data to validate/convert.

  • required_types_mixed (list/dict/tuple) – A list of valid classes, or a list tuples of valid classes, or a dict where the value is a tuple of value classes.

  • path_to_item (list) – The path to the data being validated this stores a list of keys or indices to get to the data being validated.

  • spec_property_naming (bool) – True if the variable names in the input data are serialized names as specified in the OpenAPI document. False if the variables names in the input data are python variable names in PEP-8 snake case.

  • check_type (bool) – If True, type will be checked and conversion will be attempted.

  • configuration: – The configuration class to use when converting file_type items.

Returns:

The correctly typed value.

Raise:

ApiTypeError

validate_get_composed_info(constant_args, model_args, self)

For composed schemas, generate schema instances for all schemas in the oneOf definition. If additional properties are allowed, also assign those properties on all matched schemas that contain additionalProperties. Openapi schemas are python classes.

Exceptions are raised if: - 0 or > 1 oneOf schema matches the model_args input data

Parameters:
  • constant_args (dict) – These are the args that every model requires.

  • model_args (dict) – These are the required and optional spec args that were passed in to make this model.

  • self (class) – The class that we are instantiating. This class contains self._composed_schemas.

Returns:

composed_instances (list): the composed instances which are not

self

var_name_to_model_instances (dict): a dict going from var_name

to the model_instance which holds that var_name the model_instance may be self or an instance of one of the classes in self.composed_instances()

additional_properties_model_instances (list): a list of the

model instances which have the property additional_properties_type. This list can include self

Return type:

list

rest

class ClientRetry(total: bool | int | None = 10, connect: int | None = None, read: int | None = None, redirect: bool | int | None = None, status: int | None = None, other: int | None = None, allowed_methods: Collection[str] | None = frozenset({'DELETE', 'GET', 'HEAD', 'OPTIONS', 'PUT', 'TRACE'}), status_forcelist: Collection[int] | None = None, backoff_factor: float = 0, backoff_max: float = 120, raise_on_redirect: bool = True, raise_on_status: bool = True, history: tuple[RequestHistory, ...] | None = None, respect_retry_after_header: bool = True, remove_headers_on_redirect: Collection[str] = frozenset({'Authorization', 'Cookie'}), backoff_jitter: float = 0.0)

Bases: Retry

DEFAULT_ALLOWED_METHODS = frozenset({'DELETE', 'GET', 'PATCH', 'POST', 'PUT'})

Default methods to be used for allowed_methods

RETRY_AFTER_STATUS_CODES = frozenset({429, 500, 501, 502, 503, 504, 505, 506, 507, 509, 510, 511})

Default status codes to be used for status_forcelist

get_retry_after(response)

This method overrides the default “Retry-after” header and uses dd’s X-Ratelimit-Reset header and gets the value of X-Ratelimit-Reset in seconds.

is_retry(method, status_code, has_retry_after=False)

Is this method/status code retryable? (Based on allowlists and control variables such as the number of total retries to allow, whether to respect the Retry-After header, whether this header is present, and whether the returned status code is on the list of status codes to be retried upon on the presence of the aforementioned header)

class ApiClient(configuration: Configuration)

Bases: object

Generic API client for OpenAPI client library builds.

OpenAPI generic API client. This client handles the client- server communication, and is invariant across implementations. Specifics of the methods and models for each application are generated from the OpenAPI templates.

Parameters:
  • configuration – Configuration object for this client

  • header_name – A header to pass when making calls to the API.

  • header_value – A header value to pass when making calls to the API.

call_api(resource_path: str, method: str, path_params: Dict[str, Any] | None = None, query_params: List[Tuple[str, Any]] | None = None, header_params: Dict[str, Any] | None = None, body: Any | None = None, post_params: List[Tuple[str, Any]] | None = None, files: Dict[str, List[FileIO]] | None = None, response_type: Tuple[Any] | None = None, return_http_data_only: bool | None = None, collection_formats: Dict[str, str] | None = None, preload_content: bool = True, request_timeout: int | float | Tuple[int | float, int | float] | None = None, host: str | None = None, check_type: bool | None = None)

Makes the HTTP request (synchronous) and returns deserialized data.

Parameters:
  • resource_path – Path to method endpoint.

  • method – Method to call.

  • path_params – Path parameters in the url.

  • query_params – Query parameters in the url.

  • header_params – Header parameters to be placed in the request header.

  • body – Request body.

  • dict (post_params) – Request post form parameters, for application/x-www-form-urlencoded, multipart/form-data.

  • response_type – For the response, a tuple containing: valid classes a list containing valid classes (for list schemas) a dict containing a tuple of valid classes as the value Example values: (str,) (Pet,) (float, none_type) ([int, none_type],) ({str: (bool, str, int, float, date, datetime, str, none_type)},)

  • files (dict) – key -> field name, value -> a list of open file objects for multipart/form-data.

  • return_http_data_only (bool, optional) – response data without head status code and headers

  • collection_formats (dict, optional) – dict of collection formats for path, query, header, and post parameters.

  • preload_content (bool, optional) – if False, the urllib3.HTTPResponse object will be returned without reading/decoding response data. Default is True.

  • request_timeout – timeout setting for this request. If one number provided, it will be total request timeout. It can also be a pair (tuple) of (connection, read) timeouts.

  • check_type (bool, optional) – boolean describing if the data back from the server should have its type checked.

Returns:

the HTTP response.

deserialize(response_data: str, response_type: Any, check_type: bool | None)

Deserializes response into an object.

Parameters:
  • response_data – Response data to be deserialized.

  • response_type – For the response, a tuple containing: valid classes a list containing valid classes (for list schemas) a dict containing a tuple of valid classes as the value Example values: (str,) (Pet,) (float, none_type) ([int, none_type],) ({str: (bool, str, int, float, date, datetime, str, none_type)},)

  • check_type (bool) – boolean, whether to check the types of the data received from the server

Returns:

deserialized object.

files_parameters(files: Dict[str, List[FileIO]] | None = None)

Builds form parameters.

Parameters:

files – None or a dict with key=param_name and value is a list of open file objects

Returns:

List of tuples of form parameters with file data

parameters_to_multipart(params)

Get parameters as list of tuples, formatting as json if value is dict.

Parameters:

params – Parameters as list of two-tuples.

Returns:

Parameters as list of tuple or urllib3.fields.RequestField

parameters_to_tuples(params, collection_formats) List[Tuple[str, Any]]

Get parameters as list of tuples, formatting collections.

Parameters:
  • params – Parameters as dict or list of two-tuples

  • collection_formats (dict) – Parameter collection formats

Returns:

Parameters as list of tuples, collections formatted

classmethod sanitize_for_serialization(obj)

Prepares data for transmission before it is sent with the rest client. If obj is None, return None. If obj is str, int, long, float, bool, return directly. If obj is datetime.datetime, datetime.date convert to string in iso8601 format. If obj is list, sanitize each element in the list. If obj is dict, return the dict. If obj is OpenAPI model, return the properties dict. If obj is io.IOBase, return the bytes.

Parameters:

obj – The data to serialize.

Returns:

The serialized form of data.

select_header_accept(accepts: List[str]) str

Returns Accept based on an array of accepts provided.

Parameters:

accepts – List of headers.

Returns:

Accept (e.g. application/json).

select_header_content_type(content_types: List[str]) str

Returns Content-Type based on an array of content_types provided.

Parameters:

content_types – List of content-types.

Returns:

Content-Type (e.g. application/json).

property user_agent: str

User agent for this API client

class AsyncApiClient(configuration: Configuration)

Bases: ApiClient

class Configuration(host=None, api_key=None, api_key_prefix=None, access_token=None, username=None, password=None, discard_unknown_keys=True, disabled_client_side_validations='', server_index=None, server_variables=None, server_operation_index=None, server_operation_variables=None, ssl_ca_cert=None, compress=True, return_http_data_only=True, preload_content=True, request_timeout=None, check_input_type=True, check_return_type=True, spec_property_naming=False, enable_retry=False, retry_backoff_factor=2, max_retries=3)

Bases: object

Parameters:
  • host – Base url.

  • api_key – Dict to store API key(s). Each entry in the dict specifies an API key. The dict key is the name of the security scheme in the OAS specification. The dict value is the API key secret.

  • api_key_prefix – Dict to store API prefix (e.g. Bearer). The dict key is the name of the security scheme in the OAS specification. The dict value is an API key prefix when generating the auth data.

  • username – Username for HTTP basic authentication.

  • password – Password for HTTP basic authentication.

  • discard_unknown_keys

    Boolean value indicating whether to discard unknown properties. A server may send a response that includes additional properties that are not known by the client in the following scenarios:

    1. The OpenAPI document is incomplete, i.e. it does not match the server implementation.

    2. The client was generated using an older version of the OpenAPI document and the server has been upgraded since then.

    If a schema in the OpenAPI document defines the additionalProperties attribute, then all undeclared properties received by the server are injected into the additional properties map. In that case, there are undeclared properties, and nothing to discard.

  • disabled_client_side_validations (str) – Comma-separated list of JSON schema validation keywords to disable JSON schema structural validation rules. The following keywords may be specified: multipleOf, maximum, exclusiveMaximum, minimum, exclusiveMinimum, maxLength, minLength, pattern, maxItems, minItems. By default, the validation is performed for data generated locally by the client and data received from the server, independent of any validation performed by the server side. If the input data does not satisfy the JSON schema validation rules specified in the OpenAPI document, an exception is raised. If disabled_client_side_validations is set, structural validation is disabled. This can be useful to troubleshoot data validation problem, such as when the OpenAPI document validation rules do not match the actual API data received by the server.

  • server_index – Index to servers configuration.

  • server_variables – Mapping with string values to replace variables in templated server configuration. The validation of enums is performed for variables with defined enum values before.

  • server_operation_index – Mapping from operation ID to an index to server configuration.

  • server_operation_variables – Mapping from operation ID to a mapping with string values to replace variables in templated server configuration. The validation of enums is performed for variables with defined enum values before.

  • ssl_ca_cert – The path to a file of concatenated CA certificates in PEM format.

  • compress (bool) – Boolean indicating whether encoded responses are accepted or not.

  • return_http_data_only (bool) – Response data without head status code and headers. Default is True.

  • preload_content (bool) – If False, the urllib3.HTTPResponse object will be returned without reading/decoding response data. Default is True.

  • request_timeout (float/tuple) – Timeout setting for this request. If one number is provided, it will be total request timeout. It can also be a pair (tuple) of (connection, read) timeouts. Default is None.

  • check_input_type (bool) – Specifies if type checking should be done on the data sent to the server. Default is True.

  • check_return_type (bool) – Specifies if type checking should be done on the data received from the server. Default is True.

  • spec_property_naming (bool) – Whether names in properties are expected to respect the spec or use snake case.

  • enable_retry (bool) – If set, the client will retry requests on backend errors (5xx status codes), and 429. On 429 if will use the returned headers to wait until the next requests, otherwise it will retry using the backoff factor.

  • retry_backoff_factor (float) – Factor used to space out retried requests on backend errors.

  • max_retries (int) – The maximum number of times a single request can be retried.

Constructor.

auth_settings()

Gets Auth Settings dict for api client.

Returns:

The Auth Settings information dict.

property debug

Debug status.

Returns:

The debug status, True or False.

Return type:

bool

get_api_key_with_prefix(identifier, alias=None)

Gets API key (with prefix if set).

Parameters:
  • identifier – The identifier of apiKey.

  • alias – The alternative identifier of apiKey.

Returns:

The token for api key authentication.

get_basic_auth_token()

Gets HTTP basic authentication header (string).

Returns:

The token for basic HTTP authentication.

get_host_from_settings(index, variables=None, servers=None)

Gets host URL based on the index and variables.

Parameters:
  • index – Array index of the host settings.

  • variables – Hash of variable and the corresponding value.

  • servers – An array of host settings or None.

Returns:

URL based on host settings.

get_host_settings()

Gets an array of host settings

Returns:

An array of host settings

property host

Return generated host.

property logger_file

The logger file.

If the logger_file is None, then add stream handler and remove file handler. Otherwise, add file handler and remove stream handler.

Returns:

The logger_file path.

Return type:

str

property logger_format

The logger format.

The logger_formatter will be updated when sets logger_format.

Returns:

The format string.

Return type:

str

property retry_backoff_factor

Retry backoff factor.

Returns:

The backoff factor, float

Return type:

float

class ThreadedApiClient(configuration: Configuration, pool_threads: int = 1)

Bases: ApiClient

property pool: ThreadPool

Create thread pool on first request avoids instantiating unused threadpool for blocking clients.