pinecone.core.client.configuration
Pinecone API
No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) # noqa: E501
The version of the OpenAPI document: version not set Contact: support@pinecone.io Generated by: https://openapi-generator.tech
1""" 2 Pinecone API 3 4 No description provided (generated by Openapi Generator https://github.com/openapitools/openapi-generator) # noqa: E501 5 6 The version of the OpenAPI document: version not set 7 Contact: support@pinecone.io 8 Generated by: https://openapi-generator.tech 9""" 10 11 12import copy 13import logging 14import multiprocessing 15import sys 16import urllib3 17 18from http import client as http_client 19from pinecone.core.client.exceptions import ApiValueError 20 21 22JSON_SCHEMA_VALIDATION_KEYWORDS = { 23 "multipleOf", 24 "maximum", 25 "exclusiveMaximum", 26 "minimum", 27 "exclusiveMinimum", 28 "maxLength", 29 "minLength", 30 "pattern", 31 "maxItems", 32 "minItems", 33} 34 35 36class Configuration(object): 37 """NOTE: This class is auto generated by OpenAPI Generator 38 39 Ref: https://openapi-generator.tech 40 Do not edit the class manually. 41 42 :param host: Base url 43 :param api_key: Dict to store API key(s). 44 Each entry in the dict specifies an API key. 45 The dict key is the name of the security scheme in the OAS specification. 46 The dict value is the API key secret. 47 :param api_key_prefix: Dict to store API prefix (e.g. Bearer) 48 The dict key is the name of the security scheme in the OAS specification. 49 The dict value is an API key prefix when generating the auth data. 50 :param username: Username for HTTP basic authentication 51 :param password: Password for HTTP basic authentication 52 :param discard_unknown_keys: Boolean value indicating whether to discard 53 unknown properties. A server may send a response that includes additional 54 properties that are not known by the client in the following scenarios: 55 1. The OpenAPI document is incomplete, i.e. it does not match the server 56 implementation. 57 2. The client was generated using an older version of the OpenAPI document 58 and the server has been upgraded since then. 59 If a schema in the OpenAPI document defines the additionalProperties attribute, 60 then all undeclared properties received by the server are injected into the 61 additional properties map. In that case, there are undeclared properties, and 62 nothing to discard. 63 :param disabled_client_side_validations (string): Comma-separated list of 64 JSON schema validation keywords to disable JSON schema structural validation 65 rules. The following keywords may be specified: multipleOf, maximum, 66 exclusiveMaximum, minimum, exclusiveMinimum, maxLength, minLength, pattern, 67 maxItems, minItems. 68 By default, the validation is performed for data generated locally by the client 69 and data received from the server, independent of any validation performed by 70 the server side. If the input data does not satisfy the JSON schema validation 71 rules specified in the OpenAPI document, an exception is raised. 72 If disabled_client_side_validations is set, structural validation is 73 disabled. This can be useful to troubleshoot data validation problem, such as 74 when the OpenAPI document validation rules do not match the actual API data 75 received by the server. 76 :param server_index: Index to servers configuration. 77 :param server_variables: Mapping with string values to replace variables in 78 templated server configuration. The validation of enums is performed for 79 variables with defined enum values before. 80 :param server_operation_index: Mapping from operation ID to an index to server 81 configuration. 82 :param server_operation_variables: Mapping from operation ID to a mapping with 83 string values to replace variables in templated server configuration. 84 The validation of enums is performed for variables with defined enum values before. 85 :param ssl_ca_cert: str - the path to a file of concatenated CA certificates 86 in PEM format 87 88 :Example: 89 90 API Key Authentication Example. 91 Given the following security scheme in the OpenAPI specification: 92 components: 93 securitySchemes: 94 cookieAuth: # name for the security scheme 95 type: apiKey 96 in: cookie 97 name: JSESSIONID # cookie name 98 99 You can programmatically set the cookie: 100 101 conf = pinecone.core.client.Configuration( 102 api_key={'cookieAuth': 'abc123'} 103 api_key_prefix={'cookieAuth': 'JSESSIONID'} 104 ) 105 106 The following cookie will be added to the HTTP request: 107 Cookie: JSESSIONID abc123 108 """ 109 110 _default = None 111 112 def __init__( 113 self, 114 host=None, 115 api_key=None, 116 api_key_prefix=None, 117 access_token=None, 118 username=None, 119 password=None, 120 discard_unknown_keys=False, 121 disabled_client_side_validations="", 122 server_index=None, 123 server_variables=None, 124 server_operation_index=None, 125 server_operation_variables=None, 126 ssl_ca_cert=None, 127 ): 128 """Constructor""" 129 self._base_path = "https://unknown-unknown.svc.unknown.pinecone.io" if host is None else host 130 """Default Base url 131 """ 132 self.server_index = 0 if server_index is None and host is None else server_index 133 self.server_operation_index = server_operation_index or {} 134 """Default server index 135 """ 136 self.server_variables = server_variables or {} 137 self.server_operation_variables = server_operation_variables or {} 138 """Default server variables 139 """ 140 self.temp_folder_path = None 141 """Temp file folder for downloading files 142 """ 143 # Authentication Settings 144 self.access_token = access_token 145 self.api_key = {} 146 if api_key: 147 self.api_key = api_key 148 """dict to store API key(s) 149 """ 150 self.api_key_prefix = {} 151 if api_key_prefix: 152 self.api_key_prefix = api_key_prefix 153 """dict to store API prefix (e.g. Bearer) 154 """ 155 self.refresh_api_key_hook = None 156 """function hook to refresh API key if expired 157 """ 158 self.username = username 159 """Username for HTTP basic authentication 160 """ 161 self.password = password 162 """Password for HTTP basic authentication 163 """ 164 self.discard_unknown_keys = discard_unknown_keys 165 self.disabled_client_side_validations = disabled_client_side_validations 166 self.logger = {} 167 """Logging Settings 168 """ 169 self.logger["package_logger"] = logging.getLogger("pinecone.core.client") 170 self.logger["urllib3_logger"] = logging.getLogger("urllib3") 171 self.logger_format = "%(asctime)s %(levelname)s %(message)s" 172 """Log format 173 """ 174 self.logger_stream_handler = None 175 """Log stream handler 176 """ 177 self.logger_file_handler = None 178 """Log file handler 179 """ 180 self.logger_file = None 181 """Debug file location 182 """ 183 self.debug = False 184 """Debug switch 185 """ 186 187 self.verify_ssl = True 188 """SSL/TLS verification 189 Set this to false to skip verifying SSL certificate when calling API 190 from https server. 191 """ 192 self.ssl_ca_cert = ssl_ca_cert 193 """Set this to customize the certificate file to verify the peer. 194 """ 195 self.cert_file = None 196 """client certificate file 197 """ 198 self.key_file = None 199 """client key file 200 """ 201 self.assert_hostname = None 202 """Set this to True/False to enable/disable SSL hostname verification. 203 """ 204 205 self.connection_pool_maxsize = multiprocessing.cpu_count() * 5 206 """urllib3 connection pool's maximum number of connections saved 207 per pool. urllib3 uses 1 connection as default value, but this is 208 not the best value when you are making a lot of possibly parallel 209 requests to the same host, which is often the case here. 210 cpu_count * 5 is used as default value to increase performance. 211 """ 212 213 self.proxy = None 214 """Proxy URL 215 """ 216 self.proxy_headers = None 217 """Proxy headers 218 """ 219 self.safe_chars_for_path_param = "" 220 """Safe chars for path_param 221 """ 222 self.retries = None 223 """Adding retries to override urllib3 default value 3 224 """ 225 # Enable client side validation 226 self.client_side_validation = True 227 228 # Options to pass down to the underlying urllib3 socket 229 self.socket_options = None 230 231 def __deepcopy__(self, memo): 232 cls = self.__class__ 233 result = cls.__new__(cls) 234 memo[id(self)] = result 235 for k, v in self.__dict__.items(): 236 if k not in ("logger", "logger_file_handler"): 237 setattr(result, k, copy.deepcopy(v, memo)) 238 # shallow copy of loggers 239 result.logger = copy.copy(self.logger) 240 # use setters to configure loggers 241 result.logger_file = self.logger_file 242 result.debug = self.debug 243 return result 244 245 def __setattr__(self, name, value): 246 object.__setattr__(self, name, value) 247 if name == "disabled_client_side_validations": 248 s = set(filter(None, value.split(","))) 249 for v in s: 250 if v not in JSON_SCHEMA_VALIDATION_KEYWORDS: 251 raise ApiValueError("Invalid keyword: '{0}''".format(v)) 252 self._disabled_client_side_validations = s 253 254 @classmethod 255 def set_default(cls, default): 256 """Set default instance of configuration. 257 258 It stores default configuration, which can be 259 returned by get_default_copy method. 260 261 :param default: object of Configuration 262 """ 263 cls._default = copy.deepcopy(default) 264 265 @classmethod 266 def get_default_copy(cls): 267 """Return new instance of configuration. 268 269 This method returns newly created, based on default constructor, 270 object of Configuration class or returns a copy of default 271 configuration passed by the set_default method. 272 273 :return: The configuration object. 274 """ 275 if cls._default is not None: 276 return copy.deepcopy(cls._default) 277 return Configuration() 278 279 @property 280 def logger_file(self): 281 """The logger file. 282 283 If the logger_file is None, then add stream handler and remove file 284 handler. Otherwise, add file handler and remove stream handler. 285 286 :param value: The logger_file path. 287 :type: str 288 """ 289 return self.__logger_file 290 291 @logger_file.setter 292 def logger_file(self, value): 293 """The logger file. 294 295 If the logger_file is None, then add stream handler and remove file 296 handler. Otherwise, add file handler and remove stream handler. 297 298 :param value: The logger_file path. 299 :type: str 300 """ 301 self.__logger_file = value 302 if self.__logger_file: 303 # If set logging file, 304 # then add file handler and remove stream handler. 305 self.logger_file_handler = logging.FileHandler(self.__logger_file) 306 self.logger_file_handler.setFormatter(self.logger_formatter) 307 for _, logger in self.logger.items(): 308 logger.addHandler(self.logger_file_handler) 309 310 @property 311 def debug(self): 312 """Debug status 313 314 :param value: The debug status, True or False. 315 :type: bool 316 """ 317 return self.__debug 318 319 @debug.setter 320 def debug(self, value): 321 """Debug status 322 323 :param value: The debug status, True or False. 324 :type: bool 325 """ 326 self.__debug = value 327 if self.__debug: 328 # if debug status is True, turn on debug logging 329 for _, logger in self.logger.items(): 330 logger.setLevel(logging.DEBUG) 331 # turn on http_client debug 332 http_client.HTTPConnection.debuglevel = 1 333 else: 334 # if debug status is False, turn off debug logging, 335 # setting log level to default `logging.WARNING` 336 for _, logger in self.logger.items(): 337 logger.setLevel(logging.WARNING) 338 # turn off http_client debug 339 http_client.HTTPConnection.debuglevel = 0 340 341 @property 342 def logger_format(self): 343 """The logger format. 344 345 The logger_formatter will be updated when sets logger_format. 346 347 :param value: The format string. 348 :type: str 349 """ 350 return self.__logger_format 351 352 @logger_format.setter 353 def logger_format(self, value): 354 """The logger format. 355 356 The logger_formatter will be updated when sets logger_format. 357 358 :param value: The format string. 359 :type: str 360 """ 361 self.__logger_format = value 362 self.logger_formatter = logging.Formatter(self.__logger_format) 363 364 def get_api_key_with_prefix(self, identifier, alias=None): 365 """Gets API key (with prefix if set). 366 367 :param identifier: The identifier of apiKey. 368 :param alias: The alternative identifier of apiKey. 369 :return: The token for api key authentication. 370 """ 371 if self.refresh_api_key_hook is not None: 372 self.refresh_api_key_hook(self) 373 key = self.api_key.get(identifier, self.api_key.get(alias) if alias is not None else None) 374 if key: 375 prefix = self.api_key_prefix.get(identifier) 376 if prefix: 377 return "%s %s" % (prefix, key) 378 else: 379 return key 380 381 def get_basic_auth_token(self): 382 """Gets HTTP basic authentication header (string). 383 384 :return: The token for basic HTTP authentication. 385 """ 386 username = "" 387 if self.username is not None: 388 username = self.username 389 password = "" 390 if self.password is not None: 391 password = self.password 392 return urllib3.util.make_headers(basic_auth=username + ":" + password).get("authorization") 393 394 def auth_settings(self): 395 """Gets Auth Settings dict for api client. 396 397 :return: The Auth Settings information dict. 398 """ 399 auth = {} 400 if "ApiKeyAuth" in self.api_key: 401 auth["ApiKeyAuth"] = { 402 "type": "api_key", 403 "in": "header", 404 "key": "Api-Key", 405 "value": self.get_api_key_with_prefix( 406 "ApiKeyAuth", 407 ), 408 } 409 return auth 410 411 def to_debug_report(self): 412 """Gets the essential information for debugging. 413 414 :return: The report for debugging. 415 """ 416 return ( 417 "Python SDK Debug Report:\n" 418 "OS: {env}\n" 419 "Python Version: {pyversion}\n" 420 "Version of the API: version not set\n" 421 "SDK Package Version: 1.0.0".format(env=sys.platform, pyversion=sys.version) 422 ) 423 424 def get_host_settings(self): 425 """Gets an array of host settings 426 427 :return: An array of host settings 428 """ 429 return [ 430 { 431 "url": "https://{index_name}-{project_name}.svc.{environment}.pinecone.io", 432 "description": "No description provided", 433 "variables": { 434 "index_name": { 435 "description": "No description provided", 436 "default_value": "unknown", 437 }, 438 "project_name": { 439 "description": "No description provided", 440 "default_value": "unknown", 441 }, 442 "environment": { 443 "description": "No description provided", 444 "default_value": "unknown", 445 }, 446 }, 447 } 448 ] 449 450 def get_host_from_settings(self, index, variables=None, servers=None): 451 """Gets host URL based on the index and variables 452 :param index: array index of the host settings 453 :param variables: hash of variable and the corresponding value 454 :param servers: an array of host settings or None 455 :return: URL based on host settings 456 """ 457 if index is None: 458 return self._base_path 459 460 variables = {} if variables is None else variables 461 servers = self.get_host_settings() if servers is None else servers 462 463 try: 464 server = servers[index] 465 except IndexError: 466 raise ValueError( 467 "Invalid index {0} when selecting the host settings. " 468 "Must be less than {1}".format(index, len(servers)) 469 ) 470 471 url = server["url"] 472 473 # go through variables and replace placeholders 474 for variable_name, variable in server.get("variables", {}).items(): 475 used_value = variables.get(variable_name, variable["default_value"]) 476 477 if "enum_values" in variable and used_value not in variable["enum_values"]: 478 raise ValueError( 479 "The variable `{0}` in the host URL has invalid value " 480 "{1}. Must be {2}.".format(variable_name, variables[variable_name], variable["enum_values"]) 481 ) 482 483 url = url.replace("{" + variable_name + "}", used_value) 484 485 return url 486 487 @property 488 def host(self): 489 """Return generated host.""" 490 return self.get_host_from_settings(self.server_index, variables=self.server_variables) 491 492 @host.setter 493 def host(self, value): 494 """Fix base path.""" 495 self._base_path = value 496 self.server_index = None
37class Configuration(object): 38 """NOTE: This class is auto generated by OpenAPI Generator 39 40 Ref: https://openapi-generator.tech 41 Do not edit the class manually. 42 43 :param host: Base url 44 :param api_key: Dict to store API key(s). 45 Each entry in the dict specifies an API key. 46 The dict key is the name of the security scheme in the OAS specification. 47 The dict value is the API key secret. 48 :param api_key_prefix: Dict to store API prefix (e.g. Bearer) 49 The dict key is the name of the security scheme in the OAS specification. 50 The dict value is an API key prefix when generating the auth data. 51 :param username: Username for HTTP basic authentication 52 :param password: Password for HTTP basic authentication 53 :param discard_unknown_keys: Boolean value indicating whether to discard 54 unknown properties. A server may send a response that includes additional 55 properties that are not known by the client in the following scenarios: 56 1. The OpenAPI document is incomplete, i.e. it does not match the server 57 implementation. 58 2. The client was generated using an older version of the OpenAPI document 59 and the server has been upgraded since then. 60 If a schema in the OpenAPI document defines the additionalProperties attribute, 61 then all undeclared properties received by the server are injected into the 62 additional properties map. In that case, there are undeclared properties, and 63 nothing to discard. 64 :param disabled_client_side_validations (string): Comma-separated list of 65 JSON schema validation keywords to disable JSON schema structural validation 66 rules. The following keywords may be specified: multipleOf, maximum, 67 exclusiveMaximum, minimum, exclusiveMinimum, maxLength, minLength, pattern, 68 maxItems, minItems. 69 By default, the validation is performed for data generated locally by the client 70 and data received from the server, independent of any validation performed by 71 the server side. If the input data does not satisfy the JSON schema validation 72 rules specified in the OpenAPI document, an exception is raised. 73 If disabled_client_side_validations is set, structural validation is 74 disabled. This can be useful to troubleshoot data validation problem, such as 75 when the OpenAPI document validation rules do not match the actual API data 76 received by the server. 77 :param server_index: Index to servers configuration. 78 :param server_variables: Mapping with string values to replace variables in 79 templated server configuration. The validation of enums is performed for 80 variables with defined enum values before. 81 :param server_operation_index: Mapping from operation ID to an index to server 82 configuration. 83 :param server_operation_variables: Mapping from operation ID to a mapping with 84 string values to replace variables in templated server configuration. 85 The validation of enums is performed for variables with defined enum values before. 86 :param ssl_ca_cert: str - the path to a file of concatenated CA certificates 87 in PEM format 88 89 :Example: 90 91 API Key Authentication Example. 92 Given the following security scheme in the OpenAPI specification: 93 components: 94 securitySchemes: 95 cookieAuth: # name for the security scheme 96 type: apiKey 97 in: cookie 98 name: JSESSIONID # cookie name 99 100 You can programmatically set the cookie: 101 102 conf = pinecone.core.client.Configuration( 103 api_key={'cookieAuth': 'abc123'} 104 api_key_prefix={'cookieAuth': 'JSESSIONID'} 105 ) 106 107 The following cookie will be added to the HTTP request: 108 Cookie: JSESSIONID abc123 109 """ 110 111 _default = None 112 113 def __init__( 114 self, 115 host=None, 116 api_key=None, 117 api_key_prefix=None, 118 access_token=None, 119 username=None, 120 password=None, 121 discard_unknown_keys=False, 122 disabled_client_side_validations="", 123 server_index=None, 124 server_variables=None, 125 server_operation_index=None, 126 server_operation_variables=None, 127 ssl_ca_cert=None, 128 ): 129 """Constructor""" 130 self._base_path = "https://unknown-unknown.svc.unknown.pinecone.io" if host is None else host 131 """Default Base url 132 """ 133 self.server_index = 0 if server_index is None and host is None else server_index 134 self.server_operation_index = server_operation_index or {} 135 """Default server index 136 """ 137 self.server_variables = server_variables or {} 138 self.server_operation_variables = server_operation_variables or {} 139 """Default server variables 140 """ 141 self.temp_folder_path = None 142 """Temp file folder for downloading files 143 """ 144 # Authentication Settings 145 self.access_token = access_token 146 self.api_key = {} 147 if api_key: 148 self.api_key = api_key 149 """dict to store API key(s) 150 """ 151 self.api_key_prefix = {} 152 if api_key_prefix: 153 self.api_key_prefix = api_key_prefix 154 """dict to store API prefix (e.g. Bearer) 155 """ 156 self.refresh_api_key_hook = None 157 """function hook to refresh API key if expired 158 """ 159 self.username = username 160 """Username for HTTP basic authentication 161 """ 162 self.password = password 163 """Password for HTTP basic authentication 164 """ 165 self.discard_unknown_keys = discard_unknown_keys 166 self.disabled_client_side_validations = disabled_client_side_validations 167 self.logger = {} 168 """Logging Settings 169 """ 170 self.logger["package_logger"] = logging.getLogger("pinecone.core.client") 171 self.logger["urllib3_logger"] = logging.getLogger("urllib3") 172 self.logger_format = "%(asctime)s %(levelname)s %(message)s" 173 """Log format 174 """ 175 self.logger_stream_handler = None 176 """Log stream handler 177 """ 178 self.logger_file_handler = None 179 """Log file handler 180 """ 181 self.logger_file = None 182 """Debug file location 183 """ 184 self.debug = False 185 """Debug switch 186 """ 187 188 self.verify_ssl = True 189 """SSL/TLS verification 190 Set this to false to skip verifying SSL certificate when calling API 191 from https server. 192 """ 193 self.ssl_ca_cert = ssl_ca_cert 194 """Set this to customize the certificate file to verify the peer. 195 """ 196 self.cert_file = None 197 """client certificate file 198 """ 199 self.key_file = None 200 """client key file 201 """ 202 self.assert_hostname = None 203 """Set this to True/False to enable/disable SSL hostname verification. 204 """ 205 206 self.connection_pool_maxsize = multiprocessing.cpu_count() * 5 207 """urllib3 connection pool's maximum number of connections saved 208 per pool. urllib3 uses 1 connection as default value, but this is 209 not the best value when you are making a lot of possibly parallel 210 requests to the same host, which is often the case here. 211 cpu_count * 5 is used as default value to increase performance. 212 """ 213 214 self.proxy = None 215 """Proxy URL 216 """ 217 self.proxy_headers = None 218 """Proxy headers 219 """ 220 self.safe_chars_for_path_param = "" 221 """Safe chars for path_param 222 """ 223 self.retries = None 224 """Adding retries to override urllib3 default value 3 225 """ 226 # Enable client side validation 227 self.client_side_validation = True 228 229 # Options to pass down to the underlying urllib3 socket 230 self.socket_options = None 231 232 def __deepcopy__(self, memo): 233 cls = self.__class__ 234 result = cls.__new__(cls) 235 memo[id(self)] = result 236 for k, v in self.__dict__.items(): 237 if k not in ("logger", "logger_file_handler"): 238 setattr(result, k, copy.deepcopy(v, memo)) 239 # shallow copy of loggers 240 result.logger = copy.copy(self.logger) 241 # use setters to configure loggers 242 result.logger_file = self.logger_file 243 result.debug = self.debug 244 return result 245 246 def __setattr__(self, name, value): 247 object.__setattr__(self, name, value) 248 if name == "disabled_client_side_validations": 249 s = set(filter(None, value.split(","))) 250 for v in s: 251 if v not in JSON_SCHEMA_VALIDATION_KEYWORDS: 252 raise ApiValueError("Invalid keyword: '{0}''".format(v)) 253 self._disabled_client_side_validations = s 254 255 @classmethod 256 def set_default(cls, default): 257 """Set default instance of configuration. 258 259 It stores default configuration, which can be 260 returned by get_default_copy method. 261 262 :param default: object of Configuration 263 """ 264 cls._default = copy.deepcopy(default) 265 266 @classmethod 267 def get_default_copy(cls): 268 """Return new instance of configuration. 269 270 This method returns newly created, based on default constructor, 271 object of Configuration class or returns a copy of default 272 configuration passed by the set_default method. 273 274 :return: The configuration object. 275 """ 276 if cls._default is not None: 277 return copy.deepcopy(cls._default) 278 return Configuration() 279 280 @property 281 def logger_file(self): 282 """The logger file. 283 284 If the logger_file is None, then add stream handler and remove file 285 handler. Otherwise, add file handler and remove stream handler. 286 287 :param value: The logger_file path. 288 :type: str 289 """ 290 return self.__logger_file 291 292 @logger_file.setter 293 def logger_file(self, value): 294 """The logger file. 295 296 If the logger_file is None, then add stream handler and remove file 297 handler. Otherwise, add file handler and remove stream handler. 298 299 :param value: The logger_file path. 300 :type: str 301 """ 302 self.__logger_file = value 303 if self.__logger_file: 304 # If set logging file, 305 # then add file handler and remove stream handler. 306 self.logger_file_handler = logging.FileHandler(self.__logger_file) 307 self.logger_file_handler.setFormatter(self.logger_formatter) 308 for _, logger in self.logger.items(): 309 logger.addHandler(self.logger_file_handler) 310 311 @property 312 def debug(self): 313 """Debug status 314 315 :param value: The debug status, True or False. 316 :type: bool 317 """ 318 return self.__debug 319 320 @debug.setter 321 def debug(self, value): 322 """Debug status 323 324 :param value: The debug status, True or False. 325 :type: bool 326 """ 327 self.__debug = value 328 if self.__debug: 329 # if debug status is True, turn on debug logging 330 for _, logger in self.logger.items(): 331 logger.setLevel(logging.DEBUG) 332 # turn on http_client debug 333 http_client.HTTPConnection.debuglevel = 1 334 else: 335 # if debug status is False, turn off debug logging, 336 # setting log level to default `logging.WARNING` 337 for _, logger in self.logger.items(): 338 logger.setLevel(logging.WARNING) 339 # turn off http_client debug 340 http_client.HTTPConnection.debuglevel = 0 341 342 @property 343 def logger_format(self): 344 """The logger format. 345 346 The logger_formatter will be updated when sets logger_format. 347 348 :param value: The format string. 349 :type: str 350 """ 351 return self.__logger_format 352 353 @logger_format.setter 354 def logger_format(self, value): 355 """The logger format. 356 357 The logger_formatter will be updated when sets logger_format. 358 359 :param value: The format string. 360 :type: str 361 """ 362 self.__logger_format = value 363 self.logger_formatter = logging.Formatter(self.__logger_format) 364 365 def get_api_key_with_prefix(self, identifier, alias=None): 366 """Gets API key (with prefix if set). 367 368 :param identifier: The identifier of apiKey. 369 :param alias: The alternative identifier of apiKey. 370 :return: The token for api key authentication. 371 """ 372 if self.refresh_api_key_hook is not None: 373 self.refresh_api_key_hook(self) 374 key = self.api_key.get(identifier, self.api_key.get(alias) if alias is not None else None) 375 if key: 376 prefix = self.api_key_prefix.get(identifier) 377 if prefix: 378 return "%s %s" % (prefix, key) 379 else: 380 return key 381 382 def get_basic_auth_token(self): 383 """Gets HTTP basic authentication header (string). 384 385 :return: The token for basic HTTP authentication. 386 """ 387 username = "" 388 if self.username is not None: 389 username = self.username 390 password = "" 391 if self.password is not None: 392 password = self.password 393 return urllib3.util.make_headers(basic_auth=username + ":" + password).get("authorization") 394 395 def auth_settings(self): 396 """Gets Auth Settings dict for api client. 397 398 :return: The Auth Settings information dict. 399 """ 400 auth = {} 401 if "ApiKeyAuth" in self.api_key: 402 auth["ApiKeyAuth"] = { 403 "type": "api_key", 404 "in": "header", 405 "key": "Api-Key", 406 "value": self.get_api_key_with_prefix( 407 "ApiKeyAuth", 408 ), 409 } 410 return auth 411 412 def to_debug_report(self): 413 """Gets the essential information for debugging. 414 415 :return: The report for debugging. 416 """ 417 return ( 418 "Python SDK Debug Report:\n" 419 "OS: {env}\n" 420 "Python Version: {pyversion}\n" 421 "Version of the API: version not set\n" 422 "SDK Package Version: 1.0.0".format(env=sys.platform, pyversion=sys.version) 423 ) 424 425 def get_host_settings(self): 426 """Gets an array of host settings 427 428 :return: An array of host settings 429 """ 430 return [ 431 { 432 "url": "https://{index_name}-{project_name}.svc.{environment}.pinecone.io", 433 "description": "No description provided", 434 "variables": { 435 "index_name": { 436 "description": "No description provided", 437 "default_value": "unknown", 438 }, 439 "project_name": { 440 "description": "No description provided", 441 "default_value": "unknown", 442 }, 443 "environment": { 444 "description": "No description provided", 445 "default_value": "unknown", 446 }, 447 }, 448 } 449 ] 450 451 def get_host_from_settings(self, index, variables=None, servers=None): 452 """Gets host URL based on the index and variables 453 :param index: array index of the host settings 454 :param variables: hash of variable and the corresponding value 455 :param servers: an array of host settings or None 456 :return: URL based on host settings 457 """ 458 if index is None: 459 return self._base_path 460 461 variables = {} if variables is None else variables 462 servers = self.get_host_settings() if servers is None else servers 463 464 try: 465 server = servers[index] 466 except IndexError: 467 raise ValueError( 468 "Invalid index {0} when selecting the host settings. " 469 "Must be less than {1}".format(index, len(servers)) 470 ) 471 472 url = server["url"] 473 474 # go through variables and replace placeholders 475 for variable_name, variable in server.get("variables", {}).items(): 476 used_value = variables.get(variable_name, variable["default_value"]) 477 478 if "enum_values" in variable and used_value not in variable["enum_values"]: 479 raise ValueError( 480 "The variable `{0}` in the host URL has invalid value " 481 "{1}. Must be {2}.".format(variable_name, variables[variable_name], variable["enum_values"]) 482 ) 483 484 url = url.replace("{" + variable_name + "}", used_value) 485 486 return url 487 488 @property 489 def host(self): 490 """Return generated host.""" 491 return self.get_host_from_settings(self.server_index, variables=self.server_variables) 492 493 @host.setter 494 def host(self, value): 495 """Fix base path.""" 496 self._base_path = value 497 self.server_index = None
NOTE: This class is auto generated by OpenAPI Generator
Ref: https://openapi-generator.tech
Do not edit the class manually.
:param host: Base url
:param 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.
:param 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.
:param username: Username for HTTP basic authentication
:param password: Password for HTTP basic authentication
:param 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.
:param disabled_client_side_validations (string): 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.
:param server_index: Index to servers configuration.
:param 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.
:param server_operation_index: Mapping from operation ID to an index to server
configuration.
:param 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.
:param ssl_ca_cert: str - the path to a file of concatenated CA certificates
in PEM format
:Example:
API Key Authentication Example.
Given the following security scheme in the OpenAPI specification:
components:
securitySchemes:
cookieAuth: # name for the security scheme
type: apiKey
in: cookie
name: JSESSIONID # cookie name
You can programmatically set the cookie:
conf = pinecone.core.client.Configuration( api_key={'cookieAuth': 'abc123'} api_key_prefix={'cookieAuth': 'JSESSIONID'} )
The following cookie will be added to the HTTP request:
Cookie: JSESSIONID abc123
113 def __init__( 114 self, 115 host=None, 116 api_key=None, 117 api_key_prefix=None, 118 access_token=None, 119 username=None, 120 password=None, 121 discard_unknown_keys=False, 122 disabled_client_side_validations="", 123 server_index=None, 124 server_variables=None, 125 server_operation_index=None, 126 server_operation_variables=None, 127 ssl_ca_cert=None, 128 ): 129 """Constructor""" 130 self._base_path = "https://unknown-unknown.svc.unknown.pinecone.io" if host is None else host 131 """Default Base url 132 """ 133 self.server_index = 0 if server_index is None and host is None else server_index 134 self.server_operation_index = server_operation_index or {} 135 """Default server index 136 """ 137 self.server_variables = server_variables or {} 138 self.server_operation_variables = server_operation_variables or {} 139 """Default server variables 140 """ 141 self.temp_folder_path = None 142 """Temp file folder for downloading files 143 """ 144 # Authentication Settings 145 self.access_token = access_token 146 self.api_key = {} 147 if api_key: 148 self.api_key = api_key 149 """dict to store API key(s) 150 """ 151 self.api_key_prefix = {} 152 if api_key_prefix: 153 self.api_key_prefix = api_key_prefix 154 """dict to store API prefix (e.g. Bearer) 155 """ 156 self.refresh_api_key_hook = None 157 """function hook to refresh API key if expired 158 """ 159 self.username = username 160 """Username for HTTP basic authentication 161 """ 162 self.password = password 163 """Password for HTTP basic authentication 164 """ 165 self.discard_unknown_keys = discard_unknown_keys 166 self.disabled_client_side_validations = disabled_client_side_validations 167 self.logger = {} 168 """Logging Settings 169 """ 170 self.logger["package_logger"] = logging.getLogger("pinecone.core.client") 171 self.logger["urllib3_logger"] = logging.getLogger("urllib3") 172 self.logger_format = "%(asctime)s %(levelname)s %(message)s" 173 """Log format 174 """ 175 self.logger_stream_handler = None 176 """Log stream handler 177 """ 178 self.logger_file_handler = None 179 """Log file handler 180 """ 181 self.logger_file = None 182 """Debug file location 183 """ 184 self.debug = False 185 """Debug switch 186 """ 187 188 self.verify_ssl = True 189 """SSL/TLS verification 190 Set this to false to skip verifying SSL certificate when calling API 191 from https server. 192 """ 193 self.ssl_ca_cert = ssl_ca_cert 194 """Set this to customize the certificate file to verify the peer. 195 """ 196 self.cert_file = None 197 """client certificate file 198 """ 199 self.key_file = None 200 """client key file 201 """ 202 self.assert_hostname = None 203 """Set this to True/False to enable/disable SSL hostname verification. 204 """ 205 206 self.connection_pool_maxsize = multiprocessing.cpu_count() * 5 207 """urllib3 connection pool's maximum number of connections saved 208 per pool. urllib3 uses 1 connection as default value, but this is 209 not the best value when you are making a lot of possibly parallel 210 requests to the same host, which is often the case here. 211 cpu_count * 5 is used as default value to increase performance. 212 """ 213 214 self.proxy = None 215 """Proxy URL 216 """ 217 self.proxy_headers = None 218 """Proxy headers 219 """ 220 self.safe_chars_for_path_param = "" 221 """Safe chars for path_param 222 """ 223 self.retries = None 224 """Adding retries to override urllib3 default value 3 225 """ 226 # Enable client side validation 227 self.client_side_validation = True 228 229 # Options to pass down to the underlying urllib3 socket 230 self.socket_options = None
Constructor
SSL/TLS verification Set this to false to skip verifying SSL certificate when calling API from https server.
urllib3 connection pool's maximum number of connections saved per pool. urllib3 uses 1 connection as default value, but this is not the best value when you are making a lot of possibly parallel requests to the same host, which is often the case here. cpu_count * 5 is used as default value to increase performance.
255 @classmethod 256 def set_default(cls, default): 257 """Set default instance of configuration. 258 259 It stores default configuration, which can be 260 returned by get_default_copy method. 261 262 :param default: object of Configuration 263 """ 264 cls._default = copy.deepcopy(default)
Set default instance of configuration.
It stores default configuration, which can be returned by get_default_copy method.
Parameters
- default: object of Configuration
266 @classmethod 267 def get_default_copy(cls): 268 """Return new instance of configuration. 269 270 This method returns newly created, based on default constructor, 271 object of Configuration class or returns a copy of default 272 configuration passed by the set_default method. 273 274 :return: The configuration object. 275 """ 276 if cls._default is not None: 277 return copy.deepcopy(cls._default) 278 return Configuration()
Return new instance of configuration.
This method returns newly created, based on default constructor, object of Configuration class or returns a copy of default configuration passed by the set_default method.
Returns
The configuration object.
365 def get_api_key_with_prefix(self, identifier, alias=None): 366 """Gets API key (with prefix if set). 367 368 :param identifier: The identifier of apiKey. 369 :param alias: The alternative identifier of apiKey. 370 :return: The token for api key authentication. 371 """ 372 if self.refresh_api_key_hook is not None: 373 self.refresh_api_key_hook(self) 374 key = self.api_key.get(identifier, self.api_key.get(alias) if alias is not None else None) 375 if key: 376 prefix = self.api_key_prefix.get(identifier) 377 if prefix: 378 return "%s %s" % (prefix, key) 379 else: 380 return key
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.
382 def get_basic_auth_token(self): 383 """Gets HTTP basic authentication header (string). 384 385 :return: The token for basic HTTP authentication. 386 """ 387 username = "" 388 if self.username is not None: 389 username = self.username 390 password = "" 391 if self.password is not None: 392 password = self.password 393 return urllib3.util.make_headers(basic_auth=username + ":" + password).get("authorization")
Gets HTTP basic authentication header (string).
Returns
The token for basic HTTP authentication.
395 def auth_settings(self): 396 """Gets Auth Settings dict for api client. 397 398 :return: The Auth Settings information dict. 399 """ 400 auth = {} 401 if "ApiKeyAuth" in self.api_key: 402 auth["ApiKeyAuth"] = { 403 "type": "api_key", 404 "in": "header", 405 "key": "Api-Key", 406 "value": self.get_api_key_with_prefix( 407 "ApiKeyAuth", 408 ), 409 } 410 return auth
Gets Auth Settings dict for api client.
Returns
The Auth Settings information dict.
412 def to_debug_report(self): 413 """Gets the essential information for debugging. 414 415 :return: The report for debugging. 416 """ 417 return ( 418 "Python SDK Debug Report:\n" 419 "OS: {env}\n" 420 "Python Version: {pyversion}\n" 421 "Version of the API: version not set\n" 422 "SDK Package Version: 1.0.0".format(env=sys.platform, pyversion=sys.version) 423 )
Gets the essential information for debugging.
Returns
The report for debugging.
425 def get_host_settings(self): 426 """Gets an array of host settings 427 428 :return: An array of host settings 429 """ 430 return [ 431 { 432 "url": "https://{index_name}-{project_name}.svc.{environment}.pinecone.io", 433 "description": "No description provided", 434 "variables": { 435 "index_name": { 436 "description": "No description provided", 437 "default_value": "unknown", 438 }, 439 "project_name": { 440 "description": "No description provided", 441 "default_value": "unknown", 442 }, 443 "environment": { 444 "description": "No description provided", 445 "default_value": "unknown", 446 }, 447 }, 448 } 449 ]
Gets an array of host settings
Returns
An array of host settings
451 def get_host_from_settings(self, index, variables=None, servers=None): 452 """Gets host URL based on the index and variables 453 :param index: array index of the host settings 454 :param variables: hash of variable and the corresponding value 455 :param servers: an array of host settings or None 456 :return: URL based on host settings 457 """ 458 if index is None: 459 return self._base_path 460 461 variables = {} if variables is None else variables 462 servers = self.get_host_settings() if servers is None else servers 463 464 try: 465 server = servers[index] 466 except IndexError: 467 raise ValueError( 468 "Invalid index {0} when selecting the host settings. " 469 "Must be less than {1}".format(index, len(servers)) 470 ) 471 472 url = server["url"] 473 474 # go through variables and replace placeholders 475 for variable_name, variable in server.get("variables", {}).items(): 476 used_value = variables.get(variable_name, variable["default_value"]) 477 478 if "enum_values" in variable and used_value not in variable["enum_values"]: 479 raise ValueError( 480 "The variable `{0}` in the host URL has invalid value " 481 "{1}. Must be {2}.".format(variable_name, variables[variable_name], variable["enum_values"]) 482 ) 483 484 url = url.replace("{" + variable_name + "}", used_value) 485 486 return url
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