pinecone.openapi_support.api_client
1import atexit 2from multiprocessing.pool import ThreadPool 3from concurrent.futures import ThreadPoolExecutor 4import io 5 6from typing import Optional, List, Tuple, Dict, Any, Union 7from .deserializer import Deserializer 8 9 10from .rest_urllib3 import Urllib3RestClient 11from .configuration import Configuration 12from .exceptions import PineconeApiValueError, PineconeApiException 13from .api_client_utils import ( 14 parameters_to_tuples, 15 files_parameters, 16 parameters_to_multipart, 17 process_params, 18 process_query_params, 19 build_request_url, 20) 21from .auth_util import AuthUtil 22from .serializer import Serializer 23 24 25class ApiClient(object): 26 """Generic API client for OpenAPI client library builds. 27 28 :param configuration: .Configuration object for this client 29 :param pool_threads: The number of threads to use for async requests 30 to the API. More threads means more concurrent API requests. 31 """ 32 33 _pool: Optional[ThreadPool] = None 34 _threadpool_executor: Optional[ThreadPoolExecutor] = None 35 36 def __init__( 37 self, configuration: Optional[Configuration] = None, pool_threads: Optional[int] = 1 38 ) -> None: 39 if configuration is None: 40 configuration = Configuration.get_default_copy() 41 self.configuration = configuration 42 self.pool_threads = pool_threads 43 44 self.rest_client = Urllib3RestClient(configuration) 45 46 self.default_headers: Dict[str, str] = {} 47 self.user_agent = "OpenAPI-Generator/1.0.0/python" 48 49 def __enter__(self): 50 return self 51 52 def __exit__(self, exc_type, exc_value, traceback): 53 self.close() 54 55 def close(self): 56 if self._threadpool_executor: 57 self._threadpool_executor.shutdown() 58 self._threadpool_executor = None 59 if self._pool: 60 self._pool.close() 61 self._pool.join() 62 self._pool = None 63 if hasattr(atexit, "unregister"): 64 atexit.unregister(self.close) 65 66 @property 67 def pool(self): 68 """Create thread pool on first request 69 avoids instantiating unused threadpool for blocking clients. 70 """ 71 if self._pool is None: 72 atexit.register(self.close) 73 self._pool = ThreadPool(self.pool_threads) 74 return self._pool 75 76 @property 77 def threadpool_executor(self): 78 if self._threadpool_executor is None: 79 self._threadpool_executor = ThreadPoolExecutor(max_workers=self.pool_threads) 80 return self._threadpool_executor 81 82 @property 83 def user_agent(self): 84 """User agent for this API client""" 85 return self.default_headers["User-Agent"] 86 87 @user_agent.setter 88 def user_agent(self, value): 89 self.default_headers["User-Agent"] = value 90 91 def set_default_header(self, header_name, header_value): 92 self.default_headers[header_name] = header_value 93 94 def __call_api( 95 self, 96 resource_path: str, 97 method: str, 98 path_params: Optional[Dict[str, Any]] = None, 99 query_params: Optional[List[Tuple[str, Any]]] = None, 100 header_params: Optional[Dict[str, Any]] = None, 101 body: Optional[Any] = None, 102 post_params: Optional[List[Tuple[str, Any]]] = None, 103 files: Optional[Dict[str, List[io.IOBase]]] = None, 104 response_type: Optional[Tuple[Any]] = None, 105 auth_settings: Optional[List[str]] = None, 106 _return_http_data_only: Optional[bool] = True, 107 collection_formats: Optional[Dict[str, str]] = None, 108 _preload_content: bool = True, 109 _request_timeout: Optional[Union[int, float, Tuple]] = None, 110 _host: Optional[str] = None, 111 _check_type: Optional[bool] = None, 112 ): 113 config = self.configuration 114 115 path_params = path_params or {} 116 query_params = query_params or [] 117 header_params = header_params or {} 118 post_params = post_params or [] 119 files = files or {} 120 collection_formats = collection_formats or {} 121 122 headers_tuple, path_params_tuple, sanitized_path_params = process_params( 123 default_headers=self.default_headers, 124 header_params=header_params, 125 path_params=path_params, 126 collection_formats=collection_formats, 127 ) 128 129 processed_query_params = process_query_params(query_params, collection_formats) 130 131 # post parameters 132 if post_params or files: 133 post_params = post_params if post_params else [] 134 sanitized_post_params = Serializer.sanitize_for_serialization(post_params) 135 if sanitized_path_params: 136 processed_post_params = parameters_to_tuples( 137 sanitized_post_params, collection_formats 138 ) 139 processed_post_params.extend(files_parameters(files)) 140 if headers_tuple["Content-Type"].startswith("multipart"): 141 processed_post_params = parameters_to_multipart(sanitized_post_params, (dict)) 142 else: 143 processed_post_params = None 144 145 # body 146 if body: 147 body = Serializer.sanitize_for_serialization(body) 148 149 # auth setting 150 AuthUtil.update_params_for_auth( 151 configuration=config, 152 endpoint_auth_settings=auth_settings, 153 headers=headers_tuple, 154 querys=processed_query_params, 155 ) 156 157 url = build_request_url( 158 config=config, 159 processed_path_params=path_params_tuple, 160 resource_path=resource_path, 161 _host=_host, 162 ) 163 164 try: 165 # perform request and return response 166 response_data = self.request( 167 method, 168 url, 169 query_params=processed_query_params, 170 headers=headers_tuple, 171 post_params=processed_post_params, 172 body=body, 173 _preload_content=_preload_content, 174 _request_timeout=_request_timeout, 175 ) 176 except PineconeApiException as e: 177 e.body = e.body.decode("utf-8") 178 raise e 179 180 self.last_response = response_data 181 182 return_data = response_data 183 184 if not _preload_content: 185 return return_data 186 187 # deserialize response data 188 if response_type: 189 Deserializer.decode_response(response_type=response_type, response=response_data) 190 return_data = Deserializer.deserialize( 191 response=response_data, 192 response_type=response_type, 193 config=self.configuration, 194 _check_type=_check_type, 195 ) 196 else: 197 return_data = None 198 199 if _return_http_data_only: 200 return return_data 201 else: 202 return (return_data, response_data.status, response_data.getheaders()) 203 204 def call_api( 205 self, 206 resource_path: str, 207 method: str, 208 path_params: Optional[Dict[str, Any]] = None, 209 query_params: Optional[List[Tuple[str, Any]]] = None, 210 header_params: Optional[Dict[str, Any]] = None, 211 body: Optional[Any] = None, 212 post_params: Optional[List[Tuple[str, Any]]] = None, 213 files: Optional[Dict[str, List[io.IOBase]]] = None, 214 response_type: Optional[Tuple[Any]] = None, 215 auth_settings: Optional[List[str]] = None, 216 async_req: Optional[bool] = None, 217 async_threadpool_executor: Optional[bool] = None, 218 _return_http_data_only: Optional[bool] = None, 219 collection_formats: Optional[Dict[str, str]] = None, 220 _preload_content: bool = True, 221 _request_timeout: Optional[Union[int, float, Tuple]] = None, 222 _host: Optional[str] = None, 223 _check_type: Optional[bool] = None, 224 ): 225 """Makes the HTTP request (synchronous) and returns deserialized data. 226 227 To make an async_req request, set the async_req parameter. 228 229 :param resource_path: Path to method endpoint. 230 :param method: Method to call. 231 :param path_params: Path parameters in the url. 232 :param query_params: Query parameters in the url. 233 :param header_params: Header parameters to be 234 placed in the request header. 235 :param body: Request body. 236 :param post_params dict: Request post form parameters, 237 for `application/x-www-form-urlencoded`, `multipart/form-data`. 238 :param auth_settings list: Auth Settings names for the request. 239 :param response_type: For the response, a tuple containing: 240 valid classes 241 a list containing valid classes (for list schemas) 242 a dict containing a tuple of valid classes as the value 243 Example values: 244 (str,) 245 (Pet,) 246 (float, none_type) 247 ([int, none_type],) 248 ({str: (bool, str, int, float, date, datetime, str, none_type)},) 249 :param files: key -> field name, value -> a list of open file 250 objects for `multipart/form-data`. 251 :type files: dict 252 :param async_req bool: execute request asynchronously 253 :type async_req: bool, optional 254 :param _return_http_data_only: response data without head status code 255 and headers 256 :type _return_http_data_only: bool, optional 257 :param collection_formats: dict of collection formats for path, query, 258 header, and post parameters. 259 :type collection_formats: dict, optional 260 :param _preload_content: if False, the urllib3.HTTPResponse object will 261 be returned without reading/decoding response 262 data. Default is True. 263 :type _preload_content: bool, optional 264 :param _request_timeout: timeout setting for this request. If one 265 number provided, it will be total request 266 timeout. It can also be a pair (tuple) of 267 (connection, read) timeouts. 268 :param _check_type: boolean describing if the data back from the server 269 should have its type checked. 270 :type _check_type: bool, optional 271 :return: 272 If async_req parameter is True, 273 the request will be called asynchronously. 274 The method will return the request thread. 275 If parameter async_req is False or missing, 276 then the method will return the response directly. 277 """ 278 if async_threadpool_executor: 279 return self.threadpool_executor.submit( 280 self.__call_api, 281 resource_path, 282 method, 283 path_params, 284 query_params, 285 header_params, 286 body, 287 post_params, 288 files, 289 response_type, 290 auth_settings, 291 _return_http_data_only, 292 collection_formats, 293 _preload_content, 294 _request_timeout, 295 _host, 296 _check_type, 297 ) 298 299 if not async_req: 300 return self.__call_api( 301 resource_path, 302 method, 303 path_params, 304 query_params, 305 header_params, 306 body, 307 post_params, 308 files, 309 response_type, 310 auth_settings, 311 _return_http_data_only, 312 collection_formats, 313 _preload_content, 314 _request_timeout, 315 _host, 316 _check_type, 317 ) 318 319 return self.pool.apply_async( 320 self.__call_api, 321 ( 322 resource_path, 323 method, 324 path_params, 325 query_params, 326 header_params, 327 body, 328 post_params, 329 files, 330 response_type, 331 auth_settings, 332 _return_http_data_only, 333 collection_formats, 334 _preload_content, 335 _request_timeout, 336 _host, 337 _check_type, 338 ), 339 ) 340 341 def request( 342 self, 343 method, 344 url, 345 query_params=None, 346 headers=None, 347 post_params=None, 348 body=None, 349 _preload_content=True, 350 _request_timeout=None, 351 ): 352 """Makes the HTTP request using RESTClient.""" 353 if method == "GET": 354 return self.rest_client.GET( 355 url, 356 query_params=query_params, 357 _preload_content=_preload_content, 358 _request_timeout=_request_timeout, 359 headers=headers, 360 ) 361 elif method == "HEAD": 362 return self.rest_client.HEAD( 363 url, 364 query_params=query_params, 365 _preload_content=_preload_content, 366 _request_timeout=_request_timeout, 367 headers=headers, 368 ) 369 elif method == "OPTIONS": 370 return self.rest_client.OPTIONS( 371 url, 372 query_params=query_params, 373 headers=headers, 374 post_params=post_params, 375 _preload_content=_preload_content, 376 _request_timeout=_request_timeout, 377 body=body, 378 ) 379 elif method == "POST": 380 return self.rest_client.POST( 381 url, 382 query_params=query_params, 383 headers=headers, 384 post_params=post_params, 385 _preload_content=_preload_content, 386 _request_timeout=_request_timeout, 387 body=body, 388 ) 389 elif method == "PUT": 390 return self.rest_client.PUT( 391 url, 392 query_params=query_params, 393 headers=headers, 394 post_params=post_params, 395 _preload_content=_preload_content, 396 _request_timeout=_request_timeout, 397 body=body, 398 ) 399 elif method == "PATCH": 400 return self.rest_client.PATCH( 401 url, 402 query_params=query_params, 403 headers=headers, 404 post_params=post_params, 405 _preload_content=_preload_content, 406 _request_timeout=_request_timeout, 407 body=body, 408 ) 409 elif method == "DELETE": 410 return self.rest_client.DELETE( 411 url, 412 query_params=query_params, 413 headers=headers, 414 _preload_content=_preload_content, 415 _request_timeout=_request_timeout, 416 body=body, 417 ) 418 else: 419 raise PineconeApiValueError( 420 "http method must be `GET`, `HEAD`, `OPTIONS`, `POST`, `PATCH`, `PUT` or `DELETE`." 421 )
class
ApiClient:
26class ApiClient(object): 27 """Generic API client for OpenAPI client library builds. 28 29 :param configuration: .Configuration object for this client 30 :param pool_threads: The number of threads to use for async requests 31 to the API. More threads means more concurrent API requests. 32 """ 33 34 _pool: Optional[ThreadPool] = None 35 _threadpool_executor: Optional[ThreadPoolExecutor] = None 36 37 def __init__( 38 self, configuration: Optional[Configuration] = None, pool_threads: Optional[int] = 1 39 ) -> None: 40 if configuration is None: 41 configuration = Configuration.get_default_copy() 42 self.configuration = configuration 43 self.pool_threads = pool_threads 44 45 self.rest_client = Urllib3RestClient(configuration) 46 47 self.default_headers: Dict[str, str] = {} 48 self.user_agent = "OpenAPI-Generator/1.0.0/python" 49 50 def __enter__(self): 51 return self 52 53 def __exit__(self, exc_type, exc_value, traceback): 54 self.close() 55 56 def close(self): 57 if self._threadpool_executor: 58 self._threadpool_executor.shutdown() 59 self._threadpool_executor = None 60 if self._pool: 61 self._pool.close() 62 self._pool.join() 63 self._pool = None 64 if hasattr(atexit, "unregister"): 65 atexit.unregister(self.close) 66 67 @property 68 def pool(self): 69 """Create thread pool on first request 70 avoids instantiating unused threadpool for blocking clients. 71 """ 72 if self._pool is None: 73 atexit.register(self.close) 74 self._pool = ThreadPool(self.pool_threads) 75 return self._pool 76 77 @property 78 def threadpool_executor(self): 79 if self._threadpool_executor is None: 80 self._threadpool_executor = ThreadPoolExecutor(max_workers=self.pool_threads) 81 return self._threadpool_executor 82 83 @property 84 def user_agent(self): 85 """User agent for this API client""" 86 return self.default_headers["User-Agent"] 87 88 @user_agent.setter 89 def user_agent(self, value): 90 self.default_headers["User-Agent"] = value 91 92 def set_default_header(self, header_name, header_value): 93 self.default_headers[header_name] = header_value 94 95 def __call_api( 96 self, 97 resource_path: str, 98 method: str, 99 path_params: Optional[Dict[str, Any]] = None, 100 query_params: Optional[List[Tuple[str, Any]]] = None, 101 header_params: Optional[Dict[str, Any]] = None, 102 body: Optional[Any] = None, 103 post_params: Optional[List[Tuple[str, Any]]] = None, 104 files: Optional[Dict[str, List[io.IOBase]]] = None, 105 response_type: Optional[Tuple[Any]] = None, 106 auth_settings: Optional[List[str]] = None, 107 _return_http_data_only: Optional[bool] = True, 108 collection_formats: Optional[Dict[str, str]] = None, 109 _preload_content: bool = True, 110 _request_timeout: Optional[Union[int, float, Tuple]] = None, 111 _host: Optional[str] = None, 112 _check_type: Optional[bool] = None, 113 ): 114 config = self.configuration 115 116 path_params = path_params or {} 117 query_params = query_params or [] 118 header_params = header_params or {} 119 post_params = post_params or [] 120 files = files or {} 121 collection_formats = collection_formats or {} 122 123 headers_tuple, path_params_tuple, sanitized_path_params = process_params( 124 default_headers=self.default_headers, 125 header_params=header_params, 126 path_params=path_params, 127 collection_formats=collection_formats, 128 ) 129 130 processed_query_params = process_query_params(query_params, collection_formats) 131 132 # post parameters 133 if post_params or files: 134 post_params = post_params if post_params else [] 135 sanitized_post_params = Serializer.sanitize_for_serialization(post_params) 136 if sanitized_path_params: 137 processed_post_params = parameters_to_tuples( 138 sanitized_post_params, collection_formats 139 ) 140 processed_post_params.extend(files_parameters(files)) 141 if headers_tuple["Content-Type"].startswith("multipart"): 142 processed_post_params = parameters_to_multipart(sanitized_post_params, (dict)) 143 else: 144 processed_post_params = None 145 146 # body 147 if body: 148 body = Serializer.sanitize_for_serialization(body) 149 150 # auth setting 151 AuthUtil.update_params_for_auth( 152 configuration=config, 153 endpoint_auth_settings=auth_settings, 154 headers=headers_tuple, 155 querys=processed_query_params, 156 ) 157 158 url = build_request_url( 159 config=config, 160 processed_path_params=path_params_tuple, 161 resource_path=resource_path, 162 _host=_host, 163 ) 164 165 try: 166 # perform request and return response 167 response_data = self.request( 168 method, 169 url, 170 query_params=processed_query_params, 171 headers=headers_tuple, 172 post_params=processed_post_params, 173 body=body, 174 _preload_content=_preload_content, 175 _request_timeout=_request_timeout, 176 ) 177 except PineconeApiException as e: 178 e.body = e.body.decode("utf-8") 179 raise e 180 181 self.last_response = response_data 182 183 return_data = response_data 184 185 if not _preload_content: 186 return return_data 187 188 # deserialize response data 189 if response_type: 190 Deserializer.decode_response(response_type=response_type, response=response_data) 191 return_data = Deserializer.deserialize( 192 response=response_data, 193 response_type=response_type, 194 config=self.configuration, 195 _check_type=_check_type, 196 ) 197 else: 198 return_data = None 199 200 if _return_http_data_only: 201 return return_data 202 else: 203 return (return_data, response_data.status, response_data.getheaders()) 204 205 def call_api( 206 self, 207 resource_path: str, 208 method: str, 209 path_params: Optional[Dict[str, Any]] = None, 210 query_params: Optional[List[Tuple[str, Any]]] = None, 211 header_params: Optional[Dict[str, Any]] = None, 212 body: Optional[Any] = None, 213 post_params: Optional[List[Tuple[str, Any]]] = None, 214 files: Optional[Dict[str, List[io.IOBase]]] = None, 215 response_type: Optional[Tuple[Any]] = None, 216 auth_settings: Optional[List[str]] = None, 217 async_req: Optional[bool] = None, 218 async_threadpool_executor: Optional[bool] = None, 219 _return_http_data_only: Optional[bool] = None, 220 collection_formats: Optional[Dict[str, str]] = None, 221 _preload_content: bool = True, 222 _request_timeout: Optional[Union[int, float, Tuple]] = None, 223 _host: Optional[str] = None, 224 _check_type: Optional[bool] = None, 225 ): 226 """Makes the HTTP request (synchronous) and returns deserialized data. 227 228 To make an async_req request, set the async_req parameter. 229 230 :param resource_path: Path to method endpoint. 231 :param method: Method to call. 232 :param path_params: Path parameters in the url. 233 :param query_params: Query parameters in the url. 234 :param header_params: Header parameters to be 235 placed in the request header. 236 :param body: Request body. 237 :param post_params dict: Request post form parameters, 238 for `application/x-www-form-urlencoded`, `multipart/form-data`. 239 :param auth_settings list: Auth Settings names for the request. 240 :param response_type: For the response, a tuple containing: 241 valid classes 242 a list containing valid classes (for list schemas) 243 a dict containing a tuple of valid classes as the value 244 Example values: 245 (str,) 246 (Pet,) 247 (float, none_type) 248 ([int, none_type],) 249 ({str: (bool, str, int, float, date, datetime, str, none_type)},) 250 :param files: key -> field name, value -> a list of open file 251 objects for `multipart/form-data`. 252 :type files: dict 253 :param async_req bool: execute request asynchronously 254 :type async_req: bool, optional 255 :param _return_http_data_only: response data without head status code 256 and headers 257 :type _return_http_data_only: bool, optional 258 :param collection_formats: dict of collection formats for path, query, 259 header, and post parameters. 260 :type collection_formats: dict, optional 261 :param _preload_content: if False, the urllib3.HTTPResponse object will 262 be returned without reading/decoding response 263 data. Default is True. 264 :type _preload_content: bool, optional 265 :param _request_timeout: timeout setting for this request. If one 266 number provided, it will be total request 267 timeout. It can also be a pair (tuple) of 268 (connection, read) timeouts. 269 :param _check_type: boolean describing if the data back from the server 270 should have its type checked. 271 :type _check_type: bool, optional 272 :return: 273 If async_req parameter is True, 274 the request will be called asynchronously. 275 The method will return the request thread. 276 If parameter async_req is False or missing, 277 then the method will return the response directly. 278 """ 279 if async_threadpool_executor: 280 return self.threadpool_executor.submit( 281 self.__call_api, 282 resource_path, 283 method, 284 path_params, 285 query_params, 286 header_params, 287 body, 288 post_params, 289 files, 290 response_type, 291 auth_settings, 292 _return_http_data_only, 293 collection_formats, 294 _preload_content, 295 _request_timeout, 296 _host, 297 _check_type, 298 ) 299 300 if not async_req: 301 return self.__call_api( 302 resource_path, 303 method, 304 path_params, 305 query_params, 306 header_params, 307 body, 308 post_params, 309 files, 310 response_type, 311 auth_settings, 312 _return_http_data_only, 313 collection_formats, 314 _preload_content, 315 _request_timeout, 316 _host, 317 _check_type, 318 ) 319 320 return self.pool.apply_async( 321 self.__call_api, 322 ( 323 resource_path, 324 method, 325 path_params, 326 query_params, 327 header_params, 328 body, 329 post_params, 330 files, 331 response_type, 332 auth_settings, 333 _return_http_data_only, 334 collection_formats, 335 _preload_content, 336 _request_timeout, 337 _host, 338 _check_type, 339 ), 340 ) 341 342 def request( 343 self, 344 method, 345 url, 346 query_params=None, 347 headers=None, 348 post_params=None, 349 body=None, 350 _preload_content=True, 351 _request_timeout=None, 352 ): 353 """Makes the HTTP request using RESTClient.""" 354 if method == "GET": 355 return self.rest_client.GET( 356 url, 357 query_params=query_params, 358 _preload_content=_preload_content, 359 _request_timeout=_request_timeout, 360 headers=headers, 361 ) 362 elif method == "HEAD": 363 return self.rest_client.HEAD( 364 url, 365 query_params=query_params, 366 _preload_content=_preload_content, 367 _request_timeout=_request_timeout, 368 headers=headers, 369 ) 370 elif method == "OPTIONS": 371 return self.rest_client.OPTIONS( 372 url, 373 query_params=query_params, 374 headers=headers, 375 post_params=post_params, 376 _preload_content=_preload_content, 377 _request_timeout=_request_timeout, 378 body=body, 379 ) 380 elif method == "POST": 381 return self.rest_client.POST( 382 url, 383 query_params=query_params, 384 headers=headers, 385 post_params=post_params, 386 _preload_content=_preload_content, 387 _request_timeout=_request_timeout, 388 body=body, 389 ) 390 elif method == "PUT": 391 return self.rest_client.PUT( 392 url, 393 query_params=query_params, 394 headers=headers, 395 post_params=post_params, 396 _preload_content=_preload_content, 397 _request_timeout=_request_timeout, 398 body=body, 399 ) 400 elif method == "PATCH": 401 return self.rest_client.PATCH( 402 url, 403 query_params=query_params, 404 headers=headers, 405 post_params=post_params, 406 _preload_content=_preload_content, 407 _request_timeout=_request_timeout, 408 body=body, 409 ) 410 elif method == "DELETE": 411 return self.rest_client.DELETE( 412 url, 413 query_params=query_params, 414 headers=headers, 415 _preload_content=_preload_content, 416 _request_timeout=_request_timeout, 417 body=body, 418 ) 419 else: 420 raise PineconeApiValueError( 421 "http method must be `GET`, `HEAD`, `OPTIONS`, `POST`, `PATCH`, `PUT` or `DELETE`." 422 )
Generic API client for OpenAPI client library builds.
Parameters
- configuration: .Configuration object for this client
- pool_threads: The number of threads to use for async requests to the API. More threads means more concurrent API requests.
ApiClient( configuration: Optional[pinecone.openapi_support.configuration.Configuration] = None, pool_threads: Optional[int] = 1)
37 def __init__( 38 self, configuration: Optional[Configuration] = None, pool_threads: Optional[int] = 1 39 ) -> None: 40 if configuration is None: 41 configuration = Configuration.get_default_copy() 42 self.configuration = configuration 43 self.pool_threads = pool_threads 44 45 self.rest_client = Urllib3RestClient(configuration) 46 47 self.default_headers: Dict[str, str] = {} 48 self.user_agent = "OpenAPI-Generator/1.0.0/python"
user_agent
83 @property 84 def user_agent(self): 85 """User agent for this API client""" 86 return self.default_headers["User-Agent"]
User agent for this API client
pool
67 @property 68 def pool(self): 69 """Create thread pool on first request 70 avoids instantiating unused threadpool for blocking clients. 71 """ 72 if self._pool is None: 73 atexit.register(self.close) 74 self._pool = ThreadPool(self.pool_threads) 75 return self._pool
Create thread pool on first request avoids instantiating unused threadpool for blocking clients.
def
call_api( self, resource_path: str, method: str, path_params: Optional[Dict[str, Any]] = None, query_params: Optional[List[Tuple[str, Any]]] = None, header_params: Optional[Dict[str, Any]] = None, body: Optional[Any] = None, post_params: Optional[List[Tuple[str, Any]]] = None, files: Optional[Dict[str, List[io.IOBase]]] = None, response_type: Optional[Tuple[Any]] = None, auth_settings: Optional[List[str]] = None, async_req: Optional[bool] = None, async_threadpool_executor: Optional[bool] = None, _return_http_data_only: Optional[bool] = None, collection_formats: Optional[Dict[str, str]] = None, _preload_content: bool = True, _request_timeout: Union[int, float, Tuple, NoneType] = None, _host: Optional[str] = None, _check_type: Optional[bool] = None):
205 def call_api( 206 self, 207 resource_path: str, 208 method: str, 209 path_params: Optional[Dict[str, Any]] = None, 210 query_params: Optional[List[Tuple[str, Any]]] = None, 211 header_params: Optional[Dict[str, Any]] = None, 212 body: Optional[Any] = None, 213 post_params: Optional[List[Tuple[str, Any]]] = None, 214 files: Optional[Dict[str, List[io.IOBase]]] = None, 215 response_type: Optional[Tuple[Any]] = None, 216 auth_settings: Optional[List[str]] = None, 217 async_req: Optional[bool] = None, 218 async_threadpool_executor: Optional[bool] = None, 219 _return_http_data_only: Optional[bool] = None, 220 collection_formats: Optional[Dict[str, str]] = None, 221 _preload_content: bool = True, 222 _request_timeout: Optional[Union[int, float, Tuple]] = None, 223 _host: Optional[str] = None, 224 _check_type: Optional[bool] = None, 225 ): 226 """Makes the HTTP request (synchronous) and returns deserialized data. 227 228 To make an async_req request, set the async_req parameter. 229 230 :param resource_path: Path to method endpoint. 231 :param method: Method to call. 232 :param path_params: Path parameters in the url. 233 :param query_params: Query parameters in the url. 234 :param header_params: Header parameters to be 235 placed in the request header. 236 :param body: Request body. 237 :param post_params dict: Request post form parameters, 238 for `application/x-www-form-urlencoded`, `multipart/form-data`. 239 :param auth_settings list: Auth Settings names for the request. 240 :param response_type: For the response, a tuple containing: 241 valid classes 242 a list containing valid classes (for list schemas) 243 a dict containing a tuple of valid classes as the value 244 Example values: 245 (str,) 246 (Pet,) 247 (float, none_type) 248 ([int, none_type],) 249 ({str: (bool, str, int, float, date, datetime, str, none_type)},) 250 :param files: key -> field name, value -> a list of open file 251 objects for `multipart/form-data`. 252 :type files: dict 253 :param async_req bool: execute request asynchronously 254 :type async_req: bool, optional 255 :param _return_http_data_only: response data without head status code 256 and headers 257 :type _return_http_data_only: bool, optional 258 :param collection_formats: dict of collection formats for path, query, 259 header, and post parameters. 260 :type collection_formats: dict, optional 261 :param _preload_content: if False, the urllib3.HTTPResponse object will 262 be returned without reading/decoding response 263 data. Default is True. 264 :type _preload_content: bool, optional 265 :param _request_timeout: timeout setting for this request. If one 266 number provided, it will be total request 267 timeout. It can also be a pair (tuple) of 268 (connection, read) timeouts. 269 :param _check_type: boolean describing if the data back from the server 270 should have its type checked. 271 :type _check_type: bool, optional 272 :return: 273 If async_req parameter is True, 274 the request will be called asynchronously. 275 The method will return the request thread. 276 If parameter async_req is False or missing, 277 then the method will return the response directly. 278 """ 279 if async_threadpool_executor: 280 return self.threadpool_executor.submit( 281 self.__call_api, 282 resource_path, 283 method, 284 path_params, 285 query_params, 286 header_params, 287 body, 288 post_params, 289 files, 290 response_type, 291 auth_settings, 292 _return_http_data_only, 293 collection_formats, 294 _preload_content, 295 _request_timeout, 296 _host, 297 _check_type, 298 ) 299 300 if not async_req: 301 return self.__call_api( 302 resource_path, 303 method, 304 path_params, 305 query_params, 306 header_params, 307 body, 308 post_params, 309 files, 310 response_type, 311 auth_settings, 312 _return_http_data_only, 313 collection_formats, 314 _preload_content, 315 _request_timeout, 316 _host, 317 _check_type, 318 ) 319 320 return self.pool.apply_async( 321 self.__call_api, 322 ( 323 resource_path, 324 method, 325 path_params, 326 query_params, 327 header_params, 328 body, 329 post_params, 330 files, 331 response_type, 332 auth_settings, 333 _return_http_data_only, 334 collection_formats, 335 _preload_content, 336 _request_timeout, 337 _host, 338 _check_type, 339 ), 340 )
Makes the HTTP request (synchronous) and returns deserialized data.
To make an async_req request, set the async_req parameter.
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.
- post_params dict: Request post form parameters,
for
application/x-www-form-urlencoded
,multipart/form-data
. - auth_settings list: Auth Settings names for the request.
- 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: key -> field name, value -> a list of open file
objects for
multipart/form-data
. - async_req bool: execute request asynchronously
- _return_http_data_only: response data without head status code and headers
- collection_formats: dict of collection formats for path, query, header, and post parameters.
- _preload_content: 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: boolean describing if the data back from the server should have its type checked.
Returns
If async_req parameter is True, the request will be called asynchronously. The method will return the request thread. If parameter async_req is False or missing, then the method will return the response directly.
def
request( self, method, url, query_params=None, headers=None, post_params=None, body=None, _preload_content=True, _request_timeout=None):
342 def request( 343 self, 344 method, 345 url, 346 query_params=None, 347 headers=None, 348 post_params=None, 349 body=None, 350 _preload_content=True, 351 _request_timeout=None, 352 ): 353 """Makes the HTTP request using RESTClient.""" 354 if method == "GET": 355 return self.rest_client.GET( 356 url, 357 query_params=query_params, 358 _preload_content=_preload_content, 359 _request_timeout=_request_timeout, 360 headers=headers, 361 ) 362 elif method == "HEAD": 363 return self.rest_client.HEAD( 364 url, 365 query_params=query_params, 366 _preload_content=_preload_content, 367 _request_timeout=_request_timeout, 368 headers=headers, 369 ) 370 elif method == "OPTIONS": 371 return self.rest_client.OPTIONS( 372 url, 373 query_params=query_params, 374 headers=headers, 375 post_params=post_params, 376 _preload_content=_preload_content, 377 _request_timeout=_request_timeout, 378 body=body, 379 ) 380 elif method == "POST": 381 return self.rest_client.POST( 382 url, 383 query_params=query_params, 384 headers=headers, 385 post_params=post_params, 386 _preload_content=_preload_content, 387 _request_timeout=_request_timeout, 388 body=body, 389 ) 390 elif method == "PUT": 391 return self.rest_client.PUT( 392 url, 393 query_params=query_params, 394 headers=headers, 395 post_params=post_params, 396 _preload_content=_preload_content, 397 _request_timeout=_request_timeout, 398 body=body, 399 ) 400 elif method == "PATCH": 401 return self.rest_client.PATCH( 402 url, 403 query_params=query_params, 404 headers=headers, 405 post_params=post_params, 406 _preload_content=_preload_content, 407 _request_timeout=_request_timeout, 408 body=body, 409 ) 410 elif method == "DELETE": 411 return self.rest_client.DELETE( 412 url, 413 query_params=query_params, 414 headers=headers, 415 _preload_content=_preload_content, 416 _request_timeout=_request_timeout, 417 body=body, 418 ) 419 else: 420 raise PineconeApiValueError( 421 "http method must be `GET`, `HEAD`, `OPTIONS`, `POST`, `PATCH`, `PUT` or `DELETE`." 422 )
Makes the HTTP request using RESTClient.