pinecone .openapi_support .asyncio_api_client
1import json 2import io 3from urllib3.fields import RequestField 4import logging 5 6from typing import Optional, List, Tuple, Dict, Any, Union 7 8 9from .rest_aiohttp import AiohttpRestClient 10from .configuration import Configuration 11from .exceptions import PineconeApiValueError, PineconeApiException 12from .api_client_utils import ( 13 parameters_to_tuples, 14 files_parameters, 15 parameters_to_multipart, 16 process_params, 17 process_query_params, 18 build_request_url, 19) 20from .serializer import Serializer 21from .deserializer import Deserializer 22from .auth_util import AuthUtil 23 24logger = logging.getLogger(__name__) 25""" @private """ 26 27 28class AsyncioApiClient(object): 29 """Generic async API client for OpenAPI client library builds. 30 31 :param configuration: .Configuration object for this client 32 """ 33 34 def __init__(self, configuration=None, **kwargs) -> None: 35 if configuration is None: 36 configuration = Configuration.get_default_copy() 37 self.configuration = configuration 38 39 self.rest_client = AiohttpRestClient(configuration) 40 41 self.default_headers: Dict[str, str] = {} 42 # Set default User-Agent. 43 self.user_agent = "OpenAPI-Generator/1.0.0/python" 44 45 async def __aenter__(self): 46 return self 47 48 async def __aexit__(self, exc_type, exc_value, traceback): 49 await self.close() 50 51 async def close(self): 52 logger.debug("Closing the aiohttp client") 53 await self.rest_client.close() 54 55 @property 56 def user_agent(self): 57 """User agent for this API client""" 58 return self.default_headers["User-Agent"] 59 60 @user_agent.setter 61 def user_agent(self, value): 62 self.default_headers["User-Agent"] = value 63 64 def set_default_header(self, header_name, header_value): 65 self.default_headers[header_name] = header_value 66 67 async def __call_api( 68 self, 69 resource_path: str, 70 method: str, 71 path_params: Optional[Dict[str, Any]] = None, 72 query_params: Optional[List[Tuple[str, Any]]] = None, 73 header_params: Optional[Dict[str, Any]] = None, 74 body: Optional[Any] = None, 75 post_params: Optional[List[Tuple[str, Any]]] = None, 76 files: Optional[Dict[str, List[io.IOBase]]] = None, 77 response_type: Optional[Tuple[Any]] = None, 78 auth_settings: Optional[List[str]] = None, 79 _return_http_data_only: Optional[bool] = None, 80 collection_formats: Optional[Dict[str, str]] = None, 81 _preload_content: bool = True, 82 _request_timeout: Optional[Union[int, float, Tuple]] = None, 83 _host: Optional[str] = None, 84 _check_type: Optional[bool] = None, 85 ): 86 config = self.configuration 87 88 path_params = path_params or {} 89 query_params = query_params or [] 90 header_params = header_params or {} 91 post_params = post_params or [] 92 files = files or {} 93 collection_formats = collection_formats or {} 94 95 processed_header_params, processed_path_params, sanitized_path_params = process_params( 96 default_headers=self.default_headers, 97 header_params=header_params, 98 path_params=path_params, 99 collection_formats=collection_formats, 100 ) 101 102 processed_query_params = process_query_params(query_params, collection_formats) 103 104 # post parameters 105 if post_params or files: 106 post_params = post_params if post_params else [] 107 sanitized_post_params = Serializer.sanitize_for_serialization(post_params) 108 if sanitized_path_params: 109 processed_post_params = parameters_to_tuples( 110 sanitized_post_params, collection_formats 111 ) 112 processed_post_params.extend(files_parameters(files)) 113 if processed_header_params["Content-Type"].startswith("multipart"): 114 processed_post_params = parameters_to_multipart(sanitized_post_params, (dict)) 115 else: 116 processed_post_params = None 117 118 # body 119 if body: 120 body = Serializer.sanitize_for_serialization(body) 121 122 # auth setting 123 AuthUtil.update_params_for_auth( 124 configuration=self.configuration, 125 endpoint_auth_settings=auth_settings, 126 headers=processed_header_params, 127 querys=processed_query_params, 128 ) 129 130 url = build_request_url( 131 config=config, 132 processed_path_params=processed_path_params, 133 resource_path=resource_path, 134 _host=_host, 135 ) 136 137 try: 138 # perform request and return response 139 response_data = await self.request( 140 method, 141 url, 142 query_params=processed_query_params, 143 headers=processed_header_params, 144 post_params=processed_post_params, 145 body=body, 146 _preload_content=_preload_content, 147 _request_timeout=_request_timeout, 148 ) 149 except PineconeApiException as e: 150 e.body = e.body.decode("utf-8") 151 raise e 152 153 self.last_response = response_data 154 155 return_data = response_data 156 157 if not _preload_content: 158 return return_data 159 160 # deserialize response data 161 if response_type: 162 Deserializer.decode_response(response_type=response_type, response=response_data) 163 return_data = Deserializer.deserialize( 164 response_data, response_type, self.configuration, _check_type 165 ) 166 else: 167 return_data = None 168 169 if _return_http_data_only: 170 return return_data 171 else: 172 return (return_data, response_data.status, response_data.getheaders()) 173 174 def parameters_to_multipart(self, params, collection_types): 175 """Get parameters as list of tuples, formatting as json if value is collection_types 176 177 :param params: Parameters as list of two-tuples 178 :param dict collection_types: Parameter collection types 179 :return: Parameters as list of tuple or urllib3.fields.RequestField 180 """ 181 new_params = [] 182 if collection_types is None: 183 collection_types = dict 184 for k, v in params.items() if isinstance(params, dict) else params: # noqa: E501 185 if isinstance( 186 v, collection_types 187 ): # v is instance of collection_type, formatting as application/json 188 v = json.dumps(v, ensure_ascii=False).encode("utf-8") 189 field = RequestField(k, v) 190 field.make_multipart(content_type="application/json; charset=utf-8") 191 new_params.append(field) 192 else: 193 new_params.append((k, v)) 194 return new_params 195 196 async def call_api( 197 self, 198 resource_path: str, 199 method: str, 200 path_params: Optional[Dict[str, Any]] = None, 201 query_params: Optional[List[Tuple[str, Any]]] = None, 202 header_params: Optional[Dict[str, Any]] = None, 203 body: Optional[Any] = None, 204 post_params: Optional[List[Tuple[str, Any]]] = None, 205 files: Optional[Dict[str, List[io.IOBase]]] = None, 206 response_type: Optional[Tuple[Any]] = None, 207 auth_settings: Optional[List[str]] = None, 208 _return_http_data_only: Optional[bool] = None, 209 collection_formats: Optional[Dict[str, str]] = None, 210 _preload_content: bool = True, 211 _request_timeout: Optional[Union[int, float, Tuple]] = None, 212 _host: Optional[str] = None, 213 _check_type: Optional[bool] = None, 214 ): 215 """Makes the HTTP request (synchronous) and returns deserialized data. 216 217 :param resource_path: Path to method endpoint. 218 :param method: Method to call. 219 :param path_params: Path parameters in the url. 220 :param query_params: Query parameters in the url. 221 :param header_params: Header parameters to be 222 placed in the request header. 223 :param body: Request body. 224 :param post_params dict: Request post form parameters, 225 for `application/x-www-form-urlencoded`, `multipart/form-data`. 226 :param auth_settings list: Auth Settings names for the request. 227 :param response_type: For the response, a tuple containing: 228 valid classes 229 a list containing valid classes (for list schemas) 230 a dict containing a tuple of valid classes as the value 231 Example values: 232 (str,) 233 (Pet,) 234 (float, none_type) 235 ([int, none_type],) 236 ({str: (bool, str, int, float, date, datetime, str, none_type)},) 237 :param files: key -> field name, value -> a list of open file 238 objects for `multipart/form-data`. 239 :type files: dict 240 :param _return_http_data_only: response data without head status code 241 and headers 242 :type _return_http_data_only: bool, optional 243 :param collection_formats: dict of collection formats for path, query, 244 header, and post parameters. 245 :type collection_formats: dict, optional 246 :param _preload_content: if False, the urllib3.HTTPResponse object will 247 be returned without reading/decoding response 248 data. Default is True. 249 :type _preload_content: bool, optional 250 :param _request_timeout: timeout setting for this request. If one 251 number provided, it will be total request 252 timeout. It can also be a pair (tuple) of 253 (connection, read) timeouts. 254 :param _check_type: boolean describing if the data back from the server 255 should have its type checked. 256 :type _check_type: bool, optional 257 """ 258 return await self.__call_api( 259 resource_path, 260 method, 261 path_params, 262 query_params, 263 header_params, 264 body, 265 post_params, 266 files, 267 response_type, 268 auth_settings, 269 _return_http_data_only, 270 collection_formats, 271 _preload_content, 272 _request_timeout, 273 _host, 274 _check_type, 275 ) 276 277 async def request( 278 self, 279 method, 280 url, 281 query_params=None, 282 headers=None, 283 post_params=None, 284 body=None, 285 _preload_content=True, 286 _request_timeout=None, 287 ): 288 """Makes the HTTP request using RESTClient.""" 289 if method == "GET": 290 return await self.rest_client.GET( 291 url, 292 query_params=query_params, 293 _preload_content=_preload_content, 294 _request_timeout=_request_timeout, 295 headers=headers, 296 ) 297 elif method == "HEAD": 298 return await self.rest_client.HEAD( 299 url, 300 query_params=query_params, 301 _preload_content=_preload_content, 302 _request_timeout=_request_timeout, 303 headers=headers, 304 ) 305 elif method == "OPTIONS": 306 return await self.rest_client.OPTIONS( 307 url, 308 query_params=query_params, 309 headers=headers, 310 post_params=post_params, 311 _preload_content=_preload_content, 312 _request_timeout=_request_timeout, 313 body=body, 314 ) 315 elif method == "POST": 316 return await self.rest_client.POST( 317 url, 318 query_params=query_params, 319 headers=headers, 320 post_params=post_params, 321 _preload_content=_preload_content, 322 _request_timeout=_request_timeout, 323 body=body, 324 ) 325 elif method == "PUT": 326 return await self.rest_client.PUT( 327 url, 328 query_params=query_params, 329 headers=headers, 330 post_params=post_params, 331 _preload_content=_preload_content, 332 _request_timeout=_request_timeout, 333 body=body, 334 ) 335 elif method == "PATCH": 336 return await self.rest_client.PATCH( 337 url, 338 query_params=query_params, 339 headers=headers, 340 post_params=post_params, 341 _preload_content=_preload_content, 342 _request_timeout=_request_timeout, 343 body=body, 344 ) 345 elif method == "DELETE": 346 return await self.rest_client.DELETE( 347 url, 348 query_params=query_params, 349 headers=headers, 350 _preload_content=_preload_content, 351 _request_timeout=_request_timeout, 352 body=body, 353 ) 354 else: 355 raise PineconeApiValueError( 356 "http method must be `GET`, `HEAD`, `OPTIONS`, `POST`, `PATCH`, `PUT` or `DELETE`." 357 ) 358 359 @staticmethod 360 def get_file_data_and_close_file(file_instance: io.IOBase) -> bytes: 361 file_data = file_instance.read() 362 file_instance.close() 363 return file_data
class
AsyncioApiClient:
29class AsyncioApiClient(object): 30 """Generic async API client for OpenAPI client library builds. 31 32 :param configuration: .Configuration object for this client 33 """ 34 35 def __init__(self, configuration=None, **kwargs) -> None: 36 if configuration is None: 37 configuration = Configuration.get_default_copy() 38 self.configuration = configuration 39 40 self.rest_client = AiohttpRestClient(configuration) 41 42 self.default_headers: Dict[str, str] = {} 43 # Set default User-Agent. 44 self.user_agent = "OpenAPI-Generator/1.0.0/python" 45 46 async def __aenter__(self): 47 return self 48 49 async def __aexit__(self, exc_type, exc_value, traceback): 50 await self.close() 51 52 async def close(self): 53 logger.debug("Closing the aiohttp client") 54 await self.rest_client.close() 55 56 @property 57 def user_agent(self): 58 """User agent for this API client""" 59 return self.default_headers["User-Agent"] 60 61 @user_agent.setter 62 def user_agent(self, value): 63 self.default_headers["User-Agent"] = value 64 65 def set_default_header(self, header_name, header_value): 66 self.default_headers[header_name] = header_value 67 68 async def __call_api( 69 self, 70 resource_path: str, 71 method: str, 72 path_params: Optional[Dict[str, Any]] = None, 73 query_params: Optional[List[Tuple[str, Any]]] = None, 74 header_params: Optional[Dict[str, Any]] = None, 75 body: Optional[Any] = None, 76 post_params: Optional[List[Tuple[str, Any]]] = None, 77 files: Optional[Dict[str, List[io.IOBase]]] = None, 78 response_type: Optional[Tuple[Any]] = None, 79 auth_settings: Optional[List[str]] = None, 80 _return_http_data_only: Optional[bool] = None, 81 collection_formats: Optional[Dict[str, str]] = None, 82 _preload_content: bool = True, 83 _request_timeout: Optional[Union[int, float, Tuple]] = None, 84 _host: Optional[str] = None, 85 _check_type: Optional[bool] = None, 86 ): 87 config = self.configuration 88 89 path_params = path_params or {} 90 query_params = query_params or [] 91 header_params = header_params or {} 92 post_params = post_params or [] 93 files = files or {} 94 collection_formats = collection_formats or {} 95 96 processed_header_params, processed_path_params, sanitized_path_params = process_params( 97 default_headers=self.default_headers, 98 header_params=header_params, 99 path_params=path_params, 100 collection_formats=collection_formats, 101 ) 102 103 processed_query_params = process_query_params(query_params, collection_formats) 104 105 # post parameters 106 if post_params or files: 107 post_params = post_params if post_params else [] 108 sanitized_post_params = Serializer.sanitize_for_serialization(post_params) 109 if sanitized_path_params: 110 processed_post_params = parameters_to_tuples( 111 sanitized_post_params, collection_formats 112 ) 113 processed_post_params.extend(files_parameters(files)) 114 if processed_header_params["Content-Type"].startswith("multipart"): 115 processed_post_params = parameters_to_multipart(sanitized_post_params, (dict)) 116 else: 117 processed_post_params = None 118 119 # body 120 if body: 121 body = Serializer.sanitize_for_serialization(body) 122 123 # auth setting 124 AuthUtil.update_params_for_auth( 125 configuration=self.configuration, 126 endpoint_auth_settings=auth_settings, 127 headers=processed_header_params, 128 querys=processed_query_params, 129 ) 130 131 url = build_request_url( 132 config=config, 133 processed_path_params=processed_path_params, 134 resource_path=resource_path, 135 _host=_host, 136 ) 137 138 try: 139 # perform request and return response 140 response_data = await self.request( 141 method, 142 url, 143 query_params=processed_query_params, 144 headers=processed_header_params, 145 post_params=processed_post_params, 146 body=body, 147 _preload_content=_preload_content, 148 _request_timeout=_request_timeout, 149 ) 150 except PineconeApiException as e: 151 e.body = e.body.decode("utf-8") 152 raise e 153 154 self.last_response = response_data 155 156 return_data = response_data 157 158 if not _preload_content: 159 return return_data 160 161 # deserialize response data 162 if response_type: 163 Deserializer.decode_response(response_type=response_type, response=response_data) 164 return_data = Deserializer.deserialize( 165 response_data, response_type, self.configuration, _check_type 166 ) 167 else: 168 return_data = None 169 170 if _return_http_data_only: 171 return return_data 172 else: 173 return (return_data, response_data.status, response_data.getheaders()) 174 175 def parameters_to_multipart(self, params, collection_types): 176 """Get parameters as list of tuples, formatting as json if value is collection_types 177 178 :param params: Parameters as list of two-tuples 179 :param dict collection_types: Parameter collection types 180 :return: Parameters as list of tuple or urllib3.fields.RequestField 181 """ 182 new_params = [] 183 if collection_types is None: 184 collection_types = dict 185 for k, v in params.items() if isinstance(params, dict) else params: # noqa: E501 186 if isinstance( 187 v, collection_types 188 ): # v is instance of collection_type, formatting as application/json 189 v = json.dumps(v, ensure_ascii=False).encode("utf-8") 190 field = RequestField(k, v) 191 field.make_multipart(content_type="application/json; charset=utf-8") 192 new_params.append(field) 193 else: 194 new_params.append((k, v)) 195 return new_params 196 197 async def call_api( 198 self, 199 resource_path: str, 200 method: str, 201 path_params: Optional[Dict[str, Any]] = None, 202 query_params: Optional[List[Tuple[str, Any]]] = None, 203 header_params: Optional[Dict[str, Any]] = None, 204 body: Optional[Any] = None, 205 post_params: Optional[List[Tuple[str, Any]]] = None, 206 files: Optional[Dict[str, List[io.IOBase]]] = None, 207 response_type: Optional[Tuple[Any]] = None, 208 auth_settings: Optional[List[str]] = None, 209 _return_http_data_only: Optional[bool] = None, 210 collection_formats: Optional[Dict[str, str]] = None, 211 _preload_content: bool = True, 212 _request_timeout: Optional[Union[int, float, Tuple]] = None, 213 _host: Optional[str] = None, 214 _check_type: Optional[bool] = None, 215 ): 216 """Makes the HTTP request (synchronous) and returns deserialized data. 217 218 :param resource_path: Path to method endpoint. 219 :param method: Method to call. 220 :param path_params: Path parameters in the url. 221 :param query_params: Query parameters in the url. 222 :param header_params: Header parameters to be 223 placed in the request header. 224 :param body: Request body. 225 :param post_params dict: Request post form parameters, 226 for `application/x-www-form-urlencoded`, `multipart/form-data`. 227 :param auth_settings list: Auth Settings names for the request. 228 :param response_type: For the response, a tuple containing: 229 valid classes 230 a list containing valid classes (for list schemas) 231 a dict containing a tuple of valid classes as the value 232 Example values: 233 (str,) 234 (Pet,) 235 (float, none_type) 236 ([int, none_type],) 237 ({str: (bool, str, int, float, date, datetime, str, none_type)},) 238 :param files: key -> field name, value -> a list of open file 239 objects for `multipart/form-data`. 240 :type files: dict 241 :param _return_http_data_only: response data without head status code 242 and headers 243 :type _return_http_data_only: bool, optional 244 :param collection_formats: dict of collection formats for path, query, 245 header, and post parameters. 246 :type collection_formats: dict, optional 247 :param _preload_content: if False, the urllib3.HTTPResponse object will 248 be returned without reading/decoding response 249 data. Default is True. 250 :type _preload_content: bool, optional 251 :param _request_timeout: timeout setting for this request. If one 252 number provided, it will be total request 253 timeout. It can also be a pair (tuple) of 254 (connection, read) timeouts. 255 :param _check_type: boolean describing if the data back from the server 256 should have its type checked. 257 :type _check_type: bool, optional 258 """ 259 return await self.__call_api( 260 resource_path, 261 method, 262 path_params, 263 query_params, 264 header_params, 265 body, 266 post_params, 267 files, 268 response_type, 269 auth_settings, 270 _return_http_data_only, 271 collection_formats, 272 _preload_content, 273 _request_timeout, 274 _host, 275 _check_type, 276 ) 277 278 async def request( 279 self, 280 method, 281 url, 282 query_params=None, 283 headers=None, 284 post_params=None, 285 body=None, 286 _preload_content=True, 287 _request_timeout=None, 288 ): 289 """Makes the HTTP request using RESTClient.""" 290 if method == "GET": 291 return await self.rest_client.GET( 292 url, 293 query_params=query_params, 294 _preload_content=_preload_content, 295 _request_timeout=_request_timeout, 296 headers=headers, 297 ) 298 elif method == "HEAD": 299 return await self.rest_client.HEAD( 300 url, 301 query_params=query_params, 302 _preload_content=_preload_content, 303 _request_timeout=_request_timeout, 304 headers=headers, 305 ) 306 elif method == "OPTIONS": 307 return await self.rest_client.OPTIONS( 308 url, 309 query_params=query_params, 310 headers=headers, 311 post_params=post_params, 312 _preload_content=_preload_content, 313 _request_timeout=_request_timeout, 314 body=body, 315 ) 316 elif method == "POST": 317 return await self.rest_client.POST( 318 url, 319 query_params=query_params, 320 headers=headers, 321 post_params=post_params, 322 _preload_content=_preload_content, 323 _request_timeout=_request_timeout, 324 body=body, 325 ) 326 elif method == "PUT": 327 return await self.rest_client.PUT( 328 url, 329 query_params=query_params, 330 headers=headers, 331 post_params=post_params, 332 _preload_content=_preload_content, 333 _request_timeout=_request_timeout, 334 body=body, 335 ) 336 elif method == "PATCH": 337 return await self.rest_client.PATCH( 338 url, 339 query_params=query_params, 340 headers=headers, 341 post_params=post_params, 342 _preload_content=_preload_content, 343 _request_timeout=_request_timeout, 344 body=body, 345 ) 346 elif method == "DELETE": 347 return await self.rest_client.DELETE( 348 url, 349 query_params=query_params, 350 headers=headers, 351 _preload_content=_preload_content, 352 _request_timeout=_request_timeout, 353 body=body, 354 ) 355 else: 356 raise PineconeApiValueError( 357 "http method must be `GET`, `HEAD`, `OPTIONS`, `POST`, `PATCH`, `PUT` or `DELETE`." 358 ) 359 360 @staticmethod 361 def get_file_data_and_close_file(file_instance: io.IOBase) -> bytes: 362 file_data = file_instance.read() 363 file_instance.close() 364 return file_data
Generic async API client for OpenAPI client library builds.
Parameters
- configuration: .Configuration object for this client
AsyncioApiClient(configuration=None, **kwargs)
35 def __init__(self, configuration=None, **kwargs) -> None: 36 if configuration is None: 37 configuration = Configuration.get_default_copy() 38 self.configuration = configuration 39 40 self.rest_client = AiohttpRestClient(configuration) 41 42 self.default_headers: Dict[str, str] = {} 43 # Set default User-Agent. 44 self.user_agent = "OpenAPI-Generator/1.0.0/python"
user_agent
56 @property 57 def user_agent(self): 58 """User agent for this API client""" 59 return self.default_headers["User-Agent"]
User agent for this API client
def
parameters_to_multipart(self, params, collection_types):
175 def parameters_to_multipart(self, params, collection_types): 176 """Get parameters as list of tuples, formatting as json if value is collection_types 177 178 :param params: Parameters as list of two-tuples 179 :param dict collection_types: Parameter collection types 180 :return: Parameters as list of tuple or urllib3.fields.RequestField 181 """ 182 new_params = [] 183 if collection_types is None: 184 collection_types = dict 185 for k, v in params.items() if isinstance(params, dict) else params: # noqa: E501 186 if isinstance( 187 v, collection_types 188 ): # v is instance of collection_type, formatting as application/json 189 v = json.dumps(v, ensure_ascii=False).encode("utf-8") 190 field = RequestField(k, v) 191 field.make_multipart(content_type="application/json; charset=utf-8") 192 new_params.append(field) 193 else: 194 new_params.append((k, v)) 195 return new_params
Get parameters as list of tuples, formatting as json if value is collection_types
Parameters
- params: Parameters as list of two-tuples
- dict collection_types: Parameter collection types
Returns
Parameters as list of tuple or urllib3.fields.RequestField
async 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, _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):
197 async def call_api( 198 self, 199 resource_path: str, 200 method: str, 201 path_params: Optional[Dict[str, Any]] = None, 202 query_params: Optional[List[Tuple[str, Any]]] = None, 203 header_params: Optional[Dict[str, Any]] = None, 204 body: Optional[Any] = None, 205 post_params: Optional[List[Tuple[str, Any]]] = None, 206 files: Optional[Dict[str, List[io.IOBase]]] = None, 207 response_type: Optional[Tuple[Any]] = None, 208 auth_settings: Optional[List[str]] = None, 209 _return_http_data_only: Optional[bool] = None, 210 collection_formats: Optional[Dict[str, str]] = None, 211 _preload_content: bool = True, 212 _request_timeout: Optional[Union[int, float, Tuple]] = None, 213 _host: Optional[str] = None, 214 _check_type: Optional[bool] = None, 215 ): 216 """Makes the HTTP request (synchronous) and returns deserialized data. 217 218 :param resource_path: Path to method endpoint. 219 :param method: Method to call. 220 :param path_params: Path parameters in the url. 221 :param query_params: Query parameters in the url. 222 :param header_params: Header parameters to be 223 placed in the request header. 224 :param body: Request body. 225 :param post_params dict: Request post form parameters, 226 for `application/x-www-form-urlencoded`, `multipart/form-data`. 227 :param auth_settings list: Auth Settings names for the request. 228 :param response_type: For the response, a tuple containing: 229 valid classes 230 a list containing valid classes (for list schemas) 231 a dict containing a tuple of valid classes as the value 232 Example values: 233 (str,) 234 (Pet,) 235 (float, none_type) 236 ([int, none_type],) 237 ({str: (bool, str, int, float, date, datetime, str, none_type)},) 238 :param files: key -> field name, value -> a list of open file 239 objects for `multipart/form-data`. 240 :type files: dict 241 :param _return_http_data_only: response data without head status code 242 and headers 243 :type _return_http_data_only: bool, optional 244 :param collection_formats: dict of collection formats for path, query, 245 header, and post parameters. 246 :type collection_formats: dict, optional 247 :param _preload_content: if False, the urllib3.HTTPResponse object will 248 be returned without reading/decoding response 249 data. Default is True. 250 :type _preload_content: bool, optional 251 :param _request_timeout: timeout setting for this request. If one 252 number provided, it will be total request 253 timeout. It can also be a pair (tuple) of 254 (connection, read) timeouts. 255 :param _check_type: boolean describing if the data back from the server 256 should have its type checked. 257 :type _check_type: bool, optional 258 """ 259 return await self.__call_api( 260 resource_path, 261 method, 262 path_params, 263 query_params, 264 header_params, 265 body, 266 post_params, 267 files, 268 response_type, 269 auth_settings, 270 _return_http_data_only, 271 collection_formats, 272 _preload_content, 273 _request_timeout, 274 _host, 275 _check_type, 276 )
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.
- 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
. - _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.
async def
request( self, method, url, query_params=None, headers=None, post_params=None, body=None, _preload_content=True, _request_timeout=None):
278 async def request( 279 self, 280 method, 281 url, 282 query_params=None, 283 headers=None, 284 post_params=None, 285 body=None, 286 _preload_content=True, 287 _request_timeout=None, 288 ): 289 """Makes the HTTP request using RESTClient.""" 290 if method == "GET": 291 return await self.rest_client.GET( 292 url, 293 query_params=query_params, 294 _preload_content=_preload_content, 295 _request_timeout=_request_timeout, 296 headers=headers, 297 ) 298 elif method == "HEAD": 299 return await self.rest_client.HEAD( 300 url, 301 query_params=query_params, 302 _preload_content=_preload_content, 303 _request_timeout=_request_timeout, 304 headers=headers, 305 ) 306 elif method == "OPTIONS": 307 return await self.rest_client.OPTIONS( 308 url, 309 query_params=query_params, 310 headers=headers, 311 post_params=post_params, 312 _preload_content=_preload_content, 313 _request_timeout=_request_timeout, 314 body=body, 315 ) 316 elif method == "POST": 317 return await self.rest_client.POST( 318 url, 319 query_params=query_params, 320 headers=headers, 321 post_params=post_params, 322 _preload_content=_preload_content, 323 _request_timeout=_request_timeout, 324 body=body, 325 ) 326 elif method == "PUT": 327 return await self.rest_client.PUT( 328 url, 329 query_params=query_params, 330 headers=headers, 331 post_params=post_params, 332 _preload_content=_preload_content, 333 _request_timeout=_request_timeout, 334 body=body, 335 ) 336 elif method == "PATCH": 337 return await self.rest_client.PATCH( 338 url, 339 query_params=query_params, 340 headers=headers, 341 post_params=post_params, 342 _preload_content=_preload_content, 343 _request_timeout=_request_timeout, 344 body=body, 345 ) 346 elif method == "DELETE": 347 return await self.rest_client.DELETE( 348 url, 349 query_params=query_params, 350 headers=headers, 351 _preload_content=_preload_content, 352 _request_timeout=_request_timeout, 353 body=body, 354 ) 355 else: 356 raise PineconeApiValueError( 357 "http method must be `GET`, `HEAD`, `OPTIONS`, `POST`, `PATCH`, `PUT` or `DELETE`." 358 )
Makes the HTTP request using RESTClient.