From 4006d145b0e07a11b30b5f3bc5546961e1015795 Mon Sep 17 00:00:00 2001 From: Armando Belardo <11140328+armandobelardo@users.noreply.github.com> Date: Mon, 3 Jun 2024 07:40:43 -0400 Subject: [PATCH] improvement, python: clean up endpoint functions by centralizing logic (#3761) --- .../python/core_utilities/sdk/http_client.py | 345 ++++++++++++- generators/python/sdk/CHANGELOG.md | 8 +- generators/python/sdk/VERSION | 2 +- .../external_dependencies/httpx.py | 51 +- .../endpoint_function_generator.py | 147 +----- .../flattened_request_body_parameter_utils.py | 62 --- .../inlined_request_body_parameters.py | 8 +- .../referenced_request_body_parameters.py | 16 +- .../client_wrapper_generator.py | 10 +- .../sdk/core_utilities/core_utilities.py | 18 +- .../alias/src/seed/core/client_wrapper.py | 14 +- .../alias/src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/service/client.py | 57 +-- .../audiences/src/seed/core/client_wrapper.py | 14 +- .../audiences/src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/folder_a/service/client.py | 49 +- .../audiences/src/seed/foo/client.py | 89 +--- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/service/client.py | 98 +--- .../src/seed/basic_auth/client.py | 100 +--- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../basic-auth/src/seed/basic_auth/client.py | 100 +--- .../src/seed/core/client_wrapper.py | 14 +- .../basic-auth/src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/service/client.py | 48 +- .../bytes/src/seed/core/client_wrapper.py | 14 +- .../bytes/src/seed/core/http_client.py | 345 ++++++++++++- .../bytes/src/seed/service/client.py | 58 +-- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/core/client_wrapper.py | 14 +- .../code-samples/src/seed/core/http_client.py | 345 ++++++++++++- .../code-samples/src/seed/service/client.py | 58 +-- .../src/seed/core/client_wrapper.py | 14 +- .../custom-auth/src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/custom_auth/client.py | 100 +--- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/inlined_request/client.py | 82 +-- .../src/seed/path_param/client.py | 57 +-- .../src/seed/query_param/client.py | 180 ++----- .../strenum/src/seed/core/client_wrapper.py | 14 +- .../enum/strenum/src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/inlined_request/client.py | 82 +-- .../strenum/src/seed/path_param/client.py | 57 +-- .../strenum/src/seed/query_param/client.py | 180 ++----- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/property_based_error/client.py | 46 +- .../client-filename/src/seed/base_client.py | 47 +- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../seed/file/notification/service/client.py | 49 +- .../src/seed/file/service/client.py | 49 +- .../src/seed/health/service/client.py | 89 +--- .../src/seed/service/client.py | 261 ++-------- .../no-custom-config/src/seed/client.py | 47 +- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../seed/file/notification/service/client.py | 49 +- .../src/seed/file/service/client.py | 49 +- .../src/seed/health/service/client.py | 89 +--- .../src/seed/service/client.py | 261 ++-------- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/endpoints/container/client.py | 398 +-------------- .../src/seed/endpoints/enum/client.py | 48 +- .../src/seed/endpoints/http_methods/client.py | 339 ++----------- .../src/seed/endpoints/object/client.py | 465 +++--------------- .../src/seed/endpoints/params/client.py | 291 +---------- .../src/seed/endpoints/primitive/client.py | 450 +---------------- .../src/seed/endpoints/union/client.py | 58 +-- .../src/seed/inlined_requests/client.py | 66 +-- .../src/seed/no_auth/client.py | 58 +-- .../src/seed/no_req_body/client.py | 94 +--- .../src/seed/req_with_headers/client.py | 76 +-- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/endpoints/container/client.py | 398 +-------------- .../src/seed/endpoints/enum/client.py | 48 +- .../src/seed/endpoints/http_methods/client.py | 339 ++----------- .../src/seed/endpoints/object/client.py | 465 +++--------------- .../src/seed/endpoints/params/client.py | 291 +---------- .../src/seed/endpoints/primitive/client.py | 450 +---------------- .../src/seed/endpoints/union/client.py | 58 +-- .../src/seed/inlined_requests/client.py | 66 +-- .../src/seed/no_auth/client.py | 58 +-- .../src/seed/no_req_body/client.py | 94 +--- .../src/seed/req_with_headers/client.py | 76 +-- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/endpoints/container/client.py | 398 +-------------- .../src/seed/endpoints/enum/client.py | 48 +- .../src/seed/endpoints/http_methods/client.py | 339 ++----------- .../src/seed/endpoints/object/client.py | 465 +++--------------- .../src/seed/endpoints/params/client.py | 291 +---------- .../src/seed/endpoints/primitive/client.py | 450 +---------------- .../src/seed/endpoints/union/client.py | 58 +-- .../src/seed/inlined_requests/client.py | 66 +-- .../src/seed/no_auth/client.py | 58 +-- .../src/seed/no_req_body/client.py | 94 +--- .../src/seed/req_with_headers/client.py | 76 +-- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/endpoints/container/client.py | 398 +-------------- .../src/seed/endpoints/enum/client.py | 48 +- .../src/seed/endpoints/http_methods/client.py | 339 ++----------- .../src/seed/endpoints/object/client.py | 465 +++--------------- .../src/seed/endpoints/params/client.py | 291 +---------- .../src/seed/endpoints/primitive/client.py | 450 +---------------- .../src/seed/endpoints/union/client.py | 58 +-- .../src/seed/inlined_requests/client.py | 66 +-- .../src/seed/no_auth/client.py | 58 +-- .../src/seed/no_req_body/client.py | 94 +--- .../src/seed/req_with_headers/client.py | 76 +-- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/endpoints/container/client.py | 398 +-------------- .../src/seed/endpoints/enum/client.py | 48 +- .../src/seed/endpoints/http_methods/client.py | 339 ++----------- .../src/seed/endpoints/object/client.py | 465 +++--------------- .../src/seed/endpoints/params/client.py | 291 +---------- .../src/seed/endpoints/primitive/client.py | 450 +---------------- .../src/seed/endpoints/union/client.py | 58 +-- .../src/seed/inlined_requests/client.py | 66 +-- .../src/seed/no_auth/client.py | 58 +-- .../src/seed/no_req_body/client.py | 94 +--- .../src/seed/req_with_headers/client.py | 76 +-- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/endpoints/container/client.py | 398 +-------------- .../src/seed/endpoints/enum/client.py | 48 +- .../src/seed/endpoints/http_methods/client.py | 339 ++----------- .../src/seed/endpoints/object/client.py | 465 +++--------------- .../src/seed/endpoints/params/client.py | 291 +---------- .../src/seed/endpoints/primitive/client.py | 450 +---------------- .../src/seed/endpoints/union/client.py | 58 +-- .../src/seed/inlined_requests/client.py | 66 +-- .../src/seed/no_auth/client.py | 58 +-- .../src/seed/no_req_body/client.py | 94 +--- .../src/seed/req_with_headers/client.py | 76 +-- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/endpoints/container/client.py | 398 +-------------- .../src/seed/endpoints/enum/client.py | 48 +- .../src/seed/endpoints/http_methods/client.py | 339 ++----------- .../src/seed/endpoints/object/client.py | 465 +++--------------- .../src/seed/endpoints/params/client.py | 291 +---------- .../src/seed/endpoints/primitive/client.py | 450 +---------------- .../src/seed/endpoints/union/client.py | 58 +-- .../src/seed/inlined_requests/client.py | 66 +-- .../src/seed/no_auth/client.py | 58 +-- .../src/seed/no_req_body/client.py | 94 +--- .../src/seed/req_with_headers/client.py | 76 +-- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/endpoints/container/client.py | 398 +-------------- .../src/seed/endpoints/enum/client.py | 48 +- .../src/seed/endpoints/http_methods/client.py | 339 ++----------- .../src/seed/endpoints/object/client.py | 465 +++--------------- .../src/seed/endpoints/params/client.py | 291 +---------- .../src/seed/endpoints/primitive/client.py | 450 +---------------- .../src/seed/endpoints/union/client.py | 58 +-- .../src/seed/inlined_requests/client.py | 66 +-- .../src/seed/no_auth/client.py | 58 +-- .../src/seed/no_req_body/client.py | 94 +--- .../src/seed/req_with_headers/client.py | 76 +-- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/endpoints/container/client.py | 398 +-------------- .../src/seed/endpoints/enum/client.py | 48 +- .../src/seed/endpoints/http_methods/client.py | 339 ++----------- .../src/seed/endpoints/object/client.py | 465 +++--------------- .../src/seed/endpoints/params/client.py | 291 +---------- .../src/seed/endpoints/primitive/client.py | 450 +---------------- .../src/seed/endpoints/union/client.py | 58 +-- .../src/seed/inlined_requests/client.py | 66 +-- .../src/seed/no_auth/client.py | 58 +-- .../src/seed/no_req_body/client.py | 94 +--- .../src/seed/req_with_headers/client.py | 76 +-- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/endpoints/container/client.py | 398 +-------------- .../src/seed/endpoints/enum/client.py | 48 +- .../src/seed/endpoints/http_methods/client.py | 339 ++----------- .../src/seed/endpoints/object/client.py | 465 +++--------------- .../src/seed/endpoints/params/client.py | 291 +---------- .../src/seed/endpoints/primitive/client.py | 450 +---------------- .../src/seed/endpoints/union/client.py | 58 +-- .../src/seed/inlined_requests/client.py | 66 +-- .../src/seed/no_auth/client.py | 58 +-- .../src/seed/no_req_body/client.py | 94 +--- .../src/seed/req_with_headers/client.py | 76 +-- .../src/seed/core/client_wrapper.py | 14 +- .../pydantic-v1/src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/endpoints/container/client.py | 398 +-------------- .../src/seed/endpoints/enum/client.py | 48 +- .../src/seed/endpoints/http_methods/client.py | 339 ++----------- .../src/seed/endpoints/object/client.py | 465 +++--------------- .../src/seed/endpoints/params/client.py | 291 +---------- .../src/seed/endpoints/primitive/client.py | 450 +---------------- .../src/seed/endpoints/union/client.py | 58 +-- .../src/seed/inlined_requests/client.py | 66 +-- .../pydantic-v1/src/seed/no_auth/client.py | 58 +-- .../src/seed/no_req_body/client.py | 94 +--- .../src/seed/req_with_headers/client.py | 76 +-- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/endpoints/container/client.py | 398 +-------------- .../src/seed/endpoints/enum/client.py | 48 +- .../src/seed/endpoints/http_methods/client.py | 339 ++----------- .../src/seed/endpoints/object/client.py | 465 +++--------------- .../src/seed/endpoints/params/client.py | 291 +---------- .../src/seed/endpoints/primitive/client.py | 450 +---------------- .../src/seed/endpoints/union/client.py | 58 +-- .../src/seed/inlined_requests/client.py | 66 +-- .../src/seed/no_auth/client.py | 58 +-- .../src/seed/no_req_body/client.py | 94 +--- .../src/seed/req_with_headers/client.py | 76 +-- .../src/seed/core/client_wrapper.py | 14 +- .../union-utils/src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/endpoints/container/client.py | 398 +-------------- .../src/seed/endpoints/enum/client.py | 48 +- .../src/seed/endpoints/http_methods/client.py | 339 ++----------- .../src/seed/endpoints/object/client.py | 465 +++--------------- .../src/seed/endpoints/params/client.py | 291 +---------- .../src/seed/endpoints/primitive/client.py | 450 +---------------- .../src/seed/endpoints/union/client.py | 58 +-- .../src/seed/inlined_requests/client.py | 66 +-- .../union-utils/src/seed/no_auth/client.py | 58 +-- .../src/seed/no_req_body/client.py | 94 +--- .../src/seed/req_with_headers/client.py | 76 +-- .../extends/src/seed/core/client_wrapper.py | 14 +- .../extends/src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../extra-properties/src/seed/user/client.py | 62 +-- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../file-download/src/seed/service/client.py | 53 +- .../src/seed/core/client_wrapper.py | 14 +- .../file-upload/src/seed/core/http_client.py | 345 ++++++++++++- .../file-upload/src/seed/service/client.py | 271 ++-------- .../python-sdk/folders/src/seed/a/b/client.py | 55 +-- .../python-sdk/folders/src/seed/a/c/client.py | 55 +-- seed/python-sdk/folders/src/seed/client.py | 55 +-- .../folders/src/seed/core/client_wrapper.py | 14 +- .../folders/src/seed/core/http_client.py | 345 ++++++++++++- .../folders/src/seed/folder/client.py | 55 +-- .../folders/src/seed/folder/service/client.py | 102 +--- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/payment/client.py | 125 +---- .../imdb/src/seed/core/client_wrapper.py | 14 +- .../imdb/src/seed/core/http_client.py | 345 ++++++++++++- seed/python-sdk/imdb/src/seed/imdb/client.py | 105 +--- .../literal/src/seed/core/client_wrapper.py | 14 +- .../literal/src/seed/core/http_client.py | 345 ++++++++++++- .../literal/src/seed/headers/client.py | 68 +-- .../literal/src/seed/inlined/client.py | 80 +-- .../literal/src/seed/path/client.py | 52 +- .../literal/src/seed/query/client.py | 76 +-- .../literal/src/seed/reference/client.py | 72 +-- .../src/seed/core/client_wrapper.py | 14 +- .../mixed-case/src/seed/core/http_client.py | 345 ++++++++++++- .../mixed-case/src/seed/service/client.py | 113 +---- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../multi-line-docs/src/seed/user/client.py | 105 +--- .../src/seed/core/client_wrapper.py | 8 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/ec_2/client.py | 64 +-- .../src/seed/s_3/client.py | 64 +-- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../no-environment/src/seed/dummy/client.py | 48 +- .../src/seed/auth/client.py | 70 +-- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/auth/client.py | 180 ++----- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/auth/client.py | 90 +--- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/auth/client.py | 180 ++----- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../object/src/seed/core/client_wrapper.py | 14 +- .../object/src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../optional/src/seed/core/client_wrapper.py | 14 +- .../optional/src/seed/core/http_client.py | 345 ++++++++++++- .../optional/src/seed/optional/client.py | 62 +-- .../python-sdk/package-yml/src/seed/client.py | 47 +- .../src/seed/core/client_wrapper.py | 14 +- .../package-yml/src/seed/core/http_client.py | 345 ++++++++++++- .../package-yml/src/seed/service/client.py | 49 +- .../src/seed/core/client_wrapper.py | 14 +- .../pagination/src/seed/core/http_client.py | 345 ++++++++++++- .../pagination/src/seed/users/client.py | 327 +----------- .../src/seed/core/client_wrapper.py | 14 +- .../plain-text/src/seed/core/http_client.py | 345 ++++++++++++- .../plain-text/src/seed/service/client.py | 54 +- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../query-parameters/src/seed/user/client.py | 117 ++--- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/package/client.py | 69 +-- .../src/seed/completions/client.py | 58 +-- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/dummy/client.py | 48 +- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/dummy/client.py | 48 +- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../no-custom-config/src/seed/dummy/client.py | 62 +-- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/dummy/client.py | 62 +-- .../src/seed/core/client_wrapper.py | 14 +- .../src/seed/core/http_client.py | 345 ++++++++++++- .../src/seed/union/client.py | 57 +-- .../unions/src/seed/core/client_wrapper.py | 14 +- .../unions/src/seed/core/http_client.py | 345 ++++++++++++- .../unions/src/seed/union/client.py | 99 +--- .../unknown/src/seed/core/client_wrapper.py | 14 +- .../unknown/src/seed/core/http_client.py | 345 ++++++++++++- .../unknown/src/seed/unknown/client.py | 57 +-- seed/python-sdk/validation/src/seed/client.py | 130 +---- .../src/seed/core/client_wrapper.py | 14 +- .../validation/src/seed/core/http_client.py | 345 ++++++++++++- .../variables/src/seed/core/client_wrapper.py | 14 +- .../variables/src/seed/core/http_client.py | 345 ++++++++++++- .../variables/src/seed/service/client.py | 51 +- .../websocket/src/seed/core/client_wrapper.py | 14 +- .../websocket/src/seed/core/http_client.py | 345 ++++++++++++- 351 files changed, 25782 insertions(+), 34701 deletions(-) diff --git a/generators/python/core_utilities/sdk/http_client.py b/generators/python/core_utilities/sdk/http_client.py index 680f5ca00d8..6270208873c 100644 --- a/generators/python/core_utilities/sdk/http_client.py +++ b/generators/python/core_utilities/sdk/http_client.py @@ -3,12 +3,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -80,49 +86,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/generators/python/sdk/CHANGELOG.md b/generators/python/sdk/CHANGELOG.md index f62136d85de..6786eb30ad1 100644 --- a/generators/python/sdk/CHANGELOG.md +++ b/generators/python/sdk/CHANGELOG.md @@ -5,11 +5,15 @@ All notable changes to this project will be documented in this file. The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/), and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html). +## [2.8.0] - 2024-06-03 + +- Improvement: Endpoint function request logic has been abstracted into the request function of the wrapped httpx client. + ## [2.7.0] - 2024-05-30 - Improvement: The generator now outputs an `exampleId` alongside each generated snippet so that - we can correlate snippets with the relevant examples. This is useful for retrieving examples from - Fern's API and making sure that you can show multiple snippets in the generated docs. + we can correlate snippets with the relevant examples. This is useful for retrieving examples from + Fern's API and making sure that you can show multiple snippets in the generated docs. ## [2.6.1] - 2024-05-31 diff --git a/generators/python/sdk/VERSION b/generators/python/sdk/VERSION index 24ba9a38de6..834f2629538 100644 --- a/generators/python/sdk/VERSION +++ b/generators/python/sdk/VERSION @@ -1 +1 @@ -2.7.0 +2.8.0 diff --git a/generators/python/src/fern_python/external_dependencies/httpx.py b/generators/python/src/fern_python/external_dependencies/httpx.py index 3965140fd60..6bc8cfdac72 100644 --- a/generators/python/src/fern_python/external_dependencies/httpx.py +++ b/generators/python/src/fern_python/external_dependencies/httpx.py @@ -34,21 +34,21 @@ class HttpX: @staticmethod def make_request( *, - url: AST.Expression, + path: Optional[AST.Expression], + url: Optional[AST.Expression], method: str, query_parameters: Optional[AST.Expression], request_body: Optional[AST.Expression], headers: Optional[AST.Expression], files: Optional[AST.Expression], content: Optional[AST.Expression], - auth: Optional[AST.Expression], - timeout: AST.Expression, response_variable_name: str, + request_options_variable_name: str, is_async: bool, is_streaming: bool, response_code_writer: AST.CodeWriter, reference_to_client: AST.Expression, - max_retries: AST.Expression, + is_default_body_parameter_used: bool, ) -> AST.Expression: def add_request_params(*, writer: AST.NodeWriter) -> None: if query_parameters is not None: @@ -76,21 +76,10 @@ def add_request_params(*, writer: AST.NodeWriter) -> None: writer.write_node(headers) writer.write_line(",") - if auth is not None: - writer.write("auth=") - writer.write_node(auth) - writer.write_line(",") - - writer.write("timeout=") - writer.write_node(timeout) - writer.write_line(",") - - writer.write("retries=0") - writer.write_line(",") + writer.write(f"request_options={request_options_variable_name},") - writer.write("max_retries=") - writer.write_node(max_retries) - writer.write_line(", # type: ignore") + if is_default_body_parameter_used: + writer.write_line("omit=OMIT,") def write_non_streaming_call( *, @@ -107,10 +96,17 @@ def make_non_streaming_request( if is_async: writer.write("await ") writer.write_node(reference_to_client) - writer.write(f'.request(method="{method}", url=') - writer.write_node(url) - writer.write(", ") + writer.write_line(f".request(") + with writer.indent(): + if path is not None: + writer.write_node(path) + writer.write(",") + if url is not None: + writer.write("base_url=") + writer.write_node(url) + writer.write(",") + writer.write_line(f'method="{method}",') add_request_params(writer=writer) writer.write_line(")") @@ -119,10 +115,17 @@ def write_streaming_call(*, writer: AST.NodeWriter) -> None: writer.write("async ") writer.write("with ") writer.write_node(reference_to_client) - writer.write(f'.stream(method="{method}", url=') - writer.write_node(url) - writer.write(", ") + writer.write(f".stream(") + with writer.indent(): + if path is not None: + writer.write_node(path) + writer.write(",") + if url is not None: + writer.write("base_url=") + writer.write_node(url) + writer.write(",") + writer.write_line(f'method="{method}",') add_request_params(writer=writer) writer.write_line(f") as {response_variable_name}:") diff --git a/generators/python/src/fern_python/generators/sdk/client_generator/endpoint_function_generator.py b/generators/python/src/fern_python/generators/sdk/client_generator/endpoint_function_generator.py index 908addd398b..dd44cd90804 100644 --- a/generators/python/src/fern_python/generators/sdk/client_generator/endpoint_function_generator.py +++ b/generators/python/src/fern_python/generators/sdk/client_generator/endpoint_function_generator.py @@ -6,7 +6,7 @@ from fern_python.codegen import AST from fern_python.codegen.ast.ast_node.node_writer import NodeWriter -from fern_python.external_dependencies import HttpX, UrlLibParse +from fern_python.external_dependencies import HttpX from fern_python.generators.sdk.client_generator.endpoint_response_code_writer import ( EndpointDummySnippetConfig, EndpointResponseCodeWriter, @@ -129,20 +129,9 @@ def __init__( _named_parameter_names.append(name) self._path_parameter_names[path_parameter.name] = name - def generate(self) -> GeneratedEndpointFunction: - is_primitive: bool = ( - self._endpoint.request_body.visit( - inlined_request_body=lambda _: False, - reference=lambda referenced_request_body: self._is_httpx_primitive_data( - type_reference=referenced_request_body.request_body_type, allow_optional=True - ), - file_upload=lambda _: False, - bytes=lambda _: False, - ) - if self._endpoint.request_body is not None - else False - ) + self.is_default_body_parameter_used = self.request_body_parameters is not None + def generate(self) -> GeneratedEndpointFunction: endpoint_snippets = self._generate_endpoint_snippets( package=self._package, service=self._service, @@ -174,7 +163,6 @@ def generate(self) -> GeneratedEndpointFunction: idempotency_headers=self._idempotency_headers, request_body_parameters=self.request_body_parameters, is_async=self._is_async, - is_primitive=is_primitive, parameters=unnamed_parameters, named_parameters=self._named_parameters, ), @@ -311,7 +299,6 @@ def _create_endpoint_body_writer( idempotency_headers: List[ir_types.HttpHeader], request_body_parameters: Optional[AbstractRequestBodyParameters], is_async: bool, - is_primitive: bool, named_parameters: List[AST.NamedFunctionParameter], parameters: List[AST.FunctionParameter], ) -> AST.CodeWriter: @@ -325,11 +312,6 @@ def write(writer: AST.NodeWriter) -> None: writer.write_node(AST.Expression(request_pre_fetch_statements)) json_request_body = request_body_parameters.get_json_body() if request_body_parameters is not None else None - encoded_json_request_body = ( - self._context.core_utilities.jsonable_encoder(json_request_body) - if json_request_body is not None - else None - ) method = endpoint.method.visit( get=lambda: "GET", @@ -340,38 +322,8 @@ def write(writer: AST.NodeWriter) -> None: ) def write_request_body(writer: AST.NodeWriter) -> None: - if is_primitive: - if encoded_json_request_body: - writer.write_node(encoded_json_request_body) - else: - # If there's an existing request body: - # - Use it if the additional body params are none (e.g. request options has no impact) - # - If additional body params is not none, json encode it and spread both dicts into a new one - # - NOTE: With the is_primitive bail out, we do not acknowledge the additional body parameters, - # to not have to merge together an integer and a hash, for example - # If there is not an existing request body, send the encoded dict - additional_parameters = ( - f"{EndpointFunctionGenerator.REQUEST_OPTIONS_VARIABLE}.get('additional_body_parameters')" - ) - additional_parameters_defaulted = f"{EndpointFunctionGenerator.REQUEST_OPTIONS_VARIABLE}.get('additional_body_parameters', {'{}'})" - json_encoded_additional_params = self._context.core_utilities.jsonable_encoder( - self._context.core_utilities.remove_none_from_dict( - AST.Expression(additional_parameters_defaulted) - ) - ) - if encoded_json_request_body: - writer.write_node(encoded_json_request_body) - writer.write( - f" if {EndpointFunctionGenerator.REQUEST_OPTIONS_VARIABLE} is None or {additional_parameters} is None else" - ) - writer.write(" {**") - writer.write_node(encoded_json_request_body) - writer.write(", **(") - writer.write_node(json_encoded_additional_params) - writer.write(")}") - else: - writer.write_node(json_encoded_additional_params) - writer.write(f" if {EndpointFunctionGenerator.REQUEST_OPTIONS_VARIABLE} is not None else None") + if json_request_body is not None: + writer.write_node(json_request_body) is_streaming = ( True @@ -394,9 +346,6 @@ def write_request_body(writer: AST.NodeWriter) -> None: ), ) - timeout = AST.Expression( - f"{EndpointFunctionGenerator.REQUEST_OPTIONS_VARIABLE}.get('timeout_in_seconds') if {EndpointFunctionGenerator.REQUEST_OPTIONS_VARIABLE} is not None and {EndpointFunctionGenerator.REQUEST_OPTIONS_VARIABLE}.get('timeout_in_seconds') is not None else self.{self._client_wrapper_member_name}.{ClientWrapperGenerator.GET_TIMEOUT_METHOD_NAME}()" - ) files = ( request_body_parameters.get_files() if request_body_parameters is not None and request_body_parameters.get_files() is not None @@ -406,32 +355,27 @@ def write_request_body(writer: AST.NodeWriter) -> None: HttpX.make_request( is_streaming=is_streaming, is_async=is_async, - url=( - self._get_environment_as_str(endpoint=endpoint) - if is_endpoint_path_empty(endpoint) - else UrlLibParse.urljoin( - self._get_environment_as_str(endpoint=endpoint), - self._get_path_for_endpoint(endpoint), - ) - ), + path=self._get_path_for_endpoint(endpoint=endpoint) + if not is_endpoint_path_empty(endpoint) + else None, + url=self._get_environment_as_str(endpoint=endpoint), method=method, query_parameters=self._get_query_parameters_for_endpoint(endpoint=endpoint), - request_body=AST.Expression(AST.CodeWriter(write_request_body)) if (method != "GET") else None, + request_body=AST.Expression(AST.CodeWriter(write_request_body)) + if (method != "GET") and json_request_body is not None + else None, content=request_body_parameters.get_content() if request_body_parameters is not None else None, files=self._context.core_utilities.httpx_tuple_converter(files) if files is not None else None, response_variable_name=EndpointResponseCodeWriter.RESPONSE_VARIABLE, + request_options_variable_name=EndpointFunctionGenerator.REQUEST_OPTIONS_VARIABLE, headers=self._get_headers_for_endpoint( service=service, endpoint=endpoint, idempotency_headers=idempotency_headers ), - auth=None, - timeout=timeout, response_code_writer=response_code_writer.get_writer(), reference_to_client=AST.Expression( f"self.{self._client_wrapper_member_name}.{ClientWrapperGenerator.HTTPX_CLIENT_MEMBER_NAME}" ), - max_retries=AST.Expression( - f"{EndpointFunctionGenerator.REQUEST_OPTIONS_VARIABLE}.get('max_retries') if {EndpointFunctionGenerator.REQUEST_OPTIONS_VARIABLE} is not None else 0" - ), + is_default_body_parameter_used=self.is_default_body_parameter_used, ) ) @@ -832,7 +776,9 @@ def write_ternary(writer: AST.NodeWriter) -> None: return reference - def _get_environment_as_str(self, *, endpoint: ir_types.HttpEndpoint) -> AST.Expression: + # Only get the environment expression if the environment is multipleBaseUrls, if it's + # not we'll leverage the URL from the client wrapper + def _get_environment_as_str(self, *, endpoint: ir_types.HttpEndpoint) -> Optional[AST.Expression]: if self._context.ir.environments is not None: environments_as_union = self._context.ir.environments.environments.get_as_union() if environments_as_union.type == "multipleBaseUrls": @@ -845,9 +791,7 @@ def _get_environment_as_str(self, *, endpoint: ir_types.HttpEndpoint) -> AST.Exp return AST.Expression( f"self.{self._client_wrapper_member_name}.{ClientWrapperGenerator.GET_ENVIRONMENT_METHOD_NAME}().{url_reference}" ) - return AST.Expression( - f"self.{self._client_wrapper_member_name}.{ClientWrapperGenerator.GET_BASE_URL_METHOD_NAME}()" - ) + return None def _get_headers_for_endpoint( self, @@ -878,42 +822,18 @@ def _get_headers_for_endpoint( ) ) - def write_headers_dict_default(writer: AST.NodeWriter) -> None: - writer.write("{") - writer.write( - f"**self.{self._client_wrapper_member_name}.{ClientWrapperGenerator.GET_HEADERS_METHOD_NAME}()," - ) - writer.write( - f"**({EndpointFunctionGenerator.REQUEST_OPTIONS_VARIABLE}.get('additional_headers', {'{}'}) if {EndpointFunctionGenerator.REQUEST_OPTIONS_VARIABLE} is not None else {'{}'})," - ) - writer.write_line("}") - if len(headers) == 0: - self._context.core_utilities.jsonable_encoder( - self._context.core_utilities.remove_none_from_dict( - AST.Expression(AST.CodeWriter(write_headers_dict_default)), - ) - ) + return None def write_headers_dict(writer: AST.NodeWriter) -> None: writer.write("{") - writer.write( - f"**self.{self._client_wrapper_member_name}.{ClientWrapperGenerator.GET_HEADERS_METHOD_NAME}()," - ) - for i, (header_key, header_value) in enumerate(headers): + for _, (header_key, header_value) in enumerate(headers): writer.write(f'"{header_key}": ') writer.write_node(header_value) writer.write(", ") - writer.write( - f"**({EndpointFunctionGenerator.REQUEST_OPTIONS_VARIABLE}.get('additional_headers', {'{}'}) if {EndpointFunctionGenerator.REQUEST_OPTIONS_VARIABLE} is not None else {'{}'})," - ) - writer.write_line("},") + writer.write_line("}") - return self._context.core_utilities.jsonable_encoder( - self._context.core_utilities.remove_none_from_dict( - AST.Expression(AST.CodeWriter(write_headers_dict)), - ) - ) + return AST.Expression(AST.CodeWriter(write_headers_dict)) def _get_query_parameter_reference(self, query_parameter: ir_types.QueryParameter) -> AST.Expression: possible_query_literal = self._context.get_literal_value(query_parameter.value_type) @@ -934,32 +854,17 @@ def _get_query_parameters_for_endpoint( ] if len(query_parameters) == 0: - return self._context.core_utilities.get_encode_query( - self._context.core_utilities.jsonable_encoder( - AST.Expression( - f"{EndpointFunctionGenerator.REQUEST_OPTIONS_VARIABLE}.get('additional_query_parameters') if {EndpointFunctionGenerator.REQUEST_OPTIONS_VARIABLE} is not None else None" - ) - ) - ) + return None def write_query_parameters_dict(writer: AST.NodeWriter) -> None: writer.write("{") - for i, (query_param_key, query_param_value) in enumerate(query_parameters): + for _, (query_param_key, query_param_value) in enumerate(query_parameters): writer.write(f'"{query_param_key}": ') writer.write_node(query_param_value) writer.write(", ") - writer.write( - f"**({EndpointFunctionGenerator.REQUEST_OPTIONS_VARIABLE}.get('additional_query_parameters', {'{}'}) if {EndpointFunctionGenerator.REQUEST_OPTIONS_VARIABLE} is not None else {'{}'})," - ) - writer.write_line("},") + writer.write_line("}") - return self._context.core_utilities.get_encode_query( - self._context.core_utilities.jsonable_encoder( - self._context.core_utilities.remove_none_from_dict( - AST.Expression(AST.CodeWriter(write_query_parameters_dict)), - ) - ) - ) + return AST.Expression(AST.CodeWriter(write_query_parameters_dict)) def _is_datetime( self, diff --git a/generators/python/src/fern_python/generators/sdk/client_generator/request_body_parameters/flattened_request_body_parameter_utils.py b/generators/python/src/fern_python/generators/sdk/client_generator/request_body_parameters/flattened_request_body_parameter_utils.py index 19b458dbdaf..7b55c3cac6b 100644 --- a/generators/python/src/fern_python/generators/sdk/client_generator/request_body_parameters/flattened_request_body_parameter_utils.py +++ b/generators/python/src/fern_python/generators/sdk/client_generator/request_body_parameters/flattened_request_body_parameter_utils.py @@ -5,7 +5,6 @@ from fern_python.codegen import AST from ...context.sdk_generator_context import SdkGeneratorContext -from ..constants import DEFAULT_BODY_PARAMETER_VALUE _REQUEST_VARIABLE_NAME = "_request" @@ -17,11 +16,7 @@ def _get_property_name(property: ir_types.InlinedRequestBodyProperty) -> str: def get_json_body_for_inlined_request( context: SdkGeneratorContext, properties: List[AST.NamedFunctionParameter], - are_any_properties_optional: bool, ) -> Optional[AST.Expression]: - if are_any_properties_optional: - return AST.Expression(_REQUEST_VARIABLE_NAME) - def write(writer: AST.NodeWriter) -> None: writer.write_line("{") with writer.indent(): @@ -41,63 +36,6 @@ def write(writer: AST.NodeWriter) -> None: return AST.Expression(AST.CodeWriter(write)) -def get_pre_fetch_statements_for_inlined_request( - context: SdkGeneratorContext, - properties: List[AST.NamedFunctionParameter], - are_any_properties_optional: bool, -) -> Optional[AST.CodeWriter]: - if not are_any_properties_optional: - return None - - optional_properties: List[AST.NamedFunctionParameter] = [] - required_properties: List[AST.NamedFunctionParameter] = [] - for body_property in properties: - type_hint = ( - context.pydantic_generator_context.get_type_hint_for_type_reference( - body_property.raw_type, - in_endpoint=True, - ) - if body_property.raw_type - else None - ) - if type_hint is not None and type_hint.is_optional: - optional_properties.append(body_property) - else: - required_properties.append(body_property) - - def write(writer: AST.NodeWriter) -> None: - writer.write(f"{_REQUEST_VARIABLE_NAME}: ") - writer.write_node(AST.TypeHint.dict(AST.TypeHint.str_(), AST.TypeHint.any())) - writer.write(" = ") - if len(required_properties) == 0: - writer.write_line("{}") - else: - writer.write_line("{") - with writer.indent(): - for required_property in required_properties: - literal_value = ( - context.get_literal_value(reference=required_property.raw_type) - if required_property.raw_type is not None - else None - ) - if literal_value is not None and type(literal_value) is str: - writer.write_line(f'"{required_property.raw_name}": "{literal_value}",') - elif literal_value is not None and type(literal_value) is bool: - writer.write_line(f'"{required_property.raw_name}": {literal_value},') - else: - writer.write_line(f'"{required_property.raw_name}": {required_property.name},') - writer.write_line("}") - - for optional_property in optional_properties: - writer.write_line(f"if {optional_property.name} is not {DEFAULT_BODY_PARAMETER_VALUE}:") - with writer.indent(): - writer.write_line( - f'{_REQUEST_VARIABLE_NAME}["{optional_property.raw_name}"] = {optional_property.name}' - ) - - return AST.CodeWriter(write) - - def are_any_properties_optional_in_inlined_request( context: SdkGeneratorContext, properties: List[ir_types.InlinedRequestBodyProperty] ) -> bool: diff --git a/generators/python/src/fern_python/generators/sdk/client_generator/request_body_parameters/inlined_request_body_parameters.py b/generators/python/src/fern_python/generators/sdk/client_generator/request_body_parameters/inlined_request_body_parameters.py index 4bdce5dd664..1676573dc57 100644 --- a/generators/python/src/fern_python/generators/sdk/client_generator/request_body_parameters/inlined_request_body_parameters.py +++ b/generators/python/src/fern_python/generators/sdk/client_generator/request_body_parameters/inlined_request_body_parameters.py @@ -13,7 +13,6 @@ from .flattened_request_body_parameter_utils import ( are_any_properties_optional_in_inlined_request, get_json_body_for_inlined_request, - get_pre_fetch_statements_for_inlined_request, ) @@ -112,16 +111,15 @@ def _get_property_name(self, property: ir_types.InlinedRequestBodyProperty) -> s def get_json_body(self, names_to_deconflict: Optional[List[str]] = None) -> Optional[AST.Expression]: return get_json_body_for_inlined_request( - self._context, self._get_properties(), self._are_any_properties_optional + self._context, + self._get_properties(), ) def get_files(self) -> Optional[AST.Expression]: return None def get_pre_fetch_statements(self, names_to_deconflict: Optional[List[str]] = None) -> Optional[AST.CodeWriter]: - return get_pre_fetch_statements_for_inlined_request( - self._context, self._get_properties(), self._are_any_properties_optional - ) + return None def is_default_body_parameter_used(self) -> bool: return self._are_any_properties_optional diff --git a/generators/python/src/fern_python/generators/sdk/client_generator/request_body_parameters/referenced_request_body_parameters.py b/generators/python/src/fern_python/generators/sdk/client_generator/request_body_parameters/referenced_request_body_parameters.py index 4939b7e2f2c..8000cc1d0c6 100644 --- a/generators/python/src/fern_python/generators/sdk/client_generator/request_body_parameters/referenced_request_body_parameters.py +++ b/generators/python/src/fern_python/generators/sdk/client_generator/request_body_parameters/referenced_request_body_parameters.py @@ -10,10 +10,7 @@ from ...context.sdk_generator_context import SdkGeneratorContext from ..constants import DEFAULT_BODY_PARAMETER_VALUE from .abstract_request_body_parameters import AbstractRequestBodyParameters -from .flattened_request_body_parameter_utils import ( - get_json_body_for_inlined_request, - get_pre_fetch_statements_for_inlined_request, -) +from .flattened_request_body_parameter_utils import get_json_body_for_inlined_request class ReferencedRequestBodyParameters(AbstractRequestBodyParameters): @@ -163,7 +160,6 @@ def get_json_body(self, names_to_deconflict: Optional[List[str]] = None) -> Opti else get_json_body_for_inlined_request( self._context, self._get_properties(names_to_deconflict), - self._are_any_properties_optional, ) ) @@ -176,15 +172,7 @@ def get_files(self) -> Optional[AST.Expression]: return None def get_pre_fetch_statements(self, names_to_deconflict: Optional[List[str]] = None) -> Optional[AST.CodeWriter]: - return ( - None - if not self.should_inline_request_parameters - else get_pre_fetch_statements_for_inlined_request( - self._context, - self._get_properties(names_to_deconflict), - self._are_any_properties_optional, - ) - ) + return None def is_default_body_parameter_used(self) -> bool: return self._are_any_properties_optional diff --git a/generators/python/src/fern_python/generators/sdk/core_utilities/client_wrapper_generator.py b/generators/python/src/fern_python/generators/sdk/core_utilities/client_wrapper_generator.py index 60cca1aba1d..b1bc0bcb506 100644 --- a/generators/python/src/fern_python/generators/sdk/core_utilities/client_wrapper_generator.py +++ b/generators/python/src/fern_python/generators/sdk/core_utilities/client_wrapper_generator.py @@ -261,6 +261,8 @@ def _create_async_client_wrapper_class_declaration( def _get_write_derived_client_wrapper_constructor_body( self, *, constructor_parameters: List[ConstructorParameter], is_async: bool ) -> CodeWriterFunction: + has_base_url = get_client_wrapper_url_type(ir=self._context.ir) == ClientWrapperUrlStorage.URL + def _write_derived_client_wrapper_constructor_body(writer: AST.NodeWriter) -> None: writer.write_line( "super().__init__(" @@ -275,7 +277,13 @@ def _write_derived_client_wrapper_constructor_body(writer: AST.NodeWriter) -> No writer.write(f"self.{ClientWrapperGenerator.HTTPX_CLIENT_MEMBER_NAME} = ") writer.write_node( self._context.core_utilities.http_client( - obj=AST.Expression(ClientWrapperGenerator.HTTPX_CLIENT_MEMBER_NAME), is_async=is_async + base_client=AST.Expression(ClientWrapperGenerator.HTTPX_CLIENT_MEMBER_NAME), + base_url=AST.Expression(f"self.{ClientWrapperGenerator.GET_BASE_URL_METHOD_NAME}()") + if has_base_url + else None, + base_headers=AST.Expression(f"self.{ClientWrapperGenerator.GET_HEADERS_METHOD_NAME}()"), + base_timeout=AST.Expression(f"self.{ClientWrapperGenerator.GET_TIMEOUT_METHOD_NAME}()"), + is_async=is_async, ) ) diff --git a/generators/python/src/fern_python/generators/sdk/core_utilities/core_utilities.py b/generators/python/src/fern_python/generators/sdk/core_utilities/core_utilities.py index 223c2715405..05145b9be2d 100644 --- a/generators/python/src/fern_python/generators/sdk/core_utilities/core_utilities.py +++ b/generators/python/src/fern_python/generators/sdk/core_utilities/core_utilities.py @@ -301,7 +301,21 @@ def httpx_tuple_converter(self, obj: AST.Expression) -> AST.Expression: ) ) - def http_client(self, obj: AST.Expression, is_async: bool) -> AST.Expression: + def http_client( + self, + base_client: AST.Expression, + base_url: Optional[AST.Expression], + base_headers: AST.Expression, + base_timeout: AST.Expression, + is_async: bool, + ) -> AST.Expression: + func_args = [ + ("httpx_client", base_client), + ("base_headers", base_headers), + ("base_timeout", base_timeout), + ] + if base_url is not None: + func_args.append(("base_url", base_url)) return AST.Expression( AST.FunctionInvocation( function_definition=AST.Reference( @@ -311,7 +325,7 @@ def http_client(self, obj: AST.Expression, is_async: bool) -> AST.Expression: named_import="HttpClient" if not is_async else "AsyncHttpClient", ), ), - kwargs=[("httpx_client", obj)], + kwargs=func_args, ) ) diff --git a/seed/python-sdk/alias/src/seed/core/client_wrapper.py b/seed/python-sdk/alias/src/seed/core/client_wrapper.py index 3fa27825967..808252942db 100644 --- a/seed/python-sdk/alias/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/alias/src/seed/core/client_wrapper.py @@ -30,10 +30,20 @@ def get_timeout(self) -> typing.Optional[float]: class SyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/alias/src/seed/core/http_client.py b/seed/python-sdk/alias/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/alias/src/seed/core/http_client.py +++ b/seed/python-sdk/alias/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/api-wide-base-path/src/seed/core/client_wrapper.py b/seed/python-sdk/api-wide-base-path/src/seed/core/client_wrapper.py index 6f7673fde40..31a8c614467 100644 --- a/seed/python-sdk/api-wide-base-path/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/api-wide-base-path/src/seed/core/client_wrapper.py @@ -30,10 +30,20 @@ def get_timeout(self) -> typing.Optional[float]: class SyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/api-wide-base-path/src/seed/core/http_client.py b/seed/python-sdk/api-wide-base-path/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/api-wide-base-path/src/seed/core/http_client.py +++ b/seed/python-sdk/api-wide-base-path/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/api-wide-base-path/src/seed/service/client.py b/seed/python-sdk/api-wide-base-path/src/seed/service/client.py index d72f3ec8c94..3f29ef6c00c 100644 --- a/seed/python-sdk/api-wide-base-path/src/seed/service/client.py +++ b/seed/python-sdk/api-wide-base-path/src/seed/service/client.py @@ -1,14 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ..core.jsonable_encoder import jsonable_encoder -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions @@ -58,32 +55,9 @@ def post( ) """ _response = self._client_wrapper.httpx_client.request( + f"test/{jsonable_encoder(path_param)}/{jsonable_encoder(service_param)}/{jsonable_encoder(endpoint_param)}/{jsonable_encoder(resource_param)}", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", - f"test/{jsonable_encoder(path_param)}/{jsonable_encoder(service_param)}/{jsonable_encoder(endpoint_param)}/{jsonable_encoder(resource_param)}", - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -140,32 +114,9 @@ async def post( ) """ _response = await self._client_wrapper.httpx_client.request( + f"test/{jsonable_encoder(path_param)}/{jsonable_encoder(service_param)}/{jsonable_encoder(endpoint_param)}/{jsonable_encoder(resource_param)}", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", - f"test/{jsonable_encoder(path_param)}/{jsonable_encoder(service_param)}/{jsonable_encoder(endpoint_param)}/{jsonable_encoder(resource_param)}", - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, ) if 200 <= _response.status_code < 300: return diff --git a/seed/python-sdk/audiences/src/seed/core/client_wrapper.py b/seed/python-sdk/audiences/src/seed/core/client_wrapper.py index f12f487b7bc..1bc956666ce 100644 --- a/seed/python-sdk/audiences/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/audiences/src/seed/core/client_wrapper.py @@ -30,10 +30,20 @@ def get_timeout(self) -> typing.Optional[float]: class SyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/audiences/src/seed/core/http_client.py b/seed/python-sdk/audiences/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/audiences/src/seed/core/http_client.py +++ b/seed/python-sdk/audiences/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/audiences/src/seed/folder_a/service/client.py b/seed/python-sdk/audiences/src/seed/folder_a/service/client.py index a0465ab0be7..31dca44e5fe 100644 --- a/seed/python-sdk/audiences/src/seed/folder_a/service/client.py +++ b/seed/python-sdk/audiences/src/seed/folder_a/service/client.py @@ -5,10 +5,7 @@ from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from .types.response import Response @@ -37,28 +34,7 @@ def get_direct_thread(self, *, request_options: typing.Optional[RequestOptions] ) client.folder_a.service.get_direct_thread() """ - _response = self._client_wrapper.httpx_client.request( - method="GET", - url=self._client_wrapper.get_base_url(), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore - ) + _response = self._client_wrapper.httpx_client.request(method="GET", request_options=request_options) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Response, _response.json()) # type: ignore try: @@ -92,28 +68,7 @@ async def get_direct_thread(self, *, request_options: typing.Optional[RequestOpt ) await client.folder_a.service.get_direct_thread() """ - _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=self._client_wrapper.get_base_url(), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore - ) + _response = await self._client_wrapper.httpx_client.request(method="GET", request_options=request_options) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Response, _response.json()) # type: ignore try: diff --git a/seed/python-sdk/audiences/src/seed/foo/client.py b/seed/python-sdk/audiences/src/seed/foo/client.py index 6ee507fa00e..f938a61f90c 100644 --- a/seed/python-sdk/audiences/src/seed/foo/client.py +++ b/seed/python-sdk/audiences/src/seed/foo/client.py @@ -5,10 +5,7 @@ from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from .types.importing_type import ImportingType from .types.optional_string import OptionalString @@ -58,47 +55,12 @@ def find( private_property=1, ) """ - _request: typing.Dict[str, typing.Any] = {} - if public_property is not OMIT: - _request["publicProperty"] = public_property - if private_property is not OMIT: - _request["privateProperty"] = private_property _response = self._client_wrapper.httpx_client.request( method="POST", - url=self._client_wrapper.get_base_url(), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "optionalString": optional_string, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"optionalString": optional_string}, + json={"publicProperty": public_property, "privateProperty": private_property}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ImportingType, _response.json()) # type: ignore @@ -150,47 +112,12 @@ async def find( private_property=1, ) """ - _request: typing.Dict[str, typing.Any] = {} - if public_property is not OMIT: - _request["publicProperty"] = public_property - if private_property is not OMIT: - _request["privateProperty"] = private_property _response = await self._client_wrapper.httpx_client.request( method="POST", - url=self._client_wrapper.get_base_url(), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "optionalString": optional_string, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"optionalString": optional_string}, + json={"publicProperty": public_property, "privateProperty": private_property}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ImportingType, _response.json()) # type: ignore diff --git a/seed/python-sdk/auth-environment-variables/src/seed/core/client_wrapper.py b/seed/python-sdk/auth-environment-variables/src/seed/core/client_wrapper.py index 6d6d3bff9f1..d06badb6789 100644 --- a/seed/python-sdk/auth-environment-variables/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/auth-environment-variables/src/seed/core/client_wrapper.py @@ -42,7 +42,12 @@ def __init__( httpx_client: httpx.Client ): super().__init__(x_another_header=x_another_header, api_key=api_key, base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): @@ -56,4 +61,9 @@ def __init__( httpx_client: httpx.AsyncClient ): super().__init__(x_another_header=x_another_header, api_key=api_key, base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/auth-environment-variables/src/seed/core/http_client.py b/seed/python-sdk/auth-environment-variables/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/auth-environment-variables/src/seed/core/http_client.py +++ b/seed/python-sdk/auth-environment-variables/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/auth-environment-variables/src/seed/service/client.py b/seed/python-sdk/auth-environment-variables/src/seed/service/client.py index 2540cb59daf..db405edf4a2 100644 --- a/seed/python-sdk/auth-environment-variables/src/seed/service/client.py +++ b/seed/python-sdk/auth-environment-variables/src/seed/service/client.py @@ -2,15 +2,11 @@ import os import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions @@ -42,28 +38,7 @@ def get_with_api_key(self, *, request_options: typing.Optional[RequestOptions] = ) client.service.get_with_api_key() """ - _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "apiKey"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore - ) + _response = self._client_wrapper.httpx_client.request("apiKey", method="GET", request_options=request_options) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore try: @@ -76,7 +51,7 @@ def get_with_header( self, *, x_endpoint_header: typing.Optional[str] = os.getenv("MY_HEADER_ENV"), - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> str: """ GET request with custom api key @@ -107,27 +82,10 @@ def get_with_header( ) """ _response = self._client_wrapper.httpx_client.request( + "apiKeyInHeader", method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "apiKeyInHeader"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-Endpoint-Header": str(x_endpoint_header) if x_endpoint_header is not None else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + headers={"X-Endpoint-Header": str(x_endpoint_header) if x_endpoint_header is not None else None}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -167,26 +125,7 @@ async def get_with_api_key(self, *, request_options: typing.Optional[RequestOpti await client.service.get_with_api_key() """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "apiKey"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "apiKey", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -200,7 +139,7 @@ async def get_with_header( self, *, x_endpoint_header: typing.Optional[str] = os.getenv("MY_HEADER_ENV"), - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> str: """ GET request with custom api key @@ -231,27 +170,10 @@ async def get_with_header( ) """ _response = await self._client_wrapper.httpx_client.request( + "apiKeyInHeader", method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "apiKeyInHeader"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-Endpoint-Header": str(x_endpoint_header) if x_endpoint_header is not None else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + headers={"X-Endpoint-Header": str(x_endpoint_header) if x_endpoint_header is not None else None}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/basic-auth-environment-variables/src/seed/basic_auth/client.py b/seed/python-sdk/basic-auth-environment-variables/src/seed/basic_auth/client.py index 0fed436c658..66c19e34f92 100644 --- a/seed/python-sdk/basic-auth-environment-variables/src/seed/basic_auth/client.py +++ b/seed/python-sdk/basic-auth-environment-variables/src/seed/basic_auth/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..errors.errors.bad_request import BadRequest from ..errors.errors.unauthorized_request import UnauthorizedRequest @@ -48,26 +44,7 @@ def get_with_basic_auth(self, *, request_options: typing.Optional[RequestOptions client.basic_auth.get_with_basic_auth() """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "basic-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "basic-auth", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -112,32 +89,7 @@ def post_with_basic_auth( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "basic-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "basic-auth", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -183,26 +135,7 @@ async def get_with_basic_auth(self, *, request_options: typing.Optional[RequestO await client.basic_auth.get_with_basic_auth() """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "basic-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "basic-auth", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -247,32 +180,7 @@ async def post_with_basic_auth( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "basic-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "basic-auth", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore diff --git a/seed/python-sdk/basic-auth-environment-variables/src/seed/core/client_wrapper.py b/seed/python-sdk/basic-auth-environment-variables/src/seed/core/client_wrapper.py index f9c1f09485d..b130e981786 100644 --- a/seed/python-sdk/basic-auth-environment-variables/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/basic-auth-environment-variables/src/seed/core/client_wrapper.py @@ -60,7 +60,12 @@ def __init__( httpx_client: httpx.Client ): super().__init__(username=username, password=password, base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): @@ -74,4 +79,9 @@ def __init__( httpx_client: httpx.AsyncClient ): super().__init__(username=username, password=password, base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/basic-auth-environment-variables/src/seed/core/http_client.py b/seed/python-sdk/basic-auth-environment-variables/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/basic-auth-environment-variables/src/seed/core/http_client.py +++ b/seed/python-sdk/basic-auth-environment-variables/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/basic-auth/src/seed/basic_auth/client.py b/seed/python-sdk/basic-auth/src/seed/basic_auth/client.py index f939eb39fe4..b56104a109a 100644 --- a/seed/python-sdk/basic-auth/src/seed/basic_auth/client.py +++ b/seed/python-sdk/basic-auth/src/seed/basic_auth/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..errors.errors.bad_request import BadRequest from ..errors.errors.unauthorized_request import UnauthorizedRequest @@ -48,26 +44,7 @@ def get_with_basic_auth(self, *, request_options: typing.Optional[RequestOptions client.basic_auth.get_with_basic_auth() """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "basic-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "basic-auth", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -112,32 +89,7 @@ def post_with_basic_auth( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "basic-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "basic-auth", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -183,26 +135,7 @@ async def get_with_basic_auth(self, *, request_options: typing.Optional[RequestO await client.basic_auth.get_with_basic_auth() """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "basic-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "basic-auth", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -247,32 +180,7 @@ async def post_with_basic_auth( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "basic-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "basic-auth", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore diff --git a/seed/python-sdk/basic-auth/src/seed/core/client_wrapper.py b/seed/python-sdk/basic-auth/src/seed/core/client_wrapper.py index 3500859dda4..e68b473e099 100644 --- a/seed/python-sdk/basic-auth/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/basic-auth/src/seed/core/client_wrapper.py @@ -60,7 +60,12 @@ def __init__( httpx_client: httpx.Client ): super().__init__(username=username, password=password, base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): @@ -74,4 +79,9 @@ def __init__( httpx_client: httpx.AsyncClient ): super().__init__(username=username, password=password, base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/basic-auth/src/seed/core/http_client.py b/seed/python-sdk/basic-auth/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/basic-auth/src/seed/core/http_client.py +++ b/seed/python-sdk/basic-auth/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/bearer-token-environment-variable/src/seed/core/client_wrapper.py b/seed/python-sdk/bearer-token-environment-variable/src/seed/core/client_wrapper.py index 734ff28e7af..838cf4dde93 100644 --- a/seed/python-sdk/bearer-token-environment-variable/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/bearer-token-environment-variable/src/seed/core/client_wrapper.py @@ -51,7 +51,12 @@ def __init__( httpx_client: httpx.Client, ): super().__init__(api_key=api_key, base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): @@ -64,4 +69,9 @@ def __init__( httpx_client: httpx.AsyncClient, ): super().__init__(api_key=api_key, base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/bearer-token-environment-variable/src/seed/core/http_client.py b/seed/python-sdk/bearer-token-environment-variable/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/bearer-token-environment-variable/src/seed/core/http_client.py +++ b/seed/python-sdk/bearer-token-environment-variable/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/bearer-token-environment-variable/src/seed/service/client.py b/seed/python-sdk/bearer-token-environment-variable/src/seed/service/client.py index 3faf276316a..b5c12106470 100644 --- a/seed/python-sdk/bearer-token-environment-variable/src/seed/service/client.py +++ b/seed/python-sdk/bearer-token-environment-variable/src/seed/service/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions @@ -40,28 +36,7 @@ def get_with_bearer_token(self, *, request_options: typing.Optional[RequestOptio ) client.service.get_with_bearer_token() """ - _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "apiKey"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore - ) + _response = self._client_wrapper.httpx_client.request("apiKey", method="GET", request_options=request_options) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore try: @@ -99,26 +74,7 @@ async def get_with_bearer_token(self, *, request_options: typing.Optional[Reques await client.service.get_with_bearer_token() """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "apiKey"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "apiKey", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/bytes/src/seed/core/client_wrapper.py b/seed/python-sdk/bytes/src/seed/core/client_wrapper.py index b0f95c5f586..4ffcdbdeb95 100644 --- a/seed/python-sdk/bytes/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/bytes/src/seed/core/client_wrapper.py @@ -30,10 +30,20 @@ def get_timeout(self) -> typing.Optional[float]: class SyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/bytes/src/seed/core/http_client.py b/seed/python-sdk/bytes/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/bytes/src/seed/core/http_client.py +++ b/seed/python-sdk/bytes/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/bytes/src/seed/service/client.py b/seed/python-sdk/bytes/src/seed/service/client.py index 3edef96db3d..70cfc5a883f 100644 --- a/seed/python-sdk/bytes/src/seed/service/client.py +++ b/seed/python-sdk/bytes/src/seed/service/client.py @@ -1,14 +1,10 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -23,7 +19,7 @@ def upload( self, *, request: typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -47,30 +43,7 @@ def upload( client.service.upload() """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "upload-content"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - content=request, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "upload-content", method="POST", content=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return @@ -89,7 +62,7 @@ async def upload( self, *, request: typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -113,30 +86,7 @@ async def upload( await client.service.upload() """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "upload-content"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - content=request, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "upload-content", method="POST", content=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return diff --git a/seed/python-sdk/circular-references-advanced/src/seed/core/client_wrapper.py b/seed/python-sdk/circular-references-advanced/src/seed/core/client_wrapper.py index 7ee9235b717..b7b94cab9e9 100644 --- a/seed/python-sdk/circular-references-advanced/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/circular-references-advanced/src/seed/core/client_wrapper.py @@ -30,10 +30,20 @@ def get_timeout(self) -> typing.Optional[float]: class SyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/circular-references-advanced/src/seed/core/http_client.py b/seed/python-sdk/circular-references-advanced/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/circular-references-advanced/src/seed/core/http_client.py +++ b/seed/python-sdk/circular-references-advanced/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/circular-references/src/seed/core/client_wrapper.py b/seed/python-sdk/circular-references/src/seed/core/client_wrapper.py index 79e3808eca4..f6aeb28ed8d 100644 --- a/seed/python-sdk/circular-references/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/circular-references/src/seed/core/client_wrapper.py @@ -30,10 +30,20 @@ def get_timeout(self) -> typing.Optional[float]: class SyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/circular-references/src/seed/core/http_client.py b/seed/python-sdk/circular-references/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/circular-references/src/seed/core/http_client.py +++ b/seed/python-sdk/circular-references/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/code-samples/src/seed/core/client_wrapper.py b/seed/python-sdk/code-samples/src/seed/core/client_wrapper.py index ad4530ff47a..67034f9dae1 100644 --- a/seed/python-sdk/code-samples/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/code-samples/src/seed/core/client_wrapper.py @@ -30,10 +30,20 @@ def get_timeout(self) -> typing.Optional[float]: class SyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/code-samples/src/seed/core/http_client.py b/seed/python-sdk/code-samples/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/code-samples/src/seed/core/http_client.py +++ b/seed/python-sdk/code-samples/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/code-samples/src/seed/service/client.py b/seed/python-sdk/code-samples/src/seed/service/client.py index fd0cece87f2..d847178a81a 100644 --- a/seed/python-sdk/code-samples/src/seed/service/client.py +++ b/seed/python-sdk/code-samples/src/seed/service/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from .types.my_response import MyResponse @@ -46,32 +42,7 @@ def hello(self, *, num_events: int, request_options: typing.Optional[RequestOpti ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "hello"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"num_events": num_events}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"num_events": num_events}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "hello", method="POST", json={"num_events": num_events}, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(MyResponse, _response.json()) # type: ignore @@ -111,32 +82,7 @@ async def hello(self, *, num_events: int, request_options: typing.Optional[Reque ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "hello"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"num_events": num_events}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"num_events": num_events}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "hello", method="POST", json={"num_events": num_events}, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(MyResponse, _response.json()) # type: ignore diff --git a/seed/python-sdk/custom-auth/src/seed/core/client_wrapper.py b/seed/python-sdk/custom-auth/src/seed/core/client_wrapper.py index 916f41e4297..5e1e31c5b32 100644 --- a/seed/python-sdk/custom-auth/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/custom-auth/src/seed/core/client_wrapper.py @@ -39,7 +39,12 @@ def __init__( httpx_client: httpx.Client ): super().__init__(custom_auth_scheme=custom_auth_scheme, base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): @@ -52,4 +57,9 @@ def __init__( httpx_client: httpx.AsyncClient ): super().__init__(custom_auth_scheme=custom_auth_scheme, base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/custom-auth/src/seed/core/http_client.py b/seed/python-sdk/custom-auth/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/custom-auth/src/seed/core/http_client.py +++ b/seed/python-sdk/custom-auth/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/custom-auth/src/seed/custom_auth/client.py b/seed/python-sdk/custom-auth/src/seed/custom_auth/client.py index 77a4ebb7bd7..821cbd45e27 100644 --- a/seed/python-sdk/custom-auth/src/seed/custom_auth/client.py +++ b/seed/python-sdk/custom-auth/src/seed/custom_auth/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..errors.errors.bad_request import BadRequest from ..errors.errors.unauthorized_request import UnauthorizedRequest @@ -47,26 +43,7 @@ def get_with_custom_auth(self, *, request_options: typing.Optional[RequestOption client.custom_auth.get_with_custom_auth() """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "custom-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "custom-auth", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -110,32 +87,7 @@ def post_with_custom_auth( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "custom-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "custom-auth", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -180,26 +132,7 @@ async def get_with_custom_auth(self, *, request_options: typing.Optional[Request await client.custom_auth.get_with_custom_auth() """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "custom-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "custom-auth", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -243,32 +176,7 @@ async def post_with_custom_auth( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "custom-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "custom-auth", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore diff --git a/seed/python-sdk/enum/no-custom-config/src/seed/core/client_wrapper.py b/seed/python-sdk/enum/no-custom-config/src/seed/core/client_wrapper.py index efe9e1ba4d3..5bf926b7b30 100644 --- a/seed/python-sdk/enum/no-custom-config/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/enum/no-custom-config/src/seed/core/client_wrapper.py @@ -30,10 +30,20 @@ def get_timeout(self) -> typing.Optional[float]: class SyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/enum/no-custom-config/src/seed/core/http_client.py b/seed/python-sdk/enum/no-custom-config/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/enum/no-custom-config/src/seed/core/http_client.py +++ b/seed/python-sdk/enum/no-custom-config/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/enum/no-custom-config/src/seed/inlined_request/client.py b/seed/python-sdk/enum/no-custom-config/src/seed/inlined_request/client.py index 009633186df..0cb2e6dd918 100644 --- a/seed/python-sdk/enum/no-custom-config/src/seed/inlined_request/client.py +++ b/seed/python-sdk/enum/no-custom-config/src/seed/inlined_request/client.py @@ -1,14 +1,10 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..types.color_or_operand import ColorOrOperand from ..types.operand import Operand @@ -28,7 +24,7 @@ def send( operand_or_color: ColorOrOperand, maybe_operand: typing.Optional[Operand] = OMIT, maybe_operand_or_color: typing.Optional[ColorOrOperand] = OMIT, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -60,38 +56,17 @@ def send( operand_or_color="red", ) """ - _request: typing.Dict[str, typing.Any] = {"operand": operand, "operandOrColor": operand_or_color} - if maybe_operand is not OMIT: - _request["maybeOperand"] = maybe_operand - if maybe_operand_or_color is not OMIT: - _request["maybeOperandOrColor"] = maybe_operand_or_color _response = self._client_wrapper.httpx_client.request( + "inlined", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "inlined"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "operand": operand, + "maybeOperand": maybe_operand, + "operandOrColor": operand_or_color, + "maybeOperandOrColor": maybe_operand_or_color, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return @@ -113,7 +88,7 @@ async def send( operand_or_color: ColorOrOperand, maybe_operand: typing.Optional[Operand] = OMIT, maybe_operand_or_color: typing.Optional[ColorOrOperand] = OMIT, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -145,38 +120,17 @@ async def send( operand_or_color="red", ) """ - _request: typing.Dict[str, typing.Any] = {"operand": operand, "operandOrColor": operand_or_color} - if maybe_operand is not OMIT: - _request["maybeOperand"] = maybe_operand - if maybe_operand_or_color is not OMIT: - _request["maybeOperandOrColor"] = maybe_operand_or_color _response = await self._client_wrapper.httpx_client.request( + "inlined", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "inlined"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "operand": operand, + "maybeOperand": maybe_operand, + "operandOrColor": operand_or_color, + "maybeOperandOrColor": maybe_operand_or_color, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return diff --git a/seed/python-sdk/enum/no-custom-config/src/seed/path_param/client.py b/seed/python-sdk/enum/no-custom-config/src/seed/path_param/client.py index 0705578fdc0..0d628f9b621 100644 --- a/seed/python-sdk/enum/no-custom-config/src/seed/path_param/client.py +++ b/seed/python-sdk/enum/no-custom-config/src/seed/path_param/client.py @@ -1,14 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ..core.jsonable_encoder import jsonable_encoder -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..types.color_or_operand import ColorOrOperand from ..types.operand import Operand @@ -60,32 +57,9 @@ def send( ) """ _response = self._client_wrapper.httpx_client.request( + f"path/{jsonable_encoder(operand)}/{jsonable_encoder(maybe_operand)}/{jsonable_encoder(operand_or_color)}/{jsonable_encoder(maybe_operand_or_color)}", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", - f"path/{jsonable_encoder(operand)}/{jsonable_encoder(maybe_operand)}/{jsonable_encoder(operand_or_color)}/{jsonable_encoder(maybe_operand_or_color)}", - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -142,32 +116,9 @@ async def send( ) """ _response = await self._client_wrapper.httpx_client.request( + f"path/{jsonable_encoder(operand)}/{jsonable_encoder(maybe_operand)}/{jsonable_encoder(operand_or_color)}/{jsonable_encoder(maybe_operand_or_color)}", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", - f"path/{jsonable_encoder(operand)}/{jsonable_encoder(maybe_operand)}/{jsonable_encoder(operand_or_color)}/{jsonable_encoder(maybe_operand_or_color)}", - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, ) if 200 <= _response.status_code < 300: return diff --git a/seed/python-sdk/enum/no-custom-config/src/seed/query_param/client.py b/seed/python-sdk/enum/no-custom-config/src/seed/query_param/client.py index 48f92b1f3a8..1b6a0589b5f 100644 --- a/seed/python-sdk/enum/no-custom-config/src/seed/query_param/client.py +++ b/seed/python-sdk/enum/no-custom-config/src/seed/query_param/client.py @@ -1,14 +1,10 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..types.color_or_operand import ColorOrOperand from ..types.operand import Operand @@ -25,7 +21,7 @@ def send( operand_or_color: ColorOrOperand, maybe_operand: typing.Optional[Operand] = None, maybe_operand_or_color: typing.Optional[ColorOrOperand] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -58,41 +54,15 @@ def send( ) """ _response = self._client_wrapper.httpx_client.request( + "query", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "query"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "operand": operand, - "maybeOperand": maybe_operand, - "operandOrColor": operand_or_color, - "maybeOperandOrColor": maybe_operand_or_color, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={ + "operand": operand, + "maybeOperand": maybe_operand, + "operandOrColor": operand_or_color, + "maybeOperandOrColor": maybe_operand_or_color, + }, + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -109,7 +79,7 @@ def send_list( operand_or_color: typing.Union[ColorOrOperand, typing.Sequence[ColorOrOperand]], maybe_operand: typing.Optional[typing.Union[Operand, typing.Sequence[Operand]]] = None, maybe_operand_or_color: typing.Optional[typing.Union[ColorOrOperand, typing.Sequence[ColorOrOperand]]] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -144,41 +114,15 @@ def send_list( ) """ _response = self._client_wrapper.httpx_client.request( + "query-list", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "query-list"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "operand": operand, - "maybeOperand": maybe_operand, - "operandOrColor": operand_or_color, - "maybeOperandOrColor": maybe_operand_or_color, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={ + "operand": operand, + "maybeOperand": maybe_operand, + "operandOrColor": operand_or_color, + "maybeOperandOrColor": maybe_operand_or_color, + }, + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -200,7 +144,7 @@ async def send( operand_or_color: ColorOrOperand, maybe_operand: typing.Optional[Operand] = None, maybe_operand_or_color: typing.Optional[ColorOrOperand] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -233,41 +177,15 @@ async def send( ) """ _response = await self._client_wrapper.httpx_client.request( + "query", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "query"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "operand": operand, - "maybeOperand": maybe_operand, - "operandOrColor": operand_or_color, - "maybeOperandOrColor": maybe_operand_or_color, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={ + "operand": operand, + "maybeOperand": maybe_operand, + "operandOrColor": operand_or_color, + "maybeOperandOrColor": maybe_operand_or_color, + }, + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -284,7 +202,7 @@ async def send_list( operand_or_color: typing.Union[ColorOrOperand, typing.Sequence[ColorOrOperand]], maybe_operand: typing.Optional[typing.Union[Operand, typing.Sequence[Operand]]] = None, maybe_operand_or_color: typing.Optional[typing.Union[ColorOrOperand, typing.Sequence[ColorOrOperand]]] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -319,41 +237,15 @@ async def send_list( ) """ _response = await self._client_wrapper.httpx_client.request( + "query-list", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "query-list"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "operand": operand, - "maybeOperand": maybe_operand, - "operandOrColor": operand_or_color, - "maybeOperandOrColor": maybe_operand_or_color, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={ + "operand": operand, + "maybeOperand": maybe_operand, + "operandOrColor": operand_or_color, + "maybeOperandOrColor": maybe_operand_or_color, + }, + request_options=request_options, ) if 200 <= _response.status_code < 300: return diff --git a/seed/python-sdk/enum/strenum/src/seed/core/client_wrapper.py b/seed/python-sdk/enum/strenum/src/seed/core/client_wrapper.py index efe9e1ba4d3..5bf926b7b30 100644 --- a/seed/python-sdk/enum/strenum/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/enum/strenum/src/seed/core/client_wrapper.py @@ -30,10 +30,20 @@ def get_timeout(self) -> typing.Optional[float]: class SyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/enum/strenum/src/seed/core/http_client.py b/seed/python-sdk/enum/strenum/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/enum/strenum/src/seed/core/http_client.py +++ b/seed/python-sdk/enum/strenum/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/enum/strenum/src/seed/inlined_request/client.py b/seed/python-sdk/enum/strenum/src/seed/inlined_request/client.py index 009633186df..0cb2e6dd918 100644 --- a/seed/python-sdk/enum/strenum/src/seed/inlined_request/client.py +++ b/seed/python-sdk/enum/strenum/src/seed/inlined_request/client.py @@ -1,14 +1,10 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..types.color_or_operand import ColorOrOperand from ..types.operand import Operand @@ -28,7 +24,7 @@ def send( operand_or_color: ColorOrOperand, maybe_operand: typing.Optional[Operand] = OMIT, maybe_operand_or_color: typing.Optional[ColorOrOperand] = OMIT, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -60,38 +56,17 @@ def send( operand_or_color="red", ) """ - _request: typing.Dict[str, typing.Any] = {"operand": operand, "operandOrColor": operand_or_color} - if maybe_operand is not OMIT: - _request["maybeOperand"] = maybe_operand - if maybe_operand_or_color is not OMIT: - _request["maybeOperandOrColor"] = maybe_operand_or_color _response = self._client_wrapper.httpx_client.request( + "inlined", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "inlined"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "operand": operand, + "maybeOperand": maybe_operand, + "operandOrColor": operand_or_color, + "maybeOperandOrColor": maybe_operand_or_color, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return @@ -113,7 +88,7 @@ async def send( operand_or_color: ColorOrOperand, maybe_operand: typing.Optional[Operand] = OMIT, maybe_operand_or_color: typing.Optional[ColorOrOperand] = OMIT, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -145,38 +120,17 @@ async def send( operand_or_color="red", ) """ - _request: typing.Dict[str, typing.Any] = {"operand": operand, "operandOrColor": operand_or_color} - if maybe_operand is not OMIT: - _request["maybeOperand"] = maybe_operand - if maybe_operand_or_color is not OMIT: - _request["maybeOperandOrColor"] = maybe_operand_or_color _response = await self._client_wrapper.httpx_client.request( + "inlined", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "inlined"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "operand": operand, + "maybeOperand": maybe_operand, + "operandOrColor": operand_or_color, + "maybeOperandOrColor": maybe_operand_or_color, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return diff --git a/seed/python-sdk/enum/strenum/src/seed/path_param/client.py b/seed/python-sdk/enum/strenum/src/seed/path_param/client.py index 0705578fdc0..0d628f9b621 100644 --- a/seed/python-sdk/enum/strenum/src/seed/path_param/client.py +++ b/seed/python-sdk/enum/strenum/src/seed/path_param/client.py @@ -1,14 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ..core.jsonable_encoder import jsonable_encoder -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..types.color_or_operand import ColorOrOperand from ..types.operand import Operand @@ -60,32 +57,9 @@ def send( ) """ _response = self._client_wrapper.httpx_client.request( + f"path/{jsonable_encoder(operand)}/{jsonable_encoder(maybe_operand)}/{jsonable_encoder(operand_or_color)}/{jsonable_encoder(maybe_operand_or_color)}", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", - f"path/{jsonable_encoder(operand)}/{jsonable_encoder(maybe_operand)}/{jsonable_encoder(operand_or_color)}/{jsonable_encoder(maybe_operand_or_color)}", - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -142,32 +116,9 @@ async def send( ) """ _response = await self._client_wrapper.httpx_client.request( + f"path/{jsonable_encoder(operand)}/{jsonable_encoder(maybe_operand)}/{jsonable_encoder(operand_or_color)}/{jsonable_encoder(maybe_operand_or_color)}", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", - f"path/{jsonable_encoder(operand)}/{jsonable_encoder(maybe_operand)}/{jsonable_encoder(operand_or_color)}/{jsonable_encoder(maybe_operand_or_color)}", - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, ) if 200 <= _response.status_code < 300: return diff --git a/seed/python-sdk/enum/strenum/src/seed/query_param/client.py b/seed/python-sdk/enum/strenum/src/seed/query_param/client.py index 48f92b1f3a8..1b6a0589b5f 100644 --- a/seed/python-sdk/enum/strenum/src/seed/query_param/client.py +++ b/seed/python-sdk/enum/strenum/src/seed/query_param/client.py @@ -1,14 +1,10 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..types.color_or_operand import ColorOrOperand from ..types.operand import Operand @@ -25,7 +21,7 @@ def send( operand_or_color: ColorOrOperand, maybe_operand: typing.Optional[Operand] = None, maybe_operand_or_color: typing.Optional[ColorOrOperand] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -58,41 +54,15 @@ def send( ) """ _response = self._client_wrapper.httpx_client.request( + "query", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "query"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "operand": operand, - "maybeOperand": maybe_operand, - "operandOrColor": operand_or_color, - "maybeOperandOrColor": maybe_operand_or_color, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={ + "operand": operand, + "maybeOperand": maybe_operand, + "operandOrColor": operand_or_color, + "maybeOperandOrColor": maybe_operand_or_color, + }, + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -109,7 +79,7 @@ def send_list( operand_or_color: typing.Union[ColorOrOperand, typing.Sequence[ColorOrOperand]], maybe_operand: typing.Optional[typing.Union[Operand, typing.Sequence[Operand]]] = None, maybe_operand_or_color: typing.Optional[typing.Union[ColorOrOperand, typing.Sequence[ColorOrOperand]]] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -144,41 +114,15 @@ def send_list( ) """ _response = self._client_wrapper.httpx_client.request( + "query-list", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "query-list"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "operand": operand, - "maybeOperand": maybe_operand, - "operandOrColor": operand_or_color, - "maybeOperandOrColor": maybe_operand_or_color, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={ + "operand": operand, + "maybeOperand": maybe_operand, + "operandOrColor": operand_or_color, + "maybeOperandOrColor": maybe_operand_or_color, + }, + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -200,7 +144,7 @@ async def send( operand_or_color: ColorOrOperand, maybe_operand: typing.Optional[Operand] = None, maybe_operand_or_color: typing.Optional[ColorOrOperand] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -233,41 +177,15 @@ async def send( ) """ _response = await self._client_wrapper.httpx_client.request( + "query", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "query"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "operand": operand, - "maybeOperand": maybe_operand, - "operandOrColor": operand_or_color, - "maybeOperandOrColor": maybe_operand_or_color, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={ + "operand": operand, + "maybeOperand": maybe_operand, + "operandOrColor": operand_or_color, + "maybeOperandOrColor": maybe_operand_or_color, + }, + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -284,7 +202,7 @@ async def send_list( operand_or_color: typing.Union[ColorOrOperand, typing.Sequence[ColorOrOperand]], maybe_operand: typing.Optional[typing.Union[Operand, typing.Sequence[Operand]]] = None, maybe_operand_or_color: typing.Optional[typing.Union[ColorOrOperand, typing.Sequence[ColorOrOperand]]] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -319,41 +237,15 @@ async def send_list( ) """ _response = await self._client_wrapper.httpx_client.request( + "query-list", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "query-list"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "operand": operand, - "maybeOperand": maybe_operand, - "operandOrColor": operand_or_color, - "maybeOperandOrColor": maybe_operand_or_color, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={ + "operand": operand, + "maybeOperand": maybe_operand, + "operandOrColor": operand_or_color, + "maybeOperandOrColor": maybe_operand_or_color, + }, + request_options=request_options, ) if 200 <= _response.status_code < 300: return diff --git a/seed/python-sdk/error-property/src/seed/core/client_wrapper.py b/seed/python-sdk/error-property/src/seed/core/client_wrapper.py index 3316c781c63..67d93313e4c 100644 --- a/seed/python-sdk/error-property/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/error-property/src/seed/core/client_wrapper.py @@ -30,10 +30,20 @@ def get_timeout(self) -> typing.Optional[float]: class SyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/error-property/src/seed/core/http_client.py b/seed/python-sdk/error-property/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/error-property/src/seed/core/http_client.py +++ b/seed/python-sdk/error-property/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/error-property/src/seed/property_based_error/client.py b/seed/python-sdk/error-property/src/seed/property_based_error/client.py index e7d9988384b..42e660c640f 100644 --- a/seed/python-sdk/error-property/src/seed/property_based_error/client.py +++ b/seed/python-sdk/error-property/src/seed/property_based_error/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..errors.errors.property_based_error_test import PropertyBasedErrorTest from ..errors.types.property_based_error_test_body import PropertyBasedErrorTestBody @@ -42,26 +38,7 @@ def throw_error(self, *, request_options: typing.Optional[RequestOptions] = None client.property_based_error.throw_error() """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "property-based-error"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "property-based-error", method="GET", request_options=request_options ) try: _response_json = _response.json() @@ -104,26 +81,7 @@ async def throw_error(self, *, request_options: typing.Optional[RequestOptions] await client.property_based_error.throw_error() """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "property-based-error"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "property-based-error", method="GET", request_options=request_options ) try: _response_json = _response.json() diff --git a/seed/python-sdk/examples/client-filename/src/seed/base_client.py b/seed/python-sdk/examples/client-filename/src/seed/base_client.py index 645ed4f9d90..0076f73af70 100644 --- a/seed/python-sdk/examples/client-filename/src/seed/base_client.py +++ b/seed/python-sdk/examples/client-filename/src/seed/base_client.py @@ -7,10 +7,7 @@ from .core.api_error import ApiError from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from .core.jsonable_encoder import jsonable_encoder from .core.pydantic_utilities import pydantic_v1 -from .core.query_encoder import encode_query -from .core.remove_none_from_dict import remove_none_from_dict from .core.request_options import RequestOptions from .environment import SeedExhaustiveEnvironment from .file.client import AsyncFileClient, FileClient @@ -106,27 +103,7 @@ def echo(self, *, request: str, request_options: typing.Optional[RequestOptions] ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=self._client_wrapper.get_base_url(), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -222,27 +199,7 @@ async def echo(self, *, request: str, request_options: typing.Optional[RequestOp ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=self._client_wrapper.get_base_url(), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/examples/client-filename/src/seed/core/client_wrapper.py b/seed/python-sdk/examples/client-filename/src/seed/core/client_wrapper.py index f7eea86d70c..ef78d78ed99 100644 --- a/seed/python-sdk/examples/client-filename/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/examples/client-filename/src/seed/core/client_wrapper.py @@ -53,7 +53,12 @@ def __init__( httpx_client: httpx.Client, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): @@ -66,4 +71,9 @@ def __init__( httpx_client: httpx.AsyncClient, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/examples/client-filename/src/seed/core/http_client.py b/seed/python-sdk/examples/client-filename/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/examples/client-filename/src/seed/core/http_client.py +++ b/seed/python-sdk/examples/client-filename/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/examples/client-filename/src/seed/file/notification/service/client.py b/seed/python-sdk/examples/client-filename/src/seed/file/notification/service/client.py index 3461b3977f0..a5be81dd88e 100644 --- a/seed/python-sdk/examples/client-filename/src/seed/file/notification/service/client.py +++ b/seed/python-sdk/examples/client-filename/src/seed/file/notification/service/client.py @@ -1,15 +1,12 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ....core.api_error import ApiError from ....core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ....core.jsonable_encoder import jsonable_encoder from ....core.pydantic_utilities import pydantic_v1 -from ....core.query_encoder import encode_query -from ....core.remove_none_from_dict import remove_none_from_dict from ....core.request_options import RequestOptions from ....types.types.exception import Exception @@ -47,28 +44,7 @@ def get_exception( ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"file/notification/{jsonable_encoder(notification_id)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"file/notification/{jsonable_encoder(notification_id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Exception, _response.json()) # type: ignore @@ -112,28 +88,7 @@ async def get_exception( ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"file/notification/{jsonable_encoder(notification_id)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"file/notification/{jsonable_encoder(notification_id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Exception, _response.json()) # type: ignore diff --git a/seed/python-sdk/examples/client-filename/src/seed/file/service/client.py b/seed/python-sdk/examples/client-filename/src/seed/file/service/client.py index 4e7d7356b47..823ce2713c4 100644 --- a/seed/python-sdk/examples/client-filename/src/seed/file/service/client.py +++ b/seed/python-sdk/examples/client-filename/src/seed/file/service/client.py @@ -1,15 +1,12 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.errors.not_found_error import NotFoundError from ...types.types.file import File @@ -54,27 +51,10 @@ def get_file( ) """ _response = self._client_wrapper.httpx_client.request( + f"file/{jsonable_encoder(filename)}", method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"file/{jsonable_encoder(filename)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-File-API-Version": str(x_file_api_version) if x_file_api_version is not None else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + headers={"X-File-API-Version": str(x_file_api_version) if x_file_api_version is not None else None}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(File, _response.json()) # type: ignore @@ -126,27 +106,10 @@ async def get_file( ) """ _response = await self._client_wrapper.httpx_client.request( + f"file/{jsonable_encoder(filename)}", method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"file/{jsonable_encoder(filename)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-File-API-Version": str(x_file_api_version) if x_file_api_version is not None else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + headers={"X-File-API-Version": str(x_file_api_version) if x_file_api_version is not None else None}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(File, _response.json()) # type: ignore diff --git a/seed/python-sdk/examples/client-filename/src/seed/health/service/client.py b/seed/python-sdk/examples/client-filename/src/seed/health/service/client.py index 94e98565b01..aa46c386eee 100644 --- a/seed/python-sdk/examples/client-filename/src/seed/health/service/client.py +++ b/seed/python-sdk/examples/client-filename/src/seed/health/service/client.py @@ -1,15 +1,12 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions @@ -47,26 +44,7 @@ def check(self, id: str, *, request_options: typing.Optional[RequestOptions] = N ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"check/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"check/{jsonable_encoder(id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -100,28 +78,7 @@ def ping(self, *, request_options: typing.Optional[RequestOptions] = None) -> bo ) client.health.service.ping() """ - _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "ping"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore - ) + _response = self._client_wrapper.httpx_client.request("ping", method="GET", request_options=request_options) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore try: @@ -165,26 +122,7 @@ async def check(self, id: str, *, request_options: typing.Optional[RequestOption ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"check/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"check/{jsonable_encoder(id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -219,26 +157,7 @@ async def ping(self, *, request_options: typing.Optional[RequestOptions] = None) await client.health.service.ping() """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "ping"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "ping", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore diff --git a/seed/python-sdk/examples/client-filename/src/seed/service/client.py b/seed/python-sdk/examples/client-filename/src/seed/service/client.py index f71ddb9e96d..9ad33dbc6cb 100644 --- a/seed/python-sdk/examples/client-filename/src/seed/service/client.py +++ b/seed/python-sdk/examples/client-filename/src/seed/service/client.py @@ -1,7 +1,6 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..commons.types.types.tag import Tag @@ -9,8 +8,6 @@ from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..types.types.metadata import Metadata from ..types.types.movie import Movie @@ -52,26 +49,7 @@ def get_movie(self, movie_id: MovieId, *, request_options: typing.Optional[Reque ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"movie/{jsonable_encoder(movie_id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"movie/{jsonable_encoder(movie_id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Movie, _response.json()) # type: ignore @@ -145,46 +123,22 @@ def create_movie( }, ) """ - _request: typing.Dict[str, typing.Any] = { - "id": id, - "title": title, - "from": from_, - "rating": rating, - "tag": tag, - "metadata": metadata, - "type": "movie", - } - if prequel is not OMIT: - _request["prequel"] = prequel - if book is not OMIT: - _request["book"] = book _response = self._client_wrapper.httpx_client.request( + "movie", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "movie"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "id": id, + "prequel": prequel, + "title": title, + "from": from_, + "rating": rating, + "tag": tag, + "book": book, + "metadata": metadata, + "type": "movie", }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(MovieId, _response.json()) # type: ignore @@ -234,37 +188,11 @@ def get_metadata( ) """ _response = self._client_wrapper.httpx_client.request( + "metadata", method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "metadata"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "shallow": shallow, - "tag": tag, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-API-Version": str(x_api_version) if x_api_version is not None else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"shallow": shallow, "tag": tag}, + headers={"X-API-Version": str(x_api_version) if x_api_version is not None else None}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Metadata, _response.json()) # type: ignore @@ -297,29 +225,7 @@ def get_response(self, *, request_options: typing.Optional[RequestOptions] = Non client.service.get_response() """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "response"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "response", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Response, _response.json()) # type: ignore @@ -361,26 +267,7 @@ async def get_movie(self, movie_id: MovieId, *, request_options: typing.Optional ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"movie/{jsonable_encoder(movie_id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"movie/{jsonable_encoder(movie_id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Movie, _response.json()) # type: ignore @@ -454,46 +341,22 @@ async def create_movie( }, ) """ - _request: typing.Dict[str, typing.Any] = { - "id": id, - "title": title, - "from": from_, - "rating": rating, - "tag": tag, - "metadata": metadata, - "type": "movie", - } - if prequel is not OMIT: - _request["prequel"] = prequel - if book is not OMIT: - _request["book"] = book _response = await self._client_wrapper.httpx_client.request( + "movie", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "movie"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "id": id, + "prequel": prequel, + "title": title, + "from": from_, + "rating": rating, + "tag": tag, + "book": book, + "metadata": metadata, + "type": "movie", }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(MovieId, _response.json()) # type: ignore @@ -543,37 +406,11 @@ async def get_metadata( ) """ _response = await self._client_wrapper.httpx_client.request( + "metadata", method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "metadata"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "shallow": shallow, - "tag": tag, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-API-Version": str(x_api_version) if x_api_version is not None else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"shallow": shallow, "tag": tag}, + headers={"X-API-Version": str(x_api_version) if x_api_version is not None else None}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Metadata, _response.json()) # type: ignore @@ -606,29 +443,7 @@ async def get_response(self, *, request_options: typing.Optional[RequestOptions] await client.service.get_response() """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "response"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "response", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Response, _response.json()) # type: ignore diff --git a/seed/python-sdk/examples/no-custom-config/src/seed/client.py b/seed/python-sdk/examples/no-custom-config/src/seed/client.py index 27270e187d0..f2ba1f69d59 100644 --- a/seed/python-sdk/examples/no-custom-config/src/seed/client.py +++ b/seed/python-sdk/examples/no-custom-config/src/seed/client.py @@ -7,10 +7,7 @@ from .core.api_error import ApiError from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from .core.jsonable_encoder import jsonable_encoder from .core.pydantic_utilities import pydantic_v1 -from .core.query_encoder import encode_query -from .core.remove_none_from_dict import remove_none_from_dict from .core.request_options import RequestOptions from .environment import SeedExamplesEnvironment from .file.client import AsyncFileClient, FileClient @@ -106,27 +103,7 @@ def echo(self, *, request: str, request_options: typing.Optional[RequestOptions] ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=self._client_wrapper.get_base_url(), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -222,27 +199,7 @@ async def echo(self, *, request: str, request_options: typing.Optional[RequestOp ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=self._client_wrapper.get_base_url(), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/examples/no-custom-config/src/seed/core/client_wrapper.py b/seed/python-sdk/examples/no-custom-config/src/seed/core/client_wrapper.py index f7eea86d70c..ef78d78ed99 100644 --- a/seed/python-sdk/examples/no-custom-config/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/examples/no-custom-config/src/seed/core/client_wrapper.py @@ -53,7 +53,12 @@ def __init__( httpx_client: httpx.Client, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): @@ -66,4 +71,9 @@ def __init__( httpx_client: httpx.AsyncClient, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/examples/no-custom-config/src/seed/core/http_client.py b/seed/python-sdk/examples/no-custom-config/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/examples/no-custom-config/src/seed/core/http_client.py +++ b/seed/python-sdk/examples/no-custom-config/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/examples/no-custom-config/src/seed/file/notification/service/client.py b/seed/python-sdk/examples/no-custom-config/src/seed/file/notification/service/client.py index a15f67cdd3f..e4f5697e2b8 100644 --- a/seed/python-sdk/examples/no-custom-config/src/seed/file/notification/service/client.py +++ b/seed/python-sdk/examples/no-custom-config/src/seed/file/notification/service/client.py @@ -1,15 +1,12 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ....core.api_error import ApiError from ....core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ....core.jsonable_encoder import jsonable_encoder from ....core.pydantic_utilities import pydantic_v1 -from ....core.query_encoder import encode_query -from ....core.remove_none_from_dict import remove_none_from_dict from ....core.request_options import RequestOptions from ....types.types.exception import Exception @@ -47,28 +44,7 @@ def get_exception( ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"file/notification/{jsonable_encoder(notification_id)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"file/notification/{jsonable_encoder(notification_id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Exception, _response.json()) # type: ignore @@ -112,28 +88,7 @@ async def get_exception( ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"file/notification/{jsonable_encoder(notification_id)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"file/notification/{jsonable_encoder(notification_id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Exception, _response.json()) # type: ignore diff --git a/seed/python-sdk/examples/no-custom-config/src/seed/file/service/client.py b/seed/python-sdk/examples/no-custom-config/src/seed/file/service/client.py index 2df4c3f635f..d509d2f810e 100644 --- a/seed/python-sdk/examples/no-custom-config/src/seed/file/service/client.py +++ b/seed/python-sdk/examples/no-custom-config/src/seed/file/service/client.py @@ -1,15 +1,12 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.errors.not_found_error import NotFoundError from ...types.types.file import File @@ -54,27 +51,10 @@ def get_file( ) """ _response = self._client_wrapper.httpx_client.request( + f"file/{jsonable_encoder(filename)}", method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"file/{jsonable_encoder(filename)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-File-API-Version": str(x_file_api_version) if x_file_api_version is not None else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + headers={"X-File-API-Version": str(x_file_api_version) if x_file_api_version is not None else None}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(File, _response.json()) # type: ignore @@ -126,27 +106,10 @@ async def get_file( ) """ _response = await self._client_wrapper.httpx_client.request( + f"file/{jsonable_encoder(filename)}", method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"file/{jsonable_encoder(filename)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-File-API-Version": str(x_file_api_version) if x_file_api_version is not None else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + headers={"X-File-API-Version": str(x_file_api_version) if x_file_api_version is not None else None}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(File, _response.json()) # type: ignore diff --git a/seed/python-sdk/examples/no-custom-config/src/seed/health/service/client.py b/seed/python-sdk/examples/no-custom-config/src/seed/health/service/client.py index c63a98a55ea..de3cd9b9e1d 100644 --- a/seed/python-sdk/examples/no-custom-config/src/seed/health/service/client.py +++ b/seed/python-sdk/examples/no-custom-config/src/seed/health/service/client.py @@ -1,15 +1,12 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions @@ -47,26 +44,7 @@ def check(self, id: str, *, request_options: typing.Optional[RequestOptions] = N ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"check/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"check/{jsonable_encoder(id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -100,28 +78,7 @@ def ping(self, *, request_options: typing.Optional[RequestOptions] = None) -> bo ) client.health.service.ping() """ - _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "ping"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore - ) + _response = self._client_wrapper.httpx_client.request("ping", method="GET", request_options=request_options) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore try: @@ -165,26 +122,7 @@ async def check(self, id: str, *, request_options: typing.Optional[RequestOption ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"check/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"check/{jsonable_encoder(id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -219,26 +157,7 @@ async def ping(self, *, request_options: typing.Optional[RequestOptions] = None) await client.health.service.ping() """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "ping"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "ping", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore diff --git a/seed/python-sdk/examples/no-custom-config/src/seed/service/client.py b/seed/python-sdk/examples/no-custom-config/src/seed/service/client.py index fefab1c37de..24ff4b99f0d 100644 --- a/seed/python-sdk/examples/no-custom-config/src/seed/service/client.py +++ b/seed/python-sdk/examples/no-custom-config/src/seed/service/client.py @@ -1,7 +1,6 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..commons.types.types.tag import Tag @@ -9,8 +8,6 @@ from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..types.types.metadata import Metadata from ..types.types.movie import Movie @@ -52,26 +49,7 @@ def get_movie(self, movie_id: MovieId, *, request_options: typing.Optional[Reque ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"movie/{jsonable_encoder(movie_id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"movie/{jsonable_encoder(movie_id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Movie, _response.json()) # type: ignore @@ -145,46 +123,22 @@ def create_movie( }, ) """ - _request: typing.Dict[str, typing.Any] = { - "id": id, - "title": title, - "from": from_, - "rating": rating, - "tag": tag, - "metadata": metadata, - "type": "movie", - } - if prequel is not OMIT: - _request["prequel"] = prequel - if book is not OMIT: - _request["book"] = book _response = self._client_wrapper.httpx_client.request( + "movie", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "movie"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "id": id, + "prequel": prequel, + "title": title, + "from": from_, + "rating": rating, + "tag": tag, + "book": book, + "metadata": metadata, + "type": "movie", }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(MovieId, _response.json()) # type: ignore @@ -234,37 +188,11 @@ def get_metadata( ) """ _response = self._client_wrapper.httpx_client.request( + "metadata", method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "metadata"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "shallow": shallow, - "tag": tag, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-API-Version": str(x_api_version) if x_api_version is not None else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"shallow": shallow, "tag": tag}, + headers={"X-API-Version": str(x_api_version) if x_api_version is not None else None}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Metadata, _response.json()) # type: ignore @@ -297,29 +225,7 @@ def get_response(self, *, request_options: typing.Optional[RequestOptions] = Non client.service.get_response() """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "response"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "response", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Response, _response.json()) # type: ignore @@ -361,26 +267,7 @@ async def get_movie(self, movie_id: MovieId, *, request_options: typing.Optional ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"movie/{jsonable_encoder(movie_id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"movie/{jsonable_encoder(movie_id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Movie, _response.json()) # type: ignore @@ -454,46 +341,22 @@ async def create_movie( }, ) """ - _request: typing.Dict[str, typing.Any] = { - "id": id, - "title": title, - "from": from_, - "rating": rating, - "tag": tag, - "metadata": metadata, - "type": "movie", - } - if prequel is not OMIT: - _request["prequel"] = prequel - if book is not OMIT: - _request["book"] = book _response = await self._client_wrapper.httpx_client.request( + "movie", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "movie"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "id": id, + "prequel": prequel, + "title": title, + "from": from_, + "rating": rating, + "tag": tag, + "book": book, + "metadata": metadata, + "type": "movie", }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(MovieId, _response.json()) # type: ignore @@ -543,37 +406,11 @@ async def get_metadata( ) """ _response = await self._client_wrapper.httpx_client.request( + "metadata", method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "metadata"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "shallow": shallow, - "tag": tag, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-API-Version": str(x_api_version) if x_api_version is not None else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"shallow": shallow, "tag": tag}, + headers={"X-API-Version": str(x_api_version) if x_api_version is not None else None}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Metadata, _response.json()) # type: ignore @@ -606,29 +443,7 @@ async def get_response(self, *, request_options: typing.Optional[RequestOptions] await client.service.get_response() """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "response"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "response", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Response, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/core/client_wrapper.py b/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/core/client_wrapper.py index 5b0c9d5ad91..8d01b584b82 100644 --- a/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/core/client_wrapper.py @@ -53,7 +53,12 @@ def __init__( httpx_client: httpx.Client, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): @@ -66,4 +71,9 @@ def __init__( httpx_client: httpx.AsyncClient, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/core/http_client.py b/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/core/http_client.py +++ b/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/endpoints/container/client.py b/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/endpoints/container/client.py index c5ab55847c7..e02bf812398 100644 --- a/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/endpoints/container/client.py +++ b/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/endpoints/container/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.object_with_required_field import ObjectWithRequiredField @@ -49,32 +45,7 @@ def get_and_return_list_of_primitives( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[str], _response.json()) # type: ignore @@ -88,7 +59,7 @@ def get_and_return_list_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -120,32 +91,7 @@ def get_and_return_list_of_objects( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -183,32 +129,7 @@ def get_and_return_set_of_primitives( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Set[str], _response.json()) # type: ignore @@ -222,7 +143,7 @@ def get_and_return_set_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -254,32 +175,7 @@ def get_and_return_set_of_objects( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -317,32 +213,7 @@ def get_and_return_map_prim_to_prim( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-prim"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-prim", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, str], _response.json()) # type: ignore @@ -356,7 +227,7 @@ def get_and_return_map_of_prim_to_object( self, *, request: typing.Dict[str, ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Dict[str, ObjectWithRequiredField]: """ Parameters @@ -388,32 +259,7 @@ def get_and_return_map_of_prim_to_object( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-object", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, ObjectWithRequiredField], _response.json()) # type: ignore @@ -427,7 +273,7 @@ def get_and_return_optional( self, *, request: typing.Optional[ObjectWithRequiredField] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Optional[ObjectWithRequiredField]: """ Parameters @@ -457,32 +303,7 @@ def get_and_return_optional( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/opt-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/opt-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Optional[ObjectWithRequiredField], _response.json()) # type: ignore @@ -525,32 +346,7 @@ async def get_and_return_list_of_primitives( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[str], _response.json()) # type: ignore @@ -564,7 +360,7 @@ async def get_and_return_list_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -596,32 +392,7 @@ async def get_and_return_list_of_objects( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -659,32 +430,7 @@ async def get_and_return_set_of_primitives( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Set[str], _response.json()) # type: ignore @@ -698,7 +444,7 @@ async def get_and_return_set_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -730,32 +476,7 @@ async def get_and_return_set_of_objects( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -793,32 +514,7 @@ async def get_and_return_map_prim_to_prim( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-prim"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-prim", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, str], _response.json()) # type: ignore @@ -832,7 +528,7 @@ async def get_and_return_map_of_prim_to_object( self, *, request: typing.Dict[str, ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Dict[str, ObjectWithRequiredField]: """ Parameters @@ -864,32 +560,7 @@ async def get_and_return_map_of_prim_to_object( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-object", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, ObjectWithRequiredField], _response.json()) # type: ignore @@ -903,7 +574,7 @@ async def get_and_return_optional( self, *, request: typing.Optional[ObjectWithRequiredField] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Optional[ObjectWithRequiredField]: """ Parameters @@ -933,32 +604,7 @@ async def get_and_return_optional( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/opt-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/opt-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Optional[ObjectWithRequiredField], _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/endpoints/enum/client.py b/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/endpoints/enum/client.py index 94ee2ac420f..8fcd0668b4b 100644 --- a/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/endpoints/enum/client.py +++ b/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/endpoints/enum/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.enum.types.weather_report import WeatherReport @@ -49,27 +45,7 @@ def get_and_return_enum( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "enum"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "enum", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(WeatherReport, _response.json()) # type: ignore @@ -112,27 +88,7 @@ async def get_and_return_enum( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "enum"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "enum", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(WeatherReport, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/endpoints/http_methods/client.py b/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/endpoints/http_methods/client.py index 1c8af11a4bd..3bd65f6adda 100644 --- a/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/endpoints/http_methods/client.py +++ b/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/endpoints/http_methods/client.py @@ -2,7 +2,6 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError @@ -10,8 +9,6 @@ from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.object_with_optional_field import ObjectWithOptionalField @@ -49,26 +46,7 @@ def test_get(self, id: str, *, request_options: typing.Optional[RequestOptions] ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -105,34 +83,8 @@ def test_post( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "http-methods"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "http-methods", method="POST", json={"string": string}, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -172,34 +124,12 @@ def test_put( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PUT", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -296,58 +226,25 @@ def test_patch( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PATCH", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -383,29 +280,7 @@ def test_delete(self, id: str, *, request_options: typing.Optional[RequestOption ) """ _response = self._client_wrapper.httpx_client.request( - method="DELETE", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="DELETE", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -446,26 +321,7 @@ async def test_get(self, id: str, *, request_options: typing.Optional[RequestOpt ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -502,34 +358,8 @@ async def test_post( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "http-methods"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "http-methods", method="POST", json={"string": string}, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -569,34 +399,12 @@ async def test_put( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PUT", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -693,58 +501,25 @@ async def test_patch( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = await self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PATCH", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -780,29 +555,7 @@ async def test_delete(self, id: str, *, request_options: typing.Optional[Request ) """ _response = await self._client_wrapper.httpx_client.request( - method="DELETE", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="DELETE", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/endpoints/object/client.py b/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/endpoints/object/client.py index 83230dec1f4..7e66510fdb0 100644 --- a/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/endpoints/object/client.py +++ b/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/endpoints/object/client.py @@ -2,7 +2,6 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError @@ -10,8 +9,6 @@ from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.nested_object_with_optional_field import NestedObjectWithOptionalField from ...types.object.types.nested_object_with_required_field import NestedObjectWithRequiredField @@ -110,60 +107,25 @@ def get_and_return_with_optional_field( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -200,36 +162,12 @@ def get_and_return_with_required_field( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-required-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-required-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithRequiredField, _response.json()) # type: ignore @@ -266,36 +204,12 @@ def get_and_return_with_map_of_map( map_={"string": {"string": "string"}}, ) """ - _request: typing.Dict[str, typing.Any] = {"map": map_} _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-map-of-map", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-map-of-map" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"map": map_}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithMapOfMap, _response.json()) # type: ignore @@ -362,40 +276,12 @@ def get_and_return_nested_with_optional_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if nested_object is not OMIT: - _request["NestedObject"] = nested_object _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithOptionalField, _response.json()) # type: ignore @@ -466,37 +352,12 @@ def get_and_return_nested_with_required_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {"string": string, "NestedObject": nested_object} _response = self._client_wrapper.httpx_client.request( + f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", - f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -565,34 +426,11 @@ def get_and_return_nested_with_required_field_as_list( ) """ _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-required-field-list", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-required-field-list" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -690,60 +528,25 @@ async def get_and_return_with_optional_field( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -780,36 +583,12 @@ async def get_and_return_with_required_field( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-required-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-required-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithRequiredField, _response.json()) # type: ignore @@ -846,36 +625,12 @@ async def get_and_return_with_map_of_map( map_={"string": {"string": "string"}}, ) """ - _request: typing.Dict[str, typing.Any] = {"map": map_} _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-map-of-map", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-map-of-map" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"map": map_}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithMapOfMap, _response.json()) # type: ignore @@ -942,40 +697,12 @@ async def get_and_return_nested_with_optional_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if nested_object is not OMIT: - _request["NestedObject"] = nested_object _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithOptionalField, _response.json()) # type: ignore @@ -1046,37 +773,12 @@ async def get_and_return_nested_with_required_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {"string": string, "NestedObject": nested_object} _response = await self._client_wrapper.httpx_client.request( + f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", - f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -1145,34 +847,11 @@ async def get_and_return_nested_with_required_field_as_list( ) """ _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-required-field-list", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-required-field-list" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/endpoints/params/client.py b/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/endpoints/params/client.py index d1f25df27fb..089d9fab5ce 100644 --- a/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/endpoints/params/client.py +++ b/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/endpoints/params/client.py @@ -1,15 +1,12 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -48,28 +45,7 @@ def get_with_path(self, param: str, *, request_options: typing.Optional[RequestO ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"params/path/{jsonable_encoder(param)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -112,36 +88,7 @@ def get_with_query( ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "number": number, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "number": number}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -188,36 +135,7 @@ def get_with_allow_multiple_query( ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "numer": numer, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "numer": numer}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -260,37 +178,10 @@ def get_with_path_and_query( ) """ _response = self._client_wrapper.httpx_client.request( + f"params/path-query/{jsonable_encoder(param)}", method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path-query/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"query": query}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -333,29 +224,11 @@ def modify_with_path( ) """ _response = self._client_wrapper.httpx_client.request( + f"params/path/{jsonable_encoder(param)}", method="PUT", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -398,28 +271,7 @@ async def get_with_path(self, param: str, *, request_options: typing.Optional[Re ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"params/path/{jsonable_encoder(param)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -462,36 +314,7 @@ async def get_with_query( ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "number": number, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "number": number}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -538,36 +361,7 @@ async def get_with_allow_multiple_query( ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "numer": numer, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "numer": numer}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -610,37 +404,10 @@ async def get_with_path_and_query( ) """ _response = await self._client_wrapper.httpx_client.request( + f"params/path-query/{jsonable_encoder(param)}", method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path-query/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"query": query}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -683,29 +450,11 @@ async def modify_with_path( ) """ _response = await self._client_wrapper.httpx_client.request( + f"params/path/{jsonable_encoder(param)}", method="PUT", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/endpoints/primitive/client.py b/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/endpoints/primitive/client.py index 076383510ff..64c7f6b2ca5 100644 --- a/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/endpoints/primitive/client.py +++ b/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/endpoints/primitive/client.py @@ -2,16 +2,12 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -48,27 +44,7 @@ def get_and_return_string(self, *, request: str, request_options: typing.Optiona ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/string"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/string", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -104,27 +80,7 @@ def get_and_return_int(self, *, request: int, request_options: typing.Optional[R ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/integer"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/integer", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -160,32 +116,7 @@ def get_and_return_long(self, *, request: int, request_options: typing.Optional[ ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/long"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/long", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -223,27 +154,7 @@ def get_and_return_double( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/double"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/double", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(float, _response.json()) # type: ignore @@ -279,27 +190,7 @@ def get_and_return_bool(self, *, request: bool, request_options: typing.Optional ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/boolean"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/boolean", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -341,32 +232,7 @@ def get_and_return_datetime( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/datetime"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/datetime", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.datetime, _response.json()) # type: ignore @@ -408,32 +274,7 @@ def get_and_return_date( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/date"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/date", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.date, _response.json()) # type: ignore @@ -475,32 +316,7 @@ def get_and_return_uuid( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/uuid"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/uuid", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(uuid.UUID, _response.json()) # type: ignore @@ -536,32 +352,7 @@ def get_and_return_base_64(self, *, request: str, request_options: typing.Option ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/base64"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/base64", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -604,27 +395,7 @@ async def get_and_return_string( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/string"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/string", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -660,27 +431,7 @@ async def get_and_return_int(self, *, request: int, request_options: typing.Opti ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/integer"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/integer", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -718,32 +469,7 @@ async def get_and_return_long( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/long"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/long", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -781,27 +507,7 @@ async def get_and_return_double( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/double"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/double", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(float, _response.json()) # type: ignore @@ -839,27 +545,7 @@ async def get_and_return_bool( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/boolean"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/boolean", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -901,32 +587,7 @@ async def get_and_return_datetime( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/datetime"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/datetime", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.datetime, _response.json()) # type: ignore @@ -968,32 +629,7 @@ async def get_and_return_date( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/date"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/date", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.date, _response.json()) # type: ignore @@ -1035,32 +671,7 @@ async def get_and_return_uuid( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/uuid"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/uuid", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(uuid.UUID, _response.json()) # type: ignore @@ -1098,32 +709,7 @@ async def get_and_return_base_64( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/base64"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/base64", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/endpoints/union/client.py b/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/endpoints/union/client.py index 23757c07bd8..843d9828bc6 100644 --- a/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/endpoints/union/client.py +++ b/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/endpoints/union/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.union.types.animal import Animal @@ -53,32 +49,7 @@ def get_and_return_union( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "union"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "union", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Animal, _response.json()) # type: ignore @@ -125,32 +96,7 @@ async def get_and_return_union( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "union"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "union", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Animal, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/inlined_requests/client.py b/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/inlined_requests/client.py index 38e428f66e0..bfb17877f08 100644 --- a/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/inlined_requests/client.py +++ b/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/inlined_requests/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..general_errors.errors.bad_request_body import BadRequestBody from ..general_errors.types.bad_object_request_info import BadObjectRequestInfo @@ -29,7 +25,7 @@ def post_with_object_bodyand_response( string: str, integer: int, nested_object: ObjectWithOptionalField, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> ObjectWithOptionalField: """ POST with custom object in request body, response is an object @@ -87,32 +83,11 @@ def post_with_object_bodyand_response( ) """ _response = self._client_wrapper.httpx_client.request( + "req-bodies/object", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "req-bodies/object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "integer": integer, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -135,7 +110,7 @@ async def post_with_object_bodyand_response( string: str, integer: int, nested_object: ObjectWithOptionalField, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> ObjectWithOptionalField: """ POST with custom object in request body, response is an object @@ -193,32 +168,11 @@ async def post_with_object_bodyand_response( ) """ _response = await self._client_wrapper.httpx_client.request( + "req-bodies/object", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "req-bodies/object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "integer": integer, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/no_auth/client.py b/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/no_auth/client.py index fd4814dde0b..477bf563998 100644 --- a/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/no_auth/client.py +++ b/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/no_auth/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..general_errors.errors.bad_request_body import BadRequestBody from ..general_errors.types.bad_object_request_info import BadObjectRequestInfo @@ -52,32 +48,7 @@ def post_with_no_auth( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-auth", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -124,32 +95,7 @@ async def post_with_no_auth( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-auth", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/no_req_body/client.py b/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/no_req_body/client.py index f984b6c24d3..7e3fd3ae95f 100644 --- a/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/no_req_body/client.py +++ b/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/no_req_body/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..types.object.types.object_with_optional_field import ObjectWithOptionalField @@ -42,26 +38,7 @@ def get_with_no_request_body( client.no_req_body.get_with_no_request_body() """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -93,29 +70,7 @@ def post_with_no_request_body(self, *, request_options: typing.Optional[RequestO client.no_req_body.post_with_no_request_body() """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -154,26 +109,7 @@ async def get_with_no_request_body( await client.no_req_body.get_with_no_request_body() """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -205,29 +141,7 @@ async def post_with_no_request_body(self, *, request_options: typing.Optional[Re await client.no_req_body.post_with_no_request_body() """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/req_with_headers/client.py b/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/req_with_headers/client.py index 3e7f80e7435..4ec08e7ee09 100644 --- a/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/req_with_headers/client.py +++ b/seed/python-sdk/exhaustive/deps_with_min_python_version/src/seed/req_with_headers/client.py @@ -1,14 +1,10 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -25,7 +21,7 @@ def get_with_custom_header( x_test_service_header: str, x_test_endpoint_header: str, request: str, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -58,33 +54,15 @@ def get_with_custom_header( ) """ _response = self._client_wrapper.httpx_client.request( + "test-headers/custom-header", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "test-headers/custom-header"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-TEST-SERVICE-HEADER": str(x_test_service_header) - if x_test_service_header is not None - else None, - "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) - if x_test_endpoint_header is not None - else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + headers={ + "X-TEST-SERVICE-HEADER": str(x_test_service_header) if x_test_service_header is not None else None, + "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) if x_test_endpoint_header is not None else None, + }, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return @@ -105,7 +83,7 @@ async def get_with_custom_header( x_test_service_header: str, x_test_endpoint_header: str, request: str, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -138,33 +116,15 @@ async def get_with_custom_header( ) """ _response = await self._client_wrapper.httpx_client.request( + "test-headers/custom-header", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "test-headers/custom-header"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-TEST-SERVICE-HEADER": str(x_test_service_header) - if x_test_service_header is not None - else None, - "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) - if x_test_endpoint_header is not None - else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + headers={ + "X-TEST-SERVICE-HEADER": str(x_test_service_header) if x_test_service_header is not None else None, + "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) if x_test_endpoint_header is not None else None, + }, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return diff --git a/seed/python-sdk/exhaustive/extra_dependencies/src/seed/core/client_wrapper.py b/seed/python-sdk/exhaustive/extra_dependencies/src/seed/core/client_wrapper.py index 5b0c9d5ad91..8d01b584b82 100644 --- a/seed/python-sdk/exhaustive/extra_dependencies/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/exhaustive/extra_dependencies/src/seed/core/client_wrapper.py @@ -53,7 +53,12 @@ def __init__( httpx_client: httpx.Client, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): @@ -66,4 +71,9 @@ def __init__( httpx_client: httpx.AsyncClient, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/exhaustive/extra_dependencies/src/seed/core/http_client.py b/seed/python-sdk/exhaustive/extra_dependencies/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/exhaustive/extra_dependencies/src/seed/core/http_client.py +++ b/seed/python-sdk/exhaustive/extra_dependencies/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/exhaustive/extra_dependencies/src/seed/endpoints/container/client.py b/seed/python-sdk/exhaustive/extra_dependencies/src/seed/endpoints/container/client.py index c5ab55847c7..e02bf812398 100644 --- a/seed/python-sdk/exhaustive/extra_dependencies/src/seed/endpoints/container/client.py +++ b/seed/python-sdk/exhaustive/extra_dependencies/src/seed/endpoints/container/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.object_with_required_field import ObjectWithRequiredField @@ -49,32 +45,7 @@ def get_and_return_list_of_primitives( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[str], _response.json()) # type: ignore @@ -88,7 +59,7 @@ def get_and_return_list_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -120,32 +91,7 @@ def get_and_return_list_of_objects( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -183,32 +129,7 @@ def get_and_return_set_of_primitives( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Set[str], _response.json()) # type: ignore @@ -222,7 +143,7 @@ def get_and_return_set_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -254,32 +175,7 @@ def get_and_return_set_of_objects( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -317,32 +213,7 @@ def get_and_return_map_prim_to_prim( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-prim"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-prim", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, str], _response.json()) # type: ignore @@ -356,7 +227,7 @@ def get_and_return_map_of_prim_to_object( self, *, request: typing.Dict[str, ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Dict[str, ObjectWithRequiredField]: """ Parameters @@ -388,32 +259,7 @@ def get_and_return_map_of_prim_to_object( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-object", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, ObjectWithRequiredField], _response.json()) # type: ignore @@ -427,7 +273,7 @@ def get_and_return_optional( self, *, request: typing.Optional[ObjectWithRequiredField] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Optional[ObjectWithRequiredField]: """ Parameters @@ -457,32 +303,7 @@ def get_and_return_optional( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/opt-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/opt-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Optional[ObjectWithRequiredField], _response.json()) # type: ignore @@ -525,32 +346,7 @@ async def get_and_return_list_of_primitives( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[str], _response.json()) # type: ignore @@ -564,7 +360,7 @@ async def get_and_return_list_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -596,32 +392,7 @@ async def get_and_return_list_of_objects( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -659,32 +430,7 @@ async def get_and_return_set_of_primitives( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Set[str], _response.json()) # type: ignore @@ -698,7 +444,7 @@ async def get_and_return_set_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -730,32 +476,7 @@ async def get_and_return_set_of_objects( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -793,32 +514,7 @@ async def get_and_return_map_prim_to_prim( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-prim"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-prim", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, str], _response.json()) # type: ignore @@ -832,7 +528,7 @@ async def get_and_return_map_of_prim_to_object( self, *, request: typing.Dict[str, ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Dict[str, ObjectWithRequiredField]: """ Parameters @@ -864,32 +560,7 @@ async def get_and_return_map_of_prim_to_object( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-object", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, ObjectWithRequiredField], _response.json()) # type: ignore @@ -903,7 +574,7 @@ async def get_and_return_optional( self, *, request: typing.Optional[ObjectWithRequiredField] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Optional[ObjectWithRequiredField]: """ Parameters @@ -933,32 +604,7 @@ async def get_and_return_optional( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/opt-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/opt-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Optional[ObjectWithRequiredField], _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/extra_dependencies/src/seed/endpoints/enum/client.py b/seed/python-sdk/exhaustive/extra_dependencies/src/seed/endpoints/enum/client.py index 94ee2ac420f..8fcd0668b4b 100644 --- a/seed/python-sdk/exhaustive/extra_dependencies/src/seed/endpoints/enum/client.py +++ b/seed/python-sdk/exhaustive/extra_dependencies/src/seed/endpoints/enum/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.enum.types.weather_report import WeatherReport @@ -49,27 +45,7 @@ def get_and_return_enum( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "enum"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "enum", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(WeatherReport, _response.json()) # type: ignore @@ -112,27 +88,7 @@ async def get_and_return_enum( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "enum"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "enum", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(WeatherReport, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/extra_dependencies/src/seed/endpoints/http_methods/client.py b/seed/python-sdk/exhaustive/extra_dependencies/src/seed/endpoints/http_methods/client.py index 1c8af11a4bd..3bd65f6adda 100644 --- a/seed/python-sdk/exhaustive/extra_dependencies/src/seed/endpoints/http_methods/client.py +++ b/seed/python-sdk/exhaustive/extra_dependencies/src/seed/endpoints/http_methods/client.py @@ -2,7 +2,6 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError @@ -10,8 +9,6 @@ from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.object_with_optional_field import ObjectWithOptionalField @@ -49,26 +46,7 @@ def test_get(self, id: str, *, request_options: typing.Optional[RequestOptions] ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -105,34 +83,8 @@ def test_post( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "http-methods"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "http-methods", method="POST", json={"string": string}, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -172,34 +124,12 @@ def test_put( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PUT", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -296,58 +226,25 @@ def test_patch( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PATCH", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -383,29 +280,7 @@ def test_delete(self, id: str, *, request_options: typing.Optional[RequestOption ) """ _response = self._client_wrapper.httpx_client.request( - method="DELETE", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="DELETE", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -446,26 +321,7 @@ async def test_get(self, id: str, *, request_options: typing.Optional[RequestOpt ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -502,34 +358,8 @@ async def test_post( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "http-methods"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "http-methods", method="POST", json={"string": string}, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -569,34 +399,12 @@ async def test_put( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PUT", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -693,58 +501,25 @@ async def test_patch( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = await self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PATCH", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -780,29 +555,7 @@ async def test_delete(self, id: str, *, request_options: typing.Optional[Request ) """ _response = await self._client_wrapper.httpx_client.request( - method="DELETE", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="DELETE", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/extra_dependencies/src/seed/endpoints/object/client.py b/seed/python-sdk/exhaustive/extra_dependencies/src/seed/endpoints/object/client.py index 83230dec1f4..7e66510fdb0 100644 --- a/seed/python-sdk/exhaustive/extra_dependencies/src/seed/endpoints/object/client.py +++ b/seed/python-sdk/exhaustive/extra_dependencies/src/seed/endpoints/object/client.py @@ -2,7 +2,6 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError @@ -10,8 +9,6 @@ from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.nested_object_with_optional_field import NestedObjectWithOptionalField from ...types.object.types.nested_object_with_required_field import NestedObjectWithRequiredField @@ -110,60 +107,25 @@ def get_and_return_with_optional_field( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -200,36 +162,12 @@ def get_and_return_with_required_field( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-required-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-required-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithRequiredField, _response.json()) # type: ignore @@ -266,36 +204,12 @@ def get_and_return_with_map_of_map( map_={"string": {"string": "string"}}, ) """ - _request: typing.Dict[str, typing.Any] = {"map": map_} _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-map-of-map", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-map-of-map" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"map": map_}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithMapOfMap, _response.json()) # type: ignore @@ -362,40 +276,12 @@ def get_and_return_nested_with_optional_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if nested_object is not OMIT: - _request["NestedObject"] = nested_object _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithOptionalField, _response.json()) # type: ignore @@ -466,37 +352,12 @@ def get_and_return_nested_with_required_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {"string": string, "NestedObject": nested_object} _response = self._client_wrapper.httpx_client.request( + f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", - f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -565,34 +426,11 @@ def get_and_return_nested_with_required_field_as_list( ) """ _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-required-field-list", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-required-field-list" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -690,60 +528,25 @@ async def get_and_return_with_optional_field( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -780,36 +583,12 @@ async def get_and_return_with_required_field( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-required-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-required-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithRequiredField, _response.json()) # type: ignore @@ -846,36 +625,12 @@ async def get_and_return_with_map_of_map( map_={"string": {"string": "string"}}, ) """ - _request: typing.Dict[str, typing.Any] = {"map": map_} _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-map-of-map", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-map-of-map" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"map": map_}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithMapOfMap, _response.json()) # type: ignore @@ -942,40 +697,12 @@ async def get_and_return_nested_with_optional_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if nested_object is not OMIT: - _request["NestedObject"] = nested_object _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithOptionalField, _response.json()) # type: ignore @@ -1046,37 +773,12 @@ async def get_and_return_nested_with_required_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {"string": string, "NestedObject": nested_object} _response = await self._client_wrapper.httpx_client.request( + f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", - f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -1145,34 +847,11 @@ async def get_and_return_nested_with_required_field_as_list( ) """ _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-required-field-list", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-required-field-list" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/extra_dependencies/src/seed/endpoints/params/client.py b/seed/python-sdk/exhaustive/extra_dependencies/src/seed/endpoints/params/client.py index d1f25df27fb..089d9fab5ce 100644 --- a/seed/python-sdk/exhaustive/extra_dependencies/src/seed/endpoints/params/client.py +++ b/seed/python-sdk/exhaustive/extra_dependencies/src/seed/endpoints/params/client.py @@ -1,15 +1,12 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -48,28 +45,7 @@ def get_with_path(self, param: str, *, request_options: typing.Optional[RequestO ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"params/path/{jsonable_encoder(param)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -112,36 +88,7 @@ def get_with_query( ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "number": number, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "number": number}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -188,36 +135,7 @@ def get_with_allow_multiple_query( ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "numer": numer, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "numer": numer}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -260,37 +178,10 @@ def get_with_path_and_query( ) """ _response = self._client_wrapper.httpx_client.request( + f"params/path-query/{jsonable_encoder(param)}", method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path-query/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"query": query}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -333,29 +224,11 @@ def modify_with_path( ) """ _response = self._client_wrapper.httpx_client.request( + f"params/path/{jsonable_encoder(param)}", method="PUT", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -398,28 +271,7 @@ async def get_with_path(self, param: str, *, request_options: typing.Optional[Re ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"params/path/{jsonable_encoder(param)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -462,36 +314,7 @@ async def get_with_query( ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "number": number, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "number": number}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -538,36 +361,7 @@ async def get_with_allow_multiple_query( ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "numer": numer, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "numer": numer}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -610,37 +404,10 @@ async def get_with_path_and_query( ) """ _response = await self._client_wrapper.httpx_client.request( + f"params/path-query/{jsonable_encoder(param)}", method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path-query/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"query": query}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -683,29 +450,11 @@ async def modify_with_path( ) """ _response = await self._client_wrapper.httpx_client.request( + f"params/path/{jsonable_encoder(param)}", method="PUT", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/extra_dependencies/src/seed/endpoints/primitive/client.py b/seed/python-sdk/exhaustive/extra_dependencies/src/seed/endpoints/primitive/client.py index 076383510ff..64c7f6b2ca5 100644 --- a/seed/python-sdk/exhaustive/extra_dependencies/src/seed/endpoints/primitive/client.py +++ b/seed/python-sdk/exhaustive/extra_dependencies/src/seed/endpoints/primitive/client.py @@ -2,16 +2,12 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -48,27 +44,7 @@ def get_and_return_string(self, *, request: str, request_options: typing.Optiona ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/string"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/string", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -104,27 +80,7 @@ def get_and_return_int(self, *, request: int, request_options: typing.Optional[R ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/integer"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/integer", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -160,32 +116,7 @@ def get_and_return_long(self, *, request: int, request_options: typing.Optional[ ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/long"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/long", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -223,27 +154,7 @@ def get_and_return_double( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/double"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/double", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(float, _response.json()) # type: ignore @@ -279,27 +190,7 @@ def get_and_return_bool(self, *, request: bool, request_options: typing.Optional ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/boolean"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/boolean", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -341,32 +232,7 @@ def get_and_return_datetime( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/datetime"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/datetime", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.datetime, _response.json()) # type: ignore @@ -408,32 +274,7 @@ def get_and_return_date( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/date"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/date", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.date, _response.json()) # type: ignore @@ -475,32 +316,7 @@ def get_and_return_uuid( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/uuid"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/uuid", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(uuid.UUID, _response.json()) # type: ignore @@ -536,32 +352,7 @@ def get_and_return_base_64(self, *, request: str, request_options: typing.Option ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/base64"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/base64", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -604,27 +395,7 @@ async def get_and_return_string( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/string"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/string", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -660,27 +431,7 @@ async def get_and_return_int(self, *, request: int, request_options: typing.Opti ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/integer"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/integer", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -718,32 +469,7 @@ async def get_and_return_long( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/long"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/long", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -781,27 +507,7 @@ async def get_and_return_double( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/double"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/double", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(float, _response.json()) # type: ignore @@ -839,27 +545,7 @@ async def get_and_return_bool( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/boolean"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/boolean", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -901,32 +587,7 @@ async def get_and_return_datetime( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/datetime"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/datetime", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.datetime, _response.json()) # type: ignore @@ -968,32 +629,7 @@ async def get_and_return_date( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/date"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/date", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.date, _response.json()) # type: ignore @@ -1035,32 +671,7 @@ async def get_and_return_uuid( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/uuid"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/uuid", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(uuid.UUID, _response.json()) # type: ignore @@ -1098,32 +709,7 @@ async def get_and_return_base_64( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/base64"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/base64", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/extra_dependencies/src/seed/endpoints/union/client.py b/seed/python-sdk/exhaustive/extra_dependencies/src/seed/endpoints/union/client.py index 23757c07bd8..843d9828bc6 100644 --- a/seed/python-sdk/exhaustive/extra_dependencies/src/seed/endpoints/union/client.py +++ b/seed/python-sdk/exhaustive/extra_dependencies/src/seed/endpoints/union/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.union.types.animal import Animal @@ -53,32 +49,7 @@ def get_and_return_union( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "union"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "union", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Animal, _response.json()) # type: ignore @@ -125,32 +96,7 @@ async def get_and_return_union( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "union"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "union", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Animal, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/extra_dependencies/src/seed/inlined_requests/client.py b/seed/python-sdk/exhaustive/extra_dependencies/src/seed/inlined_requests/client.py index 38e428f66e0..bfb17877f08 100644 --- a/seed/python-sdk/exhaustive/extra_dependencies/src/seed/inlined_requests/client.py +++ b/seed/python-sdk/exhaustive/extra_dependencies/src/seed/inlined_requests/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..general_errors.errors.bad_request_body import BadRequestBody from ..general_errors.types.bad_object_request_info import BadObjectRequestInfo @@ -29,7 +25,7 @@ def post_with_object_bodyand_response( string: str, integer: int, nested_object: ObjectWithOptionalField, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> ObjectWithOptionalField: """ POST with custom object in request body, response is an object @@ -87,32 +83,11 @@ def post_with_object_bodyand_response( ) """ _response = self._client_wrapper.httpx_client.request( + "req-bodies/object", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "req-bodies/object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "integer": integer, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -135,7 +110,7 @@ async def post_with_object_bodyand_response( string: str, integer: int, nested_object: ObjectWithOptionalField, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> ObjectWithOptionalField: """ POST with custom object in request body, response is an object @@ -193,32 +168,11 @@ async def post_with_object_bodyand_response( ) """ _response = await self._client_wrapper.httpx_client.request( + "req-bodies/object", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "req-bodies/object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "integer": integer, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/extra_dependencies/src/seed/no_auth/client.py b/seed/python-sdk/exhaustive/extra_dependencies/src/seed/no_auth/client.py index fd4814dde0b..477bf563998 100644 --- a/seed/python-sdk/exhaustive/extra_dependencies/src/seed/no_auth/client.py +++ b/seed/python-sdk/exhaustive/extra_dependencies/src/seed/no_auth/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..general_errors.errors.bad_request_body import BadRequestBody from ..general_errors.types.bad_object_request_info import BadObjectRequestInfo @@ -52,32 +48,7 @@ def post_with_no_auth( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-auth", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -124,32 +95,7 @@ async def post_with_no_auth( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-auth", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/extra_dependencies/src/seed/no_req_body/client.py b/seed/python-sdk/exhaustive/extra_dependencies/src/seed/no_req_body/client.py index f984b6c24d3..7e3fd3ae95f 100644 --- a/seed/python-sdk/exhaustive/extra_dependencies/src/seed/no_req_body/client.py +++ b/seed/python-sdk/exhaustive/extra_dependencies/src/seed/no_req_body/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..types.object.types.object_with_optional_field import ObjectWithOptionalField @@ -42,26 +38,7 @@ def get_with_no_request_body( client.no_req_body.get_with_no_request_body() """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -93,29 +70,7 @@ def post_with_no_request_body(self, *, request_options: typing.Optional[RequestO client.no_req_body.post_with_no_request_body() """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -154,26 +109,7 @@ async def get_with_no_request_body( await client.no_req_body.get_with_no_request_body() """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -205,29 +141,7 @@ async def post_with_no_request_body(self, *, request_options: typing.Optional[Re await client.no_req_body.post_with_no_request_body() """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/extra_dependencies/src/seed/req_with_headers/client.py b/seed/python-sdk/exhaustive/extra_dependencies/src/seed/req_with_headers/client.py index 3e7f80e7435..4ec08e7ee09 100644 --- a/seed/python-sdk/exhaustive/extra_dependencies/src/seed/req_with_headers/client.py +++ b/seed/python-sdk/exhaustive/extra_dependencies/src/seed/req_with_headers/client.py @@ -1,14 +1,10 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -25,7 +21,7 @@ def get_with_custom_header( x_test_service_header: str, x_test_endpoint_header: str, request: str, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -58,33 +54,15 @@ def get_with_custom_header( ) """ _response = self._client_wrapper.httpx_client.request( + "test-headers/custom-header", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "test-headers/custom-header"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-TEST-SERVICE-HEADER": str(x_test_service_header) - if x_test_service_header is not None - else None, - "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) - if x_test_endpoint_header is not None - else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + headers={ + "X-TEST-SERVICE-HEADER": str(x_test_service_header) if x_test_service_header is not None else None, + "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) if x_test_endpoint_header is not None else None, + }, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return @@ -105,7 +83,7 @@ async def get_with_custom_header( x_test_service_header: str, x_test_endpoint_header: str, request: str, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -138,33 +116,15 @@ async def get_with_custom_header( ) """ _response = await self._client_wrapper.httpx_client.request( + "test-headers/custom-header", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "test-headers/custom-header"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-TEST-SERVICE-HEADER": str(x_test_service_header) - if x_test_service_header is not None - else None, - "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) - if x_test_endpoint_header is not None - else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + headers={ + "X-TEST-SERVICE-HEADER": str(x_test_service_header) if x_test_service_header is not None else None, + "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) if x_test_endpoint_header is not None else None, + }, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return diff --git a/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/core/client_wrapper.py b/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/core/client_wrapper.py index 5b0c9d5ad91..8d01b584b82 100644 --- a/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/core/client_wrapper.py @@ -53,7 +53,12 @@ def __init__( httpx_client: httpx.Client, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): @@ -66,4 +71,9 @@ def __init__( httpx_client: httpx.AsyncClient, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/core/http_client.py b/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/core/http_client.py +++ b/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/endpoints/container/client.py b/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/endpoints/container/client.py index c5ab55847c7..e02bf812398 100644 --- a/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/endpoints/container/client.py +++ b/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/endpoints/container/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.object_with_required_field import ObjectWithRequiredField @@ -49,32 +45,7 @@ def get_and_return_list_of_primitives( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[str], _response.json()) # type: ignore @@ -88,7 +59,7 @@ def get_and_return_list_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -120,32 +91,7 @@ def get_and_return_list_of_objects( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -183,32 +129,7 @@ def get_and_return_set_of_primitives( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Set[str], _response.json()) # type: ignore @@ -222,7 +143,7 @@ def get_and_return_set_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -254,32 +175,7 @@ def get_and_return_set_of_objects( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -317,32 +213,7 @@ def get_and_return_map_prim_to_prim( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-prim"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-prim", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, str], _response.json()) # type: ignore @@ -356,7 +227,7 @@ def get_and_return_map_of_prim_to_object( self, *, request: typing.Dict[str, ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Dict[str, ObjectWithRequiredField]: """ Parameters @@ -388,32 +259,7 @@ def get_and_return_map_of_prim_to_object( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-object", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, ObjectWithRequiredField], _response.json()) # type: ignore @@ -427,7 +273,7 @@ def get_and_return_optional( self, *, request: typing.Optional[ObjectWithRequiredField] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Optional[ObjectWithRequiredField]: """ Parameters @@ -457,32 +303,7 @@ def get_and_return_optional( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/opt-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/opt-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Optional[ObjectWithRequiredField], _response.json()) # type: ignore @@ -525,32 +346,7 @@ async def get_and_return_list_of_primitives( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[str], _response.json()) # type: ignore @@ -564,7 +360,7 @@ async def get_and_return_list_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -596,32 +392,7 @@ async def get_and_return_list_of_objects( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -659,32 +430,7 @@ async def get_and_return_set_of_primitives( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Set[str], _response.json()) # type: ignore @@ -698,7 +444,7 @@ async def get_and_return_set_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -730,32 +476,7 @@ async def get_and_return_set_of_objects( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -793,32 +514,7 @@ async def get_and_return_map_prim_to_prim( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-prim"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-prim", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, str], _response.json()) # type: ignore @@ -832,7 +528,7 @@ async def get_and_return_map_of_prim_to_object( self, *, request: typing.Dict[str, ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Dict[str, ObjectWithRequiredField]: """ Parameters @@ -864,32 +560,7 @@ async def get_and_return_map_of_prim_to_object( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-object", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, ObjectWithRequiredField], _response.json()) # type: ignore @@ -903,7 +574,7 @@ async def get_and_return_optional( self, *, request: typing.Optional[ObjectWithRequiredField] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Optional[ObjectWithRequiredField]: """ Parameters @@ -933,32 +604,7 @@ async def get_and_return_optional( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/opt-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/opt-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Optional[ObjectWithRequiredField], _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/endpoints/enum/client.py b/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/endpoints/enum/client.py index 94ee2ac420f..8fcd0668b4b 100644 --- a/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/endpoints/enum/client.py +++ b/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/endpoints/enum/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.enum.types.weather_report import WeatherReport @@ -49,27 +45,7 @@ def get_and_return_enum( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "enum"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "enum", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(WeatherReport, _response.json()) # type: ignore @@ -112,27 +88,7 @@ async def get_and_return_enum( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "enum"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "enum", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(WeatherReport, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/endpoints/http_methods/client.py b/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/endpoints/http_methods/client.py index 1c8af11a4bd..3bd65f6adda 100644 --- a/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/endpoints/http_methods/client.py +++ b/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/endpoints/http_methods/client.py @@ -2,7 +2,6 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError @@ -10,8 +9,6 @@ from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.object_with_optional_field import ObjectWithOptionalField @@ -49,26 +46,7 @@ def test_get(self, id: str, *, request_options: typing.Optional[RequestOptions] ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -105,34 +83,8 @@ def test_post( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "http-methods"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "http-methods", method="POST", json={"string": string}, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -172,34 +124,12 @@ def test_put( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PUT", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -296,58 +226,25 @@ def test_patch( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PATCH", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -383,29 +280,7 @@ def test_delete(self, id: str, *, request_options: typing.Optional[RequestOption ) """ _response = self._client_wrapper.httpx_client.request( - method="DELETE", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="DELETE", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -446,26 +321,7 @@ async def test_get(self, id: str, *, request_options: typing.Optional[RequestOpt ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -502,34 +358,8 @@ async def test_post( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "http-methods"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "http-methods", method="POST", json={"string": string}, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -569,34 +399,12 @@ async def test_put( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PUT", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -693,58 +501,25 @@ async def test_patch( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = await self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PATCH", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -780,29 +555,7 @@ async def test_delete(self, id: str, *, request_options: typing.Optional[Request ) """ _response = await self._client_wrapper.httpx_client.request( - method="DELETE", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="DELETE", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/endpoints/object/client.py b/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/endpoints/object/client.py index 83230dec1f4..7e66510fdb0 100644 --- a/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/endpoints/object/client.py +++ b/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/endpoints/object/client.py @@ -2,7 +2,6 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError @@ -10,8 +9,6 @@ from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.nested_object_with_optional_field import NestedObjectWithOptionalField from ...types.object.types.nested_object_with_required_field import NestedObjectWithRequiredField @@ -110,60 +107,25 @@ def get_and_return_with_optional_field( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -200,36 +162,12 @@ def get_and_return_with_required_field( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-required-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-required-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithRequiredField, _response.json()) # type: ignore @@ -266,36 +204,12 @@ def get_and_return_with_map_of_map( map_={"string": {"string": "string"}}, ) """ - _request: typing.Dict[str, typing.Any] = {"map": map_} _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-map-of-map", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-map-of-map" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"map": map_}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithMapOfMap, _response.json()) # type: ignore @@ -362,40 +276,12 @@ def get_and_return_nested_with_optional_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if nested_object is not OMIT: - _request["NestedObject"] = nested_object _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithOptionalField, _response.json()) # type: ignore @@ -466,37 +352,12 @@ def get_and_return_nested_with_required_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {"string": string, "NestedObject": nested_object} _response = self._client_wrapper.httpx_client.request( + f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", - f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -565,34 +426,11 @@ def get_and_return_nested_with_required_field_as_list( ) """ _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-required-field-list", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-required-field-list" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -690,60 +528,25 @@ async def get_and_return_with_optional_field( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -780,36 +583,12 @@ async def get_and_return_with_required_field( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-required-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-required-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithRequiredField, _response.json()) # type: ignore @@ -846,36 +625,12 @@ async def get_and_return_with_map_of_map( map_={"string": {"string": "string"}}, ) """ - _request: typing.Dict[str, typing.Any] = {"map": map_} _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-map-of-map", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-map-of-map" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"map": map_}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithMapOfMap, _response.json()) # type: ignore @@ -942,40 +697,12 @@ async def get_and_return_nested_with_optional_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if nested_object is not OMIT: - _request["NestedObject"] = nested_object _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithOptionalField, _response.json()) # type: ignore @@ -1046,37 +773,12 @@ async def get_and_return_nested_with_required_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {"string": string, "NestedObject": nested_object} _response = await self._client_wrapper.httpx_client.request( + f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", - f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -1145,34 +847,11 @@ async def get_and_return_nested_with_required_field_as_list( ) """ _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-required-field-list", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-required-field-list" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/endpoints/params/client.py b/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/endpoints/params/client.py index d1f25df27fb..089d9fab5ce 100644 --- a/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/endpoints/params/client.py +++ b/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/endpoints/params/client.py @@ -1,15 +1,12 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -48,28 +45,7 @@ def get_with_path(self, param: str, *, request_options: typing.Optional[RequestO ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"params/path/{jsonable_encoder(param)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -112,36 +88,7 @@ def get_with_query( ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "number": number, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "number": number}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -188,36 +135,7 @@ def get_with_allow_multiple_query( ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "numer": numer, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "numer": numer}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -260,37 +178,10 @@ def get_with_path_and_query( ) """ _response = self._client_wrapper.httpx_client.request( + f"params/path-query/{jsonable_encoder(param)}", method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path-query/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"query": query}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -333,29 +224,11 @@ def modify_with_path( ) """ _response = self._client_wrapper.httpx_client.request( + f"params/path/{jsonable_encoder(param)}", method="PUT", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -398,28 +271,7 @@ async def get_with_path(self, param: str, *, request_options: typing.Optional[Re ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"params/path/{jsonable_encoder(param)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -462,36 +314,7 @@ async def get_with_query( ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "number": number, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "number": number}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -538,36 +361,7 @@ async def get_with_allow_multiple_query( ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "numer": numer, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "numer": numer}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -610,37 +404,10 @@ async def get_with_path_and_query( ) """ _response = await self._client_wrapper.httpx_client.request( + f"params/path-query/{jsonable_encoder(param)}", method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path-query/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"query": query}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -683,29 +450,11 @@ async def modify_with_path( ) """ _response = await self._client_wrapper.httpx_client.request( + f"params/path/{jsonable_encoder(param)}", method="PUT", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/endpoints/primitive/client.py b/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/endpoints/primitive/client.py index 076383510ff..64c7f6b2ca5 100644 --- a/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/endpoints/primitive/client.py +++ b/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/endpoints/primitive/client.py @@ -2,16 +2,12 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -48,27 +44,7 @@ def get_and_return_string(self, *, request: str, request_options: typing.Optiona ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/string"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/string", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -104,27 +80,7 @@ def get_and_return_int(self, *, request: int, request_options: typing.Optional[R ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/integer"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/integer", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -160,32 +116,7 @@ def get_and_return_long(self, *, request: int, request_options: typing.Optional[ ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/long"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/long", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -223,27 +154,7 @@ def get_and_return_double( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/double"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/double", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(float, _response.json()) # type: ignore @@ -279,27 +190,7 @@ def get_and_return_bool(self, *, request: bool, request_options: typing.Optional ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/boolean"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/boolean", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -341,32 +232,7 @@ def get_and_return_datetime( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/datetime"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/datetime", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.datetime, _response.json()) # type: ignore @@ -408,32 +274,7 @@ def get_and_return_date( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/date"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/date", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.date, _response.json()) # type: ignore @@ -475,32 +316,7 @@ def get_and_return_uuid( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/uuid"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/uuid", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(uuid.UUID, _response.json()) # type: ignore @@ -536,32 +352,7 @@ def get_and_return_base_64(self, *, request: str, request_options: typing.Option ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/base64"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/base64", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -604,27 +395,7 @@ async def get_and_return_string( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/string"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/string", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -660,27 +431,7 @@ async def get_and_return_int(self, *, request: int, request_options: typing.Opti ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/integer"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/integer", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -718,32 +469,7 @@ async def get_and_return_long( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/long"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/long", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -781,27 +507,7 @@ async def get_and_return_double( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/double"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/double", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(float, _response.json()) # type: ignore @@ -839,27 +545,7 @@ async def get_and_return_bool( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/boolean"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/boolean", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -901,32 +587,7 @@ async def get_and_return_datetime( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/datetime"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/datetime", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.datetime, _response.json()) # type: ignore @@ -968,32 +629,7 @@ async def get_and_return_date( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/date"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/date", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.date, _response.json()) # type: ignore @@ -1035,32 +671,7 @@ async def get_and_return_uuid( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/uuid"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/uuid", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(uuid.UUID, _response.json()) # type: ignore @@ -1098,32 +709,7 @@ async def get_and_return_base_64( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/base64"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/base64", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/endpoints/union/client.py b/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/endpoints/union/client.py index 23757c07bd8..843d9828bc6 100644 --- a/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/endpoints/union/client.py +++ b/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/endpoints/union/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.union.types.animal import Animal @@ -53,32 +49,7 @@ def get_and_return_union( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "union"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "union", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Animal, _response.json()) # type: ignore @@ -125,32 +96,7 @@ async def get_and_return_union( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "union"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "union", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Animal, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/inlined_requests/client.py b/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/inlined_requests/client.py index 38e428f66e0..bfb17877f08 100644 --- a/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/inlined_requests/client.py +++ b/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/inlined_requests/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..general_errors.errors.bad_request_body import BadRequestBody from ..general_errors.types.bad_object_request_info import BadObjectRequestInfo @@ -29,7 +25,7 @@ def post_with_object_bodyand_response( string: str, integer: int, nested_object: ObjectWithOptionalField, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> ObjectWithOptionalField: """ POST with custom object in request body, response is an object @@ -87,32 +83,11 @@ def post_with_object_bodyand_response( ) """ _response = self._client_wrapper.httpx_client.request( + "req-bodies/object", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "req-bodies/object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "integer": integer, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -135,7 +110,7 @@ async def post_with_object_bodyand_response( string: str, integer: int, nested_object: ObjectWithOptionalField, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> ObjectWithOptionalField: """ POST with custom object in request body, response is an object @@ -193,32 +168,11 @@ async def post_with_object_bodyand_response( ) """ _response = await self._client_wrapper.httpx_client.request( + "req-bodies/object", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "req-bodies/object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "integer": integer, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/no_auth/client.py b/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/no_auth/client.py index fd4814dde0b..477bf563998 100644 --- a/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/no_auth/client.py +++ b/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/no_auth/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..general_errors.errors.bad_request_body import BadRequestBody from ..general_errors.types.bad_object_request_info import BadObjectRequestInfo @@ -52,32 +48,7 @@ def post_with_no_auth( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-auth", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -124,32 +95,7 @@ async def post_with_no_auth( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-auth", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/no_req_body/client.py b/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/no_req_body/client.py index f984b6c24d3..7e3fd3ae95f 100644 --- a/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/no_req_body/client.py +++ b/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/no_req_body/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..types.object.types.object_with_optional_field import ObjectWithOptionalField @@ -42,26 +38,7 @@ def get_with_no_request_body( client.no_req_body.get_with_no_request_body() """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -93,29 +70,7 @@ def post_with_no_request_body(self, *, request_options: typing.Optional[RequestO client.no_req_body.post_with_no_request_body() """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -154,26 +109,7 @@ async def get_with_no_request_body( await client.no_req_body.get_with_no_request_body() """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -205,29 +141,7 @@ async def post_with_no_request_body(self, *, request_options: typing.Optional[Re await client.no_req_body.post_with_no_request_body() """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/req_with_headers/client.py b/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/req_with_headers/client.py index 3e7f80e7435..4ec08e7ee09 100644 --- a/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/req_with_headers/client.py +++ b/seed/python-sdk/exhaustive/extra_dev_dependencies/src/seed/req_with_headers/client.py @@ -1,14 +1,10 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -25,7 +21,7 @@ def get_with_custom_header( x_test_service_header: str, x_test_endpoint_header: str, request: str, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -58,33 +54,15 @@ def get_with_custom_header( ) """ _response = self._client_wrapper.httpx_client.request( + "test-headers/custom-header", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "test-headers/custom-header"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-TEST-SERVICE-HEADER": str(x_test_service_header) - if x_test_service_header is not None - else None, - "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) - if x_test_endpoint_header is not None - else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + headers={ + "X-TEST-SERVICE-HEADER": str(x_test_service_header) if x_test_service_header is not None else None, + "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) if x_test_endpoint_header is not None else None, + }, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return @@ -105,7 +83,7 @@ async def get_with_custom_header( x_test_service_header: str, x_test_endpoint_header: str, request: str, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -138,33 +116,15 @@ async def get_with_custom_header( ) """ _response = await self._client_wrapper.httpx_client.request( + "test-headers/custom-header", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "test-headers/custom-header"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-TEST-SERVICE-HEADER": str(x_test_service_header) - if x_test_service_header is not None - else None, - "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) - if x_test_endpoint_header is not None - else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + headers={ + "X-TEST-SERVICE-HEADER": str(x_test_service_header) if x_test_service_header is not None else None, + "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) if x_test_endpoint_header is not None else None, + }, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return diff --git a/seed/python-sdk/exhaustive/five-second-timeout/src/seed/core/client_wrapper.py b/seed/python-sdk/exhaustive/five-second-timeout/src/seed/core/client_wrapper.py index 5b0c9d5ad91..8d01b584b82 100644 --- a/seed/python-sdk/exhaustive/five-second-timeout/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/exhaustive/five-second-timeout/src/seed/core/client_wrapper.py @@ -53,7 +53,12 @@ def __init__( httpx_client: httpx.Client, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): @@ -66,4 +71,9 @@ def __init__( httpx_client: httpx.AsyncClient, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/exhaustive/five-second-timeout/src/seed/core/http_client.py b/seed/python-sdk/exhaustive/five-second-timeout/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/exhaustive/five-second-timeout/src/seed/core/http_client.py +++ b/seed/python-sdk/exhaustive/five-second-timeout/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/exhaustive/five-second-timeout/src/seed/endpoints/container/client.py b/seed/python-sdk/exhaustive/five-second-timeout/src/seed/endpoints/container/client.py index c5ab55847c7..e02bf812398 100644 --- a/seed/python-sdk/exhaustive/five-second-timeout/src/seed/endpoints/container/client.py +++ b/seed/python-sdk/exhaustive/five-second-timeout/src/seed/endpoints/container/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.object_with_required_field import ObjectWithRequiredField @@ -49,32 +45,7 @@ def get_and_return_list_of_primitives( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[str], _response.json()) # type: ignore @@ -88,7 +59,7 @@ def get_and_return_list_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -120,32 +91,7 @@ def get_and_return_list_of_objects( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -183,32 +129,7 @@ def get_and_return_set_of_primitives( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Set[str], _response.json()) # type: ignore @@ -222,7 +143,7 @@ def get_and_return_set_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -254,32 +175,7 @@ def get_and_return_set_of_objects( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -317,32 +213,7 @@ def get_and_return_map_prim_to_prim( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-prim"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-prim", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, str], _response.json()) # type: ignore @@ -356,7 +227,7 @@ def get_and_return_map_of_prim_to_object( self, *, request: typing.Dict[str, ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Dict[str, ObjectWithRequiredField]: """ Parameters @@ -388,32 +259,7 @@ def get_and_return_map_of_prim_to_object( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-object", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, ObjectWithRequiredField], _response.json()) # type: ignore @@ -427,7 +273,7 @@ def get_and_return_optional( self, *, request: typing.Optional[ObjectWithRequiredField] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Optional[ObjectWithRequiredField]: """ Parameters @@ -457,32 +303,7 @@ def get_and_return_optional( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/opt-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/opt-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Optional[ObjectWithRequiredField], _response.json()) # type: ignore @@ -525,32 +346,7 @@ async def get_and_return_list_of_primitives( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[str], _response.json()) # type: ignore @@ -564,7 +360,7 @@ async def get_and_return_list_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -596,32 +392,7 @@ async def get_and_return_list_of_objects( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -659,32 +430,7 @@ async def get_and_return_set_of_primitives( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Set[str], _response.json()) # type: ignore @@ -698,7 +444,7 @@ async def get_and_return_set_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -730,32 +476,7 @@ async def get_and_return_set_of_objects( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -793,32 +514,7 @@ async def get_and_return_map_prim_to_prim( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-prim"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-prim", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, str], _response.json()) # type: ignore @@ -832,7 +528,7 @@ async def get_and_return_map_of_prim_to_object( self, *, request: typing.Dict[str, ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Dict[str, ObjectWithRequiredField]: """ Parameters @@ -864,32 +560,7 @@ async def get_and_return_map_of_prim_to_object( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-object", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, ObjectWithRequiredField], _response.json()) # type: ignore @@ -903,7 +574,7 @@ async def get_and_return_optional( self, *, request: typing.Optional[ObjectWithRequiredField] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Optional[ObjectWithRequiredField]: """ Parameters @@ -933,32 +604,7 @@ async def get_and_return_optional( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/opt-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/opt-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Optional[ObjectWithRequiredField], _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/five-second-timeout/src/seed/endpoints/enum/client.py b/seed/python-sdk/exhaustive/five-second-timeout/src/seed/endpoints/enum/client.py index 94ee2ac420f..8fcd0668b4b 100644 --- a/seed/python-sdk/exhaustive/five-second-timeout/src/seed/endpoints/enum/client.py +++ b/seed/python-sdk/exhaustive/five-second-timeout/src/seed/endpoints/enum/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.enum.types.weather_report import WeatherReport @@ -49,27 +45,7 @@ def get_and_return_enum( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "enum"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "enum", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(WeatherReport, _response.json()) # type: ignore @@ -112,27 +88,7 @@ async def get_and_return_enum( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "enum"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "enum", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(WeatherReport, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/five-second-timeout/src/seed/endpoints/http_methods/client.py b/seed/python-sdk/exhaustive/five-second-timeout/src/seed/endpoints/http_methods/client.py index 1c8af11a4bd..3bd65f6adda 100644 --- a/seed/python-sdk/exhaustive/five-second-timeout/src/seed/endpoints/http_methods/client.py +++ b/seed/python-sdk/exhaustive/five-second-timeout/src/seed/endpoints/http_methods/client.py @@ -2,7 +2,6 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError @@ -10,8 +9,6 @@ from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.object_with_optional_field import ObjectWithOptionalField @@ -49,26 +46,7 @@ def test_get(self, id: str, *, request_options: typing.Optional[RequestOptions] ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -105,34 +83,8 @@ def test_post( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "http-methods"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "http-methods", method="POST", json={"string": string}, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -172,34 +124,12 @@ def test_put( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PUT", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -296,58 +226,25 @@ def test_patch( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PATCH", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -383,29 +280,7 @@ def test_delete(self, id: str, *, request_options: typing.Optional[RequestOption ) """ _response = self._client_wrapper.httpx_client.request( - method="DELETE", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="DELETE", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -446,26 +321,7 @@ async def test_get(self, id: str, *, request_options: typing.Optional[RequestOpt ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -502,34 +358,8 @@ async def test_post( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "http-methods"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "http-methods", method="POST", json={"string": string}, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -569,34 +399,12 @@ async def test_put( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PUT", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -693,58 +501,25 @@ async def test_patch( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = await self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PATCH", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -780,29 +555,7 @@ async def test_delete(self, id: str, *, request_options: typing.Optional[Request ) """ _response = await self._client_wrapper.httpx_client.request( - method="DELETE", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="DELETE", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/five-second-timeout/src/seed/endpoints/object/client.py b/seed/python-sdk/exhaustive/five-second-timeout/src/seed/endpoints/object/client.py index 83230dec1f4..7e66510fdb0 100644 --- a/seed/python-sdk/exhaustive/five-second-timeout/src/seed/endpoints/object/client.py +++ b/seed/python-sdk/exhaustive/five-second-timeout/src/seed/endpoints/object/client.py @@ -2,7 +2,6 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError @@ -10,8 +9,6 @@ from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.nested_object_with_optional_field import NestedObjectWithOptionalField from ...types.object.types.nested_object_with_required_field import NestedObjectWithRequiredField @@ -110,60 +107,25 @@ def get_and_return_with_optional_field( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -200,36 +162,12 @@ def get_and_return_with_required_field( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-required-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-required-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithRequiredField, _response.json()) # type: ignore @@ -266,36 +204,12 @@ def get_and_return_with_map_of_map( map_={"string": {"string": "string"}}, ) """ - _request: typing.Dict[str, typing.Any] = {"map": map_} _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-map-of-map", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-map-of-map" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"map": map_}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithMapOfMap, _response.json()) # type: ignore @@ -362,40 +276,12 @@ def get_and_return_nested_with_optional_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if nested_object is not OMIT: - _request["NestedObject"] = nested_object _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithOptionalField, _response.json()) # type: ignore @@ -466,37 +352,12 @@ def get_and_return_nested_with_required_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {"string": string, "NestedObject": nested_object} _response = self._client_wrapper.httpx_client.request( + f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", - f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -565,34 +426,11 @@ def get_and_return_nested_with_required_field_as_list( ) """ _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-required-field-list", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-required-field-list" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -690,60 +528,25 @@ async def get_and_return_with_optional_field( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -780,36 +583,12 @@ async def get_and_return_with_required_field( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-required-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-required-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithRequiredField, _response.json()) # type: ignore @@ -846,36 +625,12 @@ async def get_and_return_with_map_of_map( map_={"string": {"string": "string"}}, ) """ - _request: typing.Dict[str, typing.Any] = {"map": map_} _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-map-of-map", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-map-of-map" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"map": map_}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithMapOfMap, _response.json()) # type: ignore @@ -942,40 +697,12 @@ async def get_and_return_nested_with_optional_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if nested_object is not OMIT: - _request["NestedObject"] = nested_object _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithOptionalField, _response.json()) # type: ignore @@ -1046,37 +773,12 @@ async def get_and_return_nested_with_required_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {"string": string, "NestedObject": nested_object} _response = await self._client_wrapper.httpx_client.request( + f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", - f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -1145,34 +847,11 @@ async def get_and_return_nested_with_required_field_as_list( ) """ _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-required-field-list", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-required-field-list" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/five-second-timeout/src/seed/endpoints/params/client.py b/seed/python-sdk/exhaustive/five-second-timeout/src/seed/endpoints/params/client.py index d1f25df27fb..089d9fab5ce 100644 --- a/seed/python-sdk/exhaustive/five-second-timeout/src/seed/endpoints/params/client.py +++ b/seed/python-sdk/exhaustive/five-second-timeout/src/seed/endpoints/params/client.py @@ -1,15 +1,12 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -48,28 +45,7 @@ def get_with_path(self, param: str, *, request_options: typing.Optional[RequestO ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"params/path/{jsonable_encoder(param)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -112,36 +88,7 @@ def get_with_query( ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "number": number, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "number": number}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -188,36 +135,7 @@ def get_with_allow_multiple_query( ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "numer": numer, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "numer": numer}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -260,37 +178,10 @@ def get_with_path_and_query( ) """ _response = self._client_wrapper.httpx_client.request( + f"params/path-query/{jsonable_encoder(param)}", method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path-query/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"query": query}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -333,29 +224,11 @@ def modify_with_path( ) """ _response = self._client_wrapper.httpx_client.request( + f"params/path/{jsonable_encoder(param)}", method="PUT", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -398,28 +271,7 @@ async def get_with_path(self, param: str, *, request_options: typing.Optional[Re ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"params/path/{jsonable_encoder(param)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -462,36 +314,7 @@ async def get_with_query( ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "number": number, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "number": number}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -538,36 +361,7 @@ async def get_with_allow_multiple_query( ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "numer": numer, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "numer": numer}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -610,37 +404,10 @@ async def get_with_path_and_query( ) """ _response = await self._client_wrapper.httpx_client.request( + f"params/path-query/{jsonable_encoder(param)}", method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path-query/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"query": query}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -683,29 +450,11 @@ async def modify_with_path( ) """ _response = await self._client_wrapper.httpx_client.request( + f"params/path/{jsonable_encoder(param)}", method="PUT", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/five-second-timeout/src/seed/endpoints/primitive/client.py b/seed/python-sdk/exhaustive/five-second-timeout/src/seed/endpoints/primitive/client.py index 076383510ff..64c7f6b2ca5 100644 --- a/seed/python-sdk/exhaustive/five-second-timeout/src/seed/endpoints/primitive/client.py +++ b/seed/python-sdk/exhaustive/five-second-timeout/src/seed/endpoints/primitive/client.py @@ -2,16 +2,12 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -48,27 +44,7 @@ def get_and_return_string(self, *, request: str, request_options: typing.Optiona ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/string"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/string", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -104,27 +80,7 @@ def get_and_return_int(self, *, request: int, request_options: typing.Optional[R ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/integer"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/integer", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -160,32 +116,7 @@ def get_and_return_long(self, *, request: int, request_options: typing.Optional[ ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/long"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/long", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -223,27 +154,7 @@ def get_and_return_double( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/double"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/double", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(float, _response.json()) # type: ignore @@ -279,27 +190,7 @@ def get_and_return_bool(self, *, request: bool, request_options: typing.Optional ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/boolean"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/boolean", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -341,32 +232,7 @@ def get_and_return_datetime( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/datetime"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/datetime", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.datetime, _response.json()) # type: ignore @@ -408,32 +274,7 @@ def get_and_return_date( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/date"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/date", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.date, _response.json()) # type: ignore @@ -475,32 +316,7 @@ def get_and_return_uuid( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/uuid"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/uuid", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(uuid.UUID, _response.json()) # type: ignore @@ -536,32 +352,7 @@ def get_and_return_base_64(self, *, request: str, request_options: typing.Option ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/base64"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/base64", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -604,27 +395,7 @@ async def get_and_return_string( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/string"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/string", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -660,27 +431,7 @@ async def get_and_return_int(self, *, request: int, request_options: typing.Opti ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/integer"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/integer", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -718,32 +469,7 @@ async def get_and_return_long( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/long"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/long", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -781,27 +507,7 @@ async def get_and_return_double( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/double"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/double", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(float, _response.json()) # type: ignore @@ -839,27 +545,7 @@ async def get_and_return_bool( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/boolean"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/boolean", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -901,32 +587,7 @@ async def get_and_return_datetime( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/datetime"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/datetime", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.datetime, _response.json()) # type: ignore @@ -968,32 +629,7 @@ async def get_and_return_date( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/date"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/date", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.date, _response.json()) # type: ignore @@ -1035,32 +671,7 @@ async def get_and_return_uuid( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/uuid"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/uuid", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(uuid.UUID, _response.json()) # type: ignore @@ -1098,32 +709,7 @@ async def get_and_return_base_64( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/base64"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/base64", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/five-second-timeout/src/seed/endpoints/union/client.py b/seed/python-sdk/exhaustive/five-second-timeout/src/seed/endpoints/union/client.py index 23757c07bd8..843d9828bc6 100644 --- a/seed/python-sdk/exhaustive/five-second-timeout/src/seed/endpoints/union/client.py +++ b/seed/python-sdk/exhaustive/five-second-timeout/src/seed/endpoints/union/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.union.types.animal import Animal @@ -53,32 +49,7 @@ def get_and_return_union( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "union"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "union", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Animal, _response.json()) # type: ignore @@ -125,32 +96,7 @@ async def get_and_return_union( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "union"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "union", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Animal, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/five-second-timeout/src/seed/inlined_requests/client.py b/seed/python-sdk/exhaustive/five-second-timeout/src/seed/inlined_requests/client.py index 38e428f66e0..bfb17877f08 100644 --- a/seed/python-sdk/exhaustive/five-second-timeout/src/seed/inlined_requests/client.py +++ b/seed/python-sdk/exhaustive/five-second-timeout/src/seed/inlined_requests/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..general_errors.errors.bad_request_body import BadRequestBody from ..general_errors.types.bad_object_request_info import BadObjectRequestInfo @@ -29,7 +25,7 @@ def post_with_object_bodyand_response( string: str, integer: int, nested_object: ObjectWithOptionalField, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> ObjectWithOptionalField: """ POST with custom object in request body, response is an object @@ -87,32 +83,11 @@ def post_with_object_bodyand_response( ) """ _response = self._client_wrapper.httpx_client.request( + "req-bodies/object", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "req-bodies/object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "integer": integer, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -135,7 +110,7 @@ async def post_with_object_bodyand_response( string: str, integer: int, nested_object: ObjectWithOptionalField, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> ObjectWithOptionalField: """ POST with custom object in request body, response is an object @@ -193,32 +168,11 @@ async def post_with_object_bodyand_response( ) """ _response = await self._client_wrapper.httpx_client.request( + "req-bodies/object", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "req-bodies/object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "integer": integer, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/five-second-timeout/src/seed/no_auth/client.py b/seed/python-sdk/exhaustive/five-second-timeout/src/seed/no_auth/client.py index fd4814dde0b..477bf563998 100644 --- a/seed/python-sdk/exhaustive/five-second-timeout/src/seed/no_auth/client.py +++ b/seed/python-sdk/exhaustive/five-second-timeout/src/seed/no_auth/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..general_errors.errors.bad_request_body import BadRequestBody from ..general_errors.types.bad_object_request_info import BadObjectRequestInfo @@ -52,32 +48,7 @@ def post_with_no_auth( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-auth", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -124,32 +95,7 @@ async def post_with_no_auth( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-auth", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/five-second-timeout/src/seed/no_req_body/client.py b/seed/python-sdk/exhaustive/five-second-timeout/src/seed/no_req_body/client.py index f984b6c24d3..7e3fd3ae95f 100644 --- a/seed/python-sdk/exhaustive/five-second-timeout/src/seed/no_req_body/client.py +++ b/seed/python-sdk/exhaustive/five-second-timeout/src/seed/no_req_body/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..types.object.types.object_with_optional_field import ObjectWithOptionalField @@ -42,26 +38,7 @@ def get_with_no_request_body( client.no_req_body.get_with_no_request_body() """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -93,29 +70,7 @@ def post_with_no_request_body(self, *, request_options: typing.Optional[RequestO client.no_req_body.post_with_no_request_body() """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -154,26 +109,7 @@ async def get_with_no_request_body( await client.no_req_body.get_with_no_request_body() """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -205,29 +141,7 @@ async def post_with_no_request_body(self, *, request_options: typing.Optional[Re await client.no_req_body.post_with_no_request_body() """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/five-second-timeout/src/seed/req_with_headers/client.py b/seed/python-sdk/exhaustive/five-second-timeout/src/seed/req_with_headers/client.py index 3e7f80e7435..4ec08e7ee09 100644 --- a/seed/python-sdk/exhaustive/five-second-timeout/src/seed/req_with_headers/client.py +++ b/seed/python-sdk/exhaustive/five-second-timeout/src/seed/req_with_headers/client.py @@ -1,14 +1,10 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -25,7 +21,7 @@ def get_with_custom_header( x_test_service_header: str, x_test_endpoint_header: str, request: str, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -58,33 +54,15 @@ def get_with_custom_header( ) """ _response = self._client_wrapper.httpx_client.request( + "test-headers/custom-header", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "test-headers/custom-header"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-TEST-SERVICE-HEADER": str(x_test_service_header) - if x_test_service_header is not None - else None, - "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) - if x_test_endpoint_header is not None - else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + headers={ + "X-TEST-SERVICE-HEADER": str(x_test_service_header) if x_test_service_header is not None else None, + "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) if x_test_endpoint_header is not None else None, + }, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return @@ -105,7 +83,7 @@ async def get_with_custom_header( x_test_service_header: str, x_test_endpoint_header: str, request: str, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -138,33 +116,15 @@ async def get_with_custom_header( ) """ _response = await self._client_wrapper.httpx_client.request( + "test-headers/custom-header", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "test-headers/custom-header"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-TEST-SERVICE-HEADER": str(x_test_service_header) - if x_test_service_header is not None - else None, - "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) - if x_test_endpoint_header is not None - else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + headers={ + "X-TEST-SERVICE-HEADER": str(x_test_service_header) if x_test_service_header is not None else None, + "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) if x_test_endpoint_header is not None else None, + }, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return diff --git a/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/core/client_wrapper.py b/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/core/client_wrapper.py index 5b0c9d5ad91..8d01b584b82 100644 --- a/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/core/client_wrapper.py @@ -53,7 +53,12 @@ def __init__( httpx_client: httpx.Client, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): @@ -66,4 +71,9 @@ def __init__( httpx_client: httpx.AsyncClient, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/core/http_client.py b/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/core/http_client.py +++ b/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/endpoints/container/client.py b/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/endpoints/container/client.py index c5ab55847c7..e02bf812398 100644 --- a/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/endpoints/container/client.py +++ b/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/endpoints/container/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.object_with_required_field import ObjectWithRequiredField @@ -49,32 +45,7 @@ def get_and_return_list_of_primitives( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[str], _response.json()) # type: ignore @@ -88,7 +59,7 @@ def get_and_return_list_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -120,32 +91,7 @@ def get_and_return_list_of_objects( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -183,32 +129,7 @@ def get_and_return_set_of_primitives( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Set[str], _response.json()) # type: ignore @@ -222,7 +143,7 @@ def get_and_return_set_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -254,32 +175,7 @@ def get_and_return_set_of_objects( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -317,32 +213,7 @@ def get_and_return_map_prim_to_prim( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-prim"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-prim", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, str], _response.json()) # type: ignore @@ -356,7 +227,7 @@ def get_and_return_map_of_prim_to_object( self, *, request: typing.Dict[str, ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Dict[str, ObjectWithRequiredField]: """ Parameters @@ -388,32 +259,7 @@ def get_and_return_map_of_prim_to_object( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-object", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, ObjectWithRequiredField], _response.json()) # type: ignore @@ -427,7 +273,7 @@ def get_and_return_optional( self, *, request: typing.Optional[ObjectWithRequiredField] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Optional[ObjectWithRequiredField]: """ Parameters @@ -457,32 +303,7 @@ def get_and_return_optional( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/opt-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/opt-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Optional[ObjectWithRequiredField], _response.json()) # type: ignore @@ -525,32 +346,7 @@ async def get_and_return_list_of_primitives( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[str], _response.json()) # type: ignore @@ -564,7 +360,7 @@ async def get_and_return_list_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -596,32 +392,7 @@ async def get_and_return_list_of_objects( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -659,32 +430,7 @@ async def get_and_return_set_of_primitives( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Set[str], _response.json()) # type: ignore @@ -698,7 +444,7 @@ async def get_and_return_set_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -730,32 +476,7 @@ async def get_and_return_set_of_objects( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -793,32 +514,7 @@ async def get_and_return_map_prim_to_prim( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-prim"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-prim", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, str], _response.json()) # type: ignore @@ -832,7 +528,7 @@ async def get_and_return_map_of_prim_to_object( self, *, request: typing.Dict[str, ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Dict[str, ObjectWithRequiredField]: """ Parameters @@ -864,32 +560,7 @@ async def get_and_return_map_of_prim_to_object( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-object", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, ObjectWithRequiredField], _response.json()) # type: ignore @@ -903,7 +574,7 @@ async def get_and_return_optional( self, *, request: typing.Optional[ObjectWithRequiredField] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Optional[ObjectWithRequiredField]: """ Parameters @@ -933,32 +604,7 @@ async def get_and_return_optional( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/opt-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/opt-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Optional[ObjectWithRequiredField], _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/endpoints/enum/client.py b/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/endpoints/enum/client.py index 94ee2ac420f..8fcd0668b4b 100644 --- a/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/endpoints/enum/client.py +++ b/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/endpoints/enum/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.enum.types.weather_report import WeatherReport @@ -49,27 +45,7 @@ def get_and_return_enum( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "enum"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "enum", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(WeatherReport, _response.json()) # type: ignore @@ -112,27 +88,7 @@ async def get_and_return_enum( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "enum"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "enum", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(WeatherReport, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/endpoints/http_methods/client.py b/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/endpoints/http_methods/client.py index 1c8af11a4bd..3bd65f6adda 100644 --- a/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/endpoints/http_methods/client.py +++ b/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/endpoints/http_methods/client.py @@ -2,7 +2,6 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError @@ -10,8 +9,6 @@ from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.object_with_optional_field import ObjectWithOptionalField @@ -49,26 +46,7 @@ def test_get(self, id: str, *, request_options: typing.Optional[RequestOptions] ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -105,34 +83,8 @@ def test_post( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "http-methods"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "http-methods", method="POST", json={"string": string}, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -172,34 +124,12 @@ def test_put( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PUT", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -296,58 +226,25 @@ def test_patch( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PATCH", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -383,29 +280,7 @@ def test_delete(self, id: str, *, request_options: typing.Optional[RequestOption ) """ _response = self._client_wrapper.httpx_client.request( - method="DELETE", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="DELETE", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -446,26 +321,7 @@ async def test_get(self, id: str, *, request_options: typing.Optional[RequestOpt ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -502,34 +358,8 @@ async def test_post( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "http-methods"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "http-methods", method="POST", json={"string": string}, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -569,34 +399,12 @@ async def test_put( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PUT", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -693,58 +501,25 @@ async def test_patch( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = await self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PATCH", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -780,29 +555,7 @@ async def test_delete(self, id: str, *, request_options: typing.Optional[Request ) """ _response = await self._client_wrapper.httpx_client.request( - method="DELETE", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="DELETE", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/endpoints/object/client.py b/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/endpoints/object/client.py index 83230dec1f4..7e66510fdb0 100644 --- a/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/endpoints/object/client.py +++ b/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/endpoints/object/client.py @@ -2,7 +2,6 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError @@ -10,8 +9,6 @@ from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.nested_object_with_optional_field import NestedObjectWithOptionalField from ...types.object.types.nested_object_with_required_field import NestedObjectWithRequiredField @@ -110,60 +107,25 @@ def get_and_return_with_optional_field( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -200,36 +162,12 @@ def get_and_return_with_required_field( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-required-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-required-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithRequiredField, _response.json()) # type: ignore @@ -266,36 +204,12 @@ def get_and_return_with_map_of_map( map_={"string": {"string": "string"}}, ) """ - _request: typing.Dict[str, typing.Any] = {"map": map_} _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-map-of-map", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-map-of-map" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"map": map_}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithMapOfMap, _response.json()) # type: ignore @@ -362,40 +276,12 @@ def get_and_return_nested_with_optional_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if nested_object is not OMIT: - _request["NestedObject"] = nested_object _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithOptionalField, _response.json()) # type: ignore @@ -466,37 +352,12 @@ def get_and_return_nested_with_required_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {"string": string, "NestedObject": nested_object} _response = self._client_wrapper.httpx_client.request( + f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", - f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -565,34 +426,11 @@ def get_and_return_nested_with_required_field_as_list( ) """ _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-required-field-list", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-required-field-list" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -690,60 +528,25 @@ async def get_and_return_with_optional_field( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -780,36 +583,12 @@ async def get_and_return_with_required_field( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-required-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-required-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithRequiredField, _response.json()) # type: ignore @@ -846,36 +625,12 @@ async def get_and_return_with_map_of_map( map_={"string": {"string": "string"}}, ) """ - _request: typing.Dict[str, typing.Any] = {"map": map_} _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-map-of-map", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-map-of-map" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"map": map_}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithMapOfMap, _response.json()) # type: ignore @@ -942,40 +697,12 @@ async def get_and_return_nested_with_optional_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if nested_object is not OMIT: - _request["NestedObject"] = nested_object _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithOptionalField, _response.json()) # type: ignore @@ -1046,37 +773,12 @@ async def get_and_return_nested_with_required_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {"string": string, "NestedObject": nested_object} _response = await self._client_wrapper.httpx_client.request( + f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", - f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -1145,34 +847,11 @@ async def get_and_return_nested_with_required_field_as_list( ) """ _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-required-field-list", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-required-field-list" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/endpoints/params/client.py b/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/endpoints/params/client.py index d1f25df27fb..089d9fab5ce 100644 --- a/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/endpoints/params/client.py +++ b/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/endpoints/params/client.py @@ -1,15 +1,12 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -48,28 +45,7 @@ def get_with_path(self, param: str, *, request_options: typing.Optional[RequestO ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"params/path/{jsonable_encoder(param)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -112,36 +88,7 @@ def get_with_query( ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "number": number, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "number": number}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -188,36 +135,7 @@ def get_with_allow_multiple_query( ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "numer": numer, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "numer": numer}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -260,37 +178,10 @@ def get_with_path_and_query( ) """ _response = self._client_wrapper.httpx_client.request( + f"params/path-query/{jsonable_encoder(param)}", method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path-query/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"query": query}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -333,29 +224,11 @@ def modify_with_path( ) """ _response = self._client_wrapper.httpx_client.request( + f"params/path/{jsonable_encoder(param)}", method="PUT", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -398,28 +271,7 @@ async def get_with_path(self, param: str, *, request_options: typing.Optional[Re ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"params/path/{jsonable_encoder(param)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -462,36 +314,7 @@ async def get_with_query( ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "number": number, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "number": number}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -538,36 +361,7 @@ async def get_with_allow_multiple_query( ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "numer": numer, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "numer": numer}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -610,37 +404,10 @@ async def get_with_path_and_query( ) """ _response = await self._client_wrapper.httpx_client.request( + f"params/path-query/{jsonable_encoder(param)}", method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path-query/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"query": query}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -683,29 +450,11 @@ async def modify_with_path( ) """ _response = await self._client_wrapper.httpx_client.request( + f"params/path/{jsonable_encoder(param)}", method="PUT", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/endpoints/primitive/client.py b/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/endpoints/primitive/client.py index 076383510ff..64c7f6b2ca5 100644 --- a/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/endpoints/primitive/client.py +++ b/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/endpoints/primitive/client.py @@ -2,16 +2,12 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -48,27 +44,7 @@ def get_and_return_string(self, *, request: str, request_options: typing.Optiona ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/string"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/string", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -104,27 +80,7 @@ def get_and_return_int(self, *, request: int, request_options: typing.Optional[R ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/integer"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/integer", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -160,32 +116,7 @@ def get_and_return_long(self, *, request: int, request_options: typing.Optional[ ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/long"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/long", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -223,27 +154,7 @@ def get_and_return_double( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/double"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/double", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(float, _response.json()) # type: ignore @@ -279,27 +190,7 @@ def get_and_return_bool(self, *, request: bool, request_options: typing.Optional ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/boolean"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/boolean", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -341,32 +232,7 @@ def get_and_return_datetime( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/datetime"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/datetime", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.datetime, _response.json()) # type: ignore @@ -408,32 +274,7 @@ def get_and_return_date( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/date"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/date", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.date, _response.json()) # type: ignore @@ -475,32 +316,7 @@ def get_and_return_uuid( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/uuid"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/uuid", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(uuid.UUID, _response.json()) # type: ignore @@ -536,32 +352,7 @@ def get_and_return_base_64(self, *, request: str, request_options: typing.Option ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/base64"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/base64", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -604,27 +395,7 @@ async def get_and_return_string( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/string"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/string", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -660,27 +431,7 @@ async def get_and_return_int(self, *, request: int, request_options: typing.Opti ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/integer"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/integer", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -718,32 +469,7 @@ async def get_and_return_long( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/long"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/long", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -781,27 +507,7 @@ async def get_and_return_double( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/double"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/double", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(float, _response.json()) # type: ignore @@ -839,27 +545,7 @@ async def get_and_return_bool( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/boolean"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/boolean", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -901,32 +587,7 @@ async def get_and_return_datetime( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/datetime"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/datetime", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.datetime, _response.json()) # type: ignore @@ -968,32 +629,7 @@ async def get_and_return_date( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/date"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/date", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.date, _response.json()) # type: ignore @@ -1035,32 +671,7 @@ async def get_and_return_uuid( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/uuid"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/uuid", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(uuid.UUID, _response.json()) # type: ignore @@ -1098,32 +709,7 @@ async def get_and_return_base_64( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/base64"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/base64", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/endpoints/union/client.py b/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/endpoints/union/client.py index 23757c07bd8..843d9828bc6 100644 --- a/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/endpoints/union/client.py +++ b/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/endpoints/union/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.union.types.animal import Animal @@ -53,32 +49,7 @@ def get_and_return_union( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "union"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "union", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Animal, _response.json()) # type: ignore @@ -125,32 +96,7 @@ async def get_and_return_union( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "union"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "union", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Animal, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/inlined_requests/client.py b/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/inlined_requests/client.py index 38e428f66e0..bfb17877f08 100644 --- a/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/inlined_requests/client.py +++ b/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/inlined_requests/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..general_errors.errors.bad_request_body import BadRequestBody from ..general_errors.types.bad_object_request_info import BadObjectRequestInfo @@ -29,7 +25,7 @@ def post_with_object_bodyand_response( string: str, integer: int, nested_object: ObjectWithOptionalField, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> ObjectWithOptionalField: """ POST with custom object in request body, response is an object @@ -87,32 +83,11 @@ def post_with_object_bodyand_response( ) """ _response = self._client_wrapper.httpx_client.request( + "req-bodies/object", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "req-bodies/object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "integer": integer, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -135,7 +110,7 @@ async def post_with_object_bodyand_response( string: str, integer: int, nested_object: ObjectWithOptionalField, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> ObjectWithOptionalField: """ POST with custom object in request body, response is an object @@ -193,32 +168,11 @@ async def post_with_object_bodyand_response( ) """ _response = await self._client_wrapper.httpx_client.request( + "req-bodies/object", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "req-bodies/object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "integer": integer, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/no_auth/client.py b/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/no_auth/client.py index fd4814dde0b..477bf563998 100644 --- a/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/no_auth/client.py +++ b/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/no_auth/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..general_errors.errors.bad_request_body import BadRequestBody from ..general_errors.types.bad_object_request_info import BadObjectRequestInfo @@ -52,32 +48,7 @@ def post_with_no_auth( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-auth", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -124,32 +95,7 @@ async def post_with_no_auth( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-auth", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/no_req_body/client.py b/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/no_req_body/client.py index f984b6c24d3..7e3fd3ae95f 100644 --- a/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/no_req_body/client.py +++ b/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/no_req_body/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..types.object.types.object_with_optional_field import ObjectWithOptionalField @@ -42,26 +38,7 @@ def get_with_no_request_body( client.no_req_body.get_with_no_request_body() """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -93,29 +70,7 @@ def post_with_no_request_body(self, *, request_options: typing.Optional[RequestO client.no_req_body.post_with_no_request_body() """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -154,26 +109,7 @@ async def get_with_no_request_body( await client.no_req_body.get_with_no_request_body() """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -205,29 +141,7 @@ async def post_with_no_request_body(self, *, request_options: typing.Optional[Re await client.no_req_body.post_with_no_request_body() """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/req_with_headers/client.py b/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/req_with_headers/client.py index 3e7f80e7435..4ec08e7ee09 100644 --- a/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/req_with_headers/client.py +++ b/seed/python-sdk/exhaustive/follow_redirects_by_default/src/seed/req_with_headers/client.py @@ -1,14 +1,10 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -25,7 +21,7 @@ def get_with_custom_header( x_test_service_header: str, x_test_endpoint_header: str, request: str, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -58,33 +54,15 @@ def get_with_custom_header( ) """ _response = self._client_wrapper.httpx_client.request( + "test-headers/custom-header", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "test-headers/custom-header"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-TEST-SERVICE-HEADER": str(x_test_service_header) - if x_test_service_header is not None - else None, - "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) - if x_test_endpoint_header is not None - else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + headers={ + "X-TEST-SERVICE-HEADER": str(x_test_service_header) if x_test_service_header is not None else None, + "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) if x_test_endpoint_header is not None else None, + }, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return @@ -105,7 +83,7 @@ async def get_with_custom_header( x_test_service_header: str, x_test_endpoint_header: str, request: str, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -138,33 +116,15 @@ async def get_with_custom_header( ) """ _response = await self._client_wrapper.httpx_client.request( + "test-headers/custom-header", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "test-headers/custom-header"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-TEST-SERVICE-HEADER": str(x_test_service_header) - if x_test_service_header is not None - else None, - "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) - if x_test_endpoint_header is not None - else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + headers={ + "X-TEST-SERVICE-HEADER": str(x_test_service_header) if x_test_service_header is not None else None, + "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) if x_test_endpoint_header is not None else None, + }, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return diff --git a/seed/python-sdk/exhaustive/improved_imports/src/seed/core/client_wrapper.py b/seed/python-sdk/exhaustive/improved_imports/src/seed/core/client_wrapper.py index 5b0c9d5ad91..8d01b584b82 100644 --- a/seed/python-sdk/exhaustive/improved_imports/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/exhaustive/improved_imports/src/seed/core/client_wrapper.py @@ -53,7 +53,12 @@ def __init__( httpx_client: httpx.Client, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): @@ -66,4 +71,9 @@ def __init__( httpx_client: httpx.AsyncClient, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/exhaustive/improved_imports/src/seed/core/http_client.py b/seed/python-sdk/exhaustive/improved_imports/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/exhaustive/improved_imports/src/seed/core/http_client.py +++ b/seed/python-sdk/exhaustive/improved_imports/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/exhaustive/improved_imports/src/seed/endpoints/container/client.py b/seed/python-sdk/exhaustive/improved_imports/src/seed/endpoints/container/client.py index c5ab55847c7..e02bf812398 100644 --- a/seed/python-sdk/exhaustive/improved_imports/src/seed/endpoints/container/client.py +++ b/seed/python-sdk/exhaustive/improved_imports/src/seed/endpoints/container/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.object_with_required_field import ObjectWithRequiredField @@ -49,32 +45,7 @@ def get_and_return_list_of_primitives( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[str], _response.json()) # type: ignore @@ -88,7 +59,7 @@ def get_and_return_list_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -120,32 +91,7 @@ def get_and_return_list_of_objects( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -183,32 +129,7 @@ def get_and_return_set_of_primitives( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Set[str], _response.json()) # type: ignore @@ -222,7 +143,7 @@ def get_and_return_set_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -254,32 +175,7 @@ def get_and_return_set_of_objects( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -317,32 +213,7 @@ def get_and_return_map_prim_to_prim( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-prim"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-prim", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, str], _response.json()) # type: ignore @@ -356,7 +227,7 @@ def get_and_return_map_of_prim_to_object( self, *, request: typing.Dict[str, ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Dict[str, ObjectWithRequiredField]: """ Parameters @@ -388,32 +259,7 @@ def get_and_return_map_of_prim_to_object( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-object", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, ObjectWithRequiredField], _response.json()) # type: ignore @@ -427,7 +273,7 @@ def get_and_return_optional( self, *, request: typing.Optional[ObjectWithRequiredField] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Optional[ObjectWithRequiredField]: """ Parameters @@ -457,32 +303,7 @@ def get_and_return_optional( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/opt-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/opt-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Optional[ObjectWithRequiredField], _response.json()) # type: ignore @@ -525,32 +346,7 @@ async def get_and_return_list_of_primitives( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[str], _response.json()) # type: ignore @@ -564,7 +360,7 @@ async def get_and_return_list_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -596,32 +392,7 @@ async def get_and_return_list_of_objects( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -659,32 +430,7 @@ async def get_and_return_set_of_primitives( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Set[str], _response.json()) # type: ignore @@ -698,7 +444,7 @@ async def get_and_return_set_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -730,32 +476,7 @@ async def get_and_return_set_of_objects( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -793,32 +514,7 @@ async def get_and_return_map_prim_to_prim( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-prim"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-prim", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, str], _response.json()) # type: ignore @@ -832,7 +528,7 @@ async def get_and_return_map_of_prim_to_object( self, *, request: typing.Dict[str, ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Dict[str, ObjectWithRequiredField]: """ Parameters @@ -864,32 +560,7 @@ async def get_and_return_map_of_prim_to_object( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-object", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, ObjectWithRequiredField], _response.json()) # type: ignore @@ -903,7 +574,7 @@ async def get_and_return_optional( self, *, request: typing.Optional[ObjectWithRequiredField] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Optional[ObjectWithRequiredField]: """ Parameters @@ -933,32 +604,7 @@ async def get_and_return_optional( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/opt-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/opt-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Optional[ObjectWithRequiredField], _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/improved_imports/src/seed/endpoints/enum/client.py b/seed/python-sdk/exhaustive/improved_imports/src/seed/endpoints/enum/client.py index 94ee2ac420f..8fcd0668b4b 100644 --- a/seed/python-sdk/exhaustive/improved_imports/src/seed/endpoints/enum/client.py +++ b/seed/python-sdk/exhaustive/improved_imports/src/seed/endpoints/enum/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.enum.types.weather_report import WeatherReport @@ -49,27 +45,7 @@ def get_and_return_enum( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "enum"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "enum", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(WeatherReport, _response.json()) # type: ignore @@ -112,27 +88,7 @@ async def get_and_return_enum( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "enum"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "enum", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(WeatherReport, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/improved_imports/src/seed/endpoints/http_methods/client.py b/seed/python-sdk/exhaustive/improved_imports/src/seed/endpoints/http_methods/client.py index 1c8af11a4bd..3bd65f6adda 100644 --- a/seed/python-sdk/exhaustive/improved_imports/src/seed/endpoints/http_methods/client.py +++ b/seed/python-sdk/exhaustive/improved_imports/src/seed/endpoints/http_methods/client.py @@ -2,7 +2,6 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError @@ -10,8 +9,6 @@ from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.object_with_optional_field import ObjectWithOptionalField @@ -49,26 +46,7 @@ def test_get(self, id: str, *, request_options: typing.Optional[RequestOptions] ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -105,34 +83,8 @@ def test_post( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "http-methods"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "http-methods", method="POST", json={"string": string}, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -172,34 +124,12 @@ def test_put( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PUT", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -296,58 +226,25 @@ def test_patch( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PATCH", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -383,29 +280,7 @@ def test_delete(self, id: str, *, request_options: typing.Optional[RequestOption ) """ _response = self._client_wrapper.httpx_client.request( - method="DELETE", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="DELETE", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -446,26 +321,7 @@ async def test_get(self, id: str, *, request_options: typing.Optional[RequestOpt ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -502,34 +358,8 @@ async def test_post( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "http-methods"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "http-methods", method="POST", json={"string": string}, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -569,34 +399,12 @@ async def test_put( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PUT", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -693,58 +501,25 @@ async def test_patch( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = await self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PATCH", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -780,29 +555,7 @@ async def test_delete(self, id: str, *, request_options: typing.Optional[Request ) """ _response = await self._client_wrapper.httpx_client.request( - method="DELETE", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="DELETE", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/improved_imports/src/seed/endpoints/object/client.py b/seed/python-sdk/exhaustive/improved_imports/src/seed/endpoints/object/client.py index 83230dec1f4..7e66510fdb0 100644 --- a/seed/python-sdk/exhaustive/improved_imports/src/seed/endpoints/object/client.py +++ b/seed/python-sdk/exhaustive/improved_imports/src/seed/endpoints/object/client.py @@ -2,7 +2,6 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError @@ -10,8 +9,6 @@ from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.nested_object_with_optional_field import NestedObjectWithOptionalField from ...types.object.types.nested_object_with_required_field import NestedObjectWithRequiredField @@ -110,60 +107,25 @@ def get_and_return_with_optional_field( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -200,36 +162,12 @@ def get_and_return_with_required_field( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-required-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-required-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithRequiredField, _response.json()) # type: ignore @@ -266,36 +204,12 @@ def get_and_return_with_map_of_map( map_={"string": {"string": "string"}}, ) """ - _request: typing.Dict[str, typing.Any] = {"map": map_} _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-map-of-map", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-map-of-map" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"map": map_}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithMapOfMap, _response.json()) # type: ignore @@ -362,40 +276,12 @@ def get_and_return_nested_with_optional_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if nested_object is not OMIT: - _request["NestedObject"] = nested_object _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithOptionalField, _response.json()) # type: ignore @@ -466,37 +352,12 @@ def get_and_return_nested_with_required_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {"string": string, "NestedObject": nested_object} _response = self._client_wrapper.httpx_client.request( + f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", - f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -565,34 +426,11 @@ def get_and_return_nested_with_required_field_as_list( ) """ _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-required-field-list", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-required-field-list" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -690,60 +528,25 @@ async def get_and_return_with_optional_field( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -780,36 +583,12 @@ async def get_and_return_with_required_field( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-required-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-required-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithRequiredField, _response.json()) # type: ignore @@ -846,36 +625,12 @@ async def get_and_return_with_map_of_map( map_={"string": {"string": "string"}}, ) """ - _request: typing.Dict[str, typing.Any] = {"map": map_} _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-map-of-map", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-map-of-map" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"map": map_}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithMapOfMap, _response.json()) # type: ignore @@ -942,40 +697,12 @@ async def get_and_return_nested_with_optional_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if nested_object is not OMIT: - _request["NestedObject"] = nested_object _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithOptionalField, _response.json()) # type: ignore @@ -1046,37 +773,12 @@ async def get_and_return_nested_with_required_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {"string": string, "NestedObject": nested_object} _response = await self._client_wrapper.httpx_client.request( + f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", - f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -1145,34 +847,11 @@ async def get_and_return_nested_with_required_field_as_list( ) """ _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-required-field-list", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-required-field-list" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/improved_imports/src/seed/endpoints/params/client.py b/seed/python-sdk/exhaustive/improved_imports/src/seed/endpoints/params/client.py index d1f25df27fb..089d9fab5ce 100644 --- a/seed/python-sdk/exhaustive/improved_imports/src/seed/endpoints/params/client.py +++ b/seed/python-sdk/exhaustive/improved_imports/src/seed/endpoints/params/client.py @@ -1,15 +1,12 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -48,28 +45,7 @@ def get_with_path(self, param: str, *, request_options: typing.Optional[RequestO ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"params/path/{jsonable_encoder(param)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -112,36 +88,7 @@ def get_with_query( ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "number": number, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "number": number}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -188,36 +135,7 @@ def get_with_allow_multiple_query( ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "numer": numer, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "numer": numer}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -260,37 +178,10 @@ def get_with_path_and_query( ) """ _response = self._client_wrapper.httpx_client.request( + f"params/path-query/{jsonable_encoder(param)}", method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path-query/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"query": query}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -333,29 +224,11 @@ def modify_with_path( ) """ _response = self._client_wrapper.httpx_client.request( + f"params/path/{jsonable_encoder(param)}", method="PUT", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -398,28 +271,7 @@ async def get_with_path(self, param: str, *, request_options: typing.Optional[Re ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"params/path/{jsonable_encoder(param)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -462,36 +314,7 @@ async def get_with_query( ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "number": number, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "number": number}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -538,36 +361,7 @@ async def get_with_allow_multiple_query( ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "numer": numer, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "numer": numer}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -610,37 +404,10 @@ async def get_with_path_and_query( ) """ _response = await self._client_wrapper.httpx_client.request( + f"params/path-query/{jsonable_encoder(param)}", method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path-query/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"query": query}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -683,29 +450,11 @@ async def modify_with_path( ) """ _response = await self._client_wrapper.httpx_client.request( + f"params/path/{jsonable_encoder(param)}", method="PUT", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/improved_imports/src/seed/endpoints/primitive/client.py b/seed/python-sdk/exhaustive/improved_imports/src/seed/endpoints/primitive/client.py index 076383510ff..64c7f6b2ca5 100644 --- a/seed/python-sdk/exhaustive/improved_imports/src/seed/endpoints/primitive/client.py +++ b/seed/python-sdk/exhaustive/improved_imports/src/seed/endpoints/primitive/client.py @@ -2,16 +2,12 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -48,27 +44,7 @@ def get_and_return_string(self, *, request: str, request_options: typing.Optiona ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/string"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/string", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -104,27 +80,7 @@ def get_and_return_int(self, *, request: int, request_options: typing.Optional[R ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/integer"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/integer", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -160,32 +116,7 @@ def get_and_return_long(self, *, request: int, request_options: typing.Optional[ ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/long"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/long", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -223,27 +154,7 @@ def get_and_return_double( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/double"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/double", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(float, _response.json()) # type: ignore @@ -279,27 +190,7 @@ def get_and_return_bool(self, *, request: bool, request_options: typing.Optional ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/boolean"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/boolean", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -341,32 +232,7 @@ def get_and_return_datetime( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/datetime"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/datetime", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.datetime, _response.json()) # type: ignore @@ -408,32 +274,7 @@ def get_and_return_date( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/date"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/date", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.date, _response.json()) # type: ignore @@ -475,32 +316,7 @@ def get_and_return_uuid( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/uuid"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/uuid", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(uuid.UUID, _response.json()) # type: ignore @@ -536,32 +352,7 @@ def get_and_return_base_64(self, *, request: str, request_options: typing.Option ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/base64"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/base64", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -604,27 +395,7 @@ async def get_and_return_string( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/string"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/string", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -660,27 +431,7 @@ async def get_and_return_int(self, *, request: int, request_options: typing.Opti ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/integer"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/integer", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -718,32 +469,7 @@ async def get_and_return_long( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/long"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/long", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -781,27 +507,7 @@ async def get_and_return_double( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/double"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/double", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(float, _response.json()) # type: ignore @@ -839,27 +545,7 @@ async def get_and_return_bool( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/boolean"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/boolean", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -901,32 +587,7 @@ async def get_and_return_datetime( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/datetime"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/datetime", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.datetime, _response.json()) # type: ignore @@ -968,32 +629,7 @@ async def get_and_return_date( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/date"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/date", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.date, _response.json()) # type: ignore @@ -1035,32 +671,7 @@ async def get_and_return_uuid( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/uuid"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/uuid", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(uuid.UUID, _response.json()) # type: ignore @@ -1098,32 +709,7 @@ async def get_and_return_base_64( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/base64"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/base64", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/improved_imports/src/seed/endpoints/union/client.py b/seed/python-sdk/exhaustive/improved_imports/src/seed/endpoints/union/client.py index 23757c07bd8..843d9828bc6 100644 --- a/seed/python-sdk/exhaustive/improved_imports/src/seed/endpoints/union/client.py +++ b/seed/python-sdk/exhaustive/improved_imports/src/seed/endpoints/union/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.union.types.animal import Animal @@ -53,32 +49,7 @@ def get_and_return_union( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "union"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "union", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Animal, _response.json()) # type: ignore @@ -125,32 +96,7 @@ async def get_and_return_union( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "union"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "union", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Animal, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/improved_imports/src/seed/inlined_requests/client.py b/seed/python-sdk/exhaustive/improved_imports/src/seed/inlined_requests/client.py index 38e428f66e0..bfb17877f08 100644 --- a/seed/python-sdk/exhaustive/improved_imports/src/seed/inlined_requests/client.py +++ b/seed/python-sdk/exhaustive/improved_imports/src/seed/inlined_requests/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..general_errors.errors.bad_request_body import BadRequestBody from ..general_errors.types.bad_object_request_info import BadObjectRequestInfo @@ -29,7 +25,7 @@ def post_with_object_bodyand_response( string: str, integer: int, nested_object: ObjectWithOptionalField, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> ObjectWithOptionalField: """ POST with custom object in request body, response is an object @@ -87,32 +83,11 @@ def post_with_object_bodyand_response( ) """ _response = self._client_wrapper.httpx_client.request( + "req-bodies/object", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "req-bodies/object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "integer": integer, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -135,7 +110,7 @@ async def post_with_object_bodyand_response( string: str, integer: int, nested_object: ObjectWithOptionalField, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> ObjectWithOptionalField: """ POST with custom object in request body, response is an object @@ -193,32 +168,11 @@ async def post_with_object_bodyand_response( ) """ _response = await self._client_wrapper.httpx_client.request( + "req-bodies/object", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "req-bodies/object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "integer": integer, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/improved_imports/src/seed/no_auth/client.py b/seed/python-sdk/exhaustive/improved_imports/src/seed/no_auth/client.py index fd4814dde0b..477bf563998 100644 --- a/seed/python-sdk/exhaustive/improved_imports/src/seed/no_auth/client.py +++ b/seed/python-sdk/exhaustive/improved_imports/src/seed/no_auth/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..general_errors.errors.bad_request_body import BadRequestBody from ..general_errors.types.bad_object_request_info import BadObjectRequestInfo @@ -52,32 +48,7 @@ def post_with_no_auth( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-auth", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -124,32 +95,7 @@ async def post_with_no_auth( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-auth", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/improved_imports/src/seed/no_req_body/client.py b/seed/python-sdk/exhaustive/improved_imports/src/seed/no_req_body/client.py index f984b6c24d3..7e3fd3ae95f 100644 --- a/seed/python-sdk/exhaustive/improved_imports/src/seed/no_req_body/client.py +++ b/seed/python-sdk/exhaustive/improved_imports/src/seed/no_req_body/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..types.object.types.object_with_optional_field import ObjectWithOptionalField @@ -42,26 +38,7 @@ def get_with_no_request_body( client.no_req_body.get_with_no_request_body() """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -93,29 +70,7 @@ def post_with_no_request_body(self, *, request_options: typing.Optional[RequestO client.no_req_body.post_with_no_request_body() """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -154,26 +109,7 @@ async def get_with_no_request_body( await client.no_req_body.get_with_no_request_body() """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -205,29 +141,7 @@ async def post_with_no_request_body(self, *, request_options: typing.Optional[Re await client.no_req_body.post_with_no_request_body() """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/improved_imports/src/seed/req_with_headers/client.py b/seed/python-sdk/exhaustive/improved_imports/src/seed/req_with_headers/client.py index 3e7f80e7435..4ec08e7ee09 100644 --- a/seed/python-sdk/exhaustive/improved_imports/src/seed/req_with_headers/client.py +++ b/seed/python-sdk/exhaustive/improved_imports/src/seed/req_with_headers/client.py @@ -1,14 +1,10 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -25,7 +21,7 @@ def get_with_custom_header( x_test_service_header: str, x_test_endpoint_header: str, request: str, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -58,33 +54,15 @@ def get_with_custom_header( ) """ _response = self._client_wrapper.httpx_client.request( + "test-headers/custom-header", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "test-headers/custom-header"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-TEST-SERVICE-HEADER": str(x_test_service_header) - if x_test_service_header is not None - else None, - "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) - if x_test_endpoint_header is not None - else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + headers={ + "X-TEST-SERVICE-HEADER": str(x_test_service_header) if x_test_service_header is not None else None, + "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) if x_test_endpoint_header is not None else None, + }, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return @@ -105,7 +83,7 @@ async def get_with_custom_header( x_test_service_header: str, x_test_endpoint_header: str, request: str, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -138,33 +116,15 @@ async def get_with_custom_header( ) """ _response = await self._client_wrapper.httpx_client.request( + "test-headers/custom-header", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "test-headers/custom-header"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-TEST-SERVICE-HEADER": str(x_test_service_header) - if x_test_service_header is not None - else None, - "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) - if x_test_endpoint_header is not None - else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + headers={ + "X-TEST-SERVICE-HEADER": str(x_test_service_header) if x_test_service_header is not None else None, + "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) if x_test_endpoint_header is not None else None, + }, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return diff --git a/seed/python-sdk/exhaustive/infinite-timeout/src/seed/core/client_wrapper.py b/seed/python-sdk/exhaustive/infinite-timeout/src/seed/core/client_wrapper.py index 5b0c9d5ad91..8d01b584b82 100644 --- a/seed/python-sdk/exhaustive/infinite-timeout/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/exhaustive/infinite-timeout/src/seed/core/client_wrapper.py @@ -53,7 +53,12 @@ def __init__( httpx_client: httpx.Client, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): @@ -66,4 +71,9 @@ def __init__( httpx_client: httpx.AsyncClient, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/exhaustive/infinite-timeout/src/seed/core/http_client.py b/seed/python-sdk/exhaustive/infinite-timeout/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/exhaustive/infinite-timeout/src/seed/core/http_client.py +++ b/seed/python-sdk/exhaustive/infinite-timeout/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/exhaustive/infinite-timeout/src/seed/endpoints/container/client.py b/seed/python-sdk/exhaustive/infinite-timeout/src/seed/endpoints/container/client.py index c5ab55847c7..e02bf812398 100644 --- a/seed/python-sdk/exhaustive/infinite-timeout/src/seed/endpoints/container/client.py +++ b/seed/python-sdk/exhaustive/infinite-timeout/src/seed/endpoints/container/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.object_with_required_field import ObjectWithRequiredField @@ -49,32 +45,7 @@ def get_and_return_list_of_primitives( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[str], _response.json()) # type: ignore @@ -88,7 +59,7 @@ def get_and_return_list_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -120,32 +91,7 @@ def get_and_return_list_of_objects( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -183,32 +129,7 @@ def get_and_return_set_of_primitives( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Set[str], _response.json()) # type: ignore @@ -222,7 +143,7 @@ def get_and_return_set_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -254,32 +175,7 @@ def get_and_return_set_of_objects( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -317,32 +213,7 @@ def get_and_return_map_prim_to_prim( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-prim"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-prim", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, str], _response.json()) # type: ignore @@ -356,7 +227,7 @@ def get_and_return_map_of_prim_to_object( self, *, request: typing.Dict[str, ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Dict[str, ObjectWithRequiredField]: """ Parameters @@ -388,32 +259,7 @@ def get_and_return_map_of_prim_to_object( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-object", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, ObjectWithRequiredField], _response.json()) # type: ignore @@ -427,7 +273,7 @@ def get_and_return_optional( self, *, request: typing.Optional[ObjectWithRequiredField] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Optional[ObjectWithRequiredField]: """ Parameters @@ -457,32 +303,7 @@ def get_and_return_optional( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/opt-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/opt-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Optional[ObjectWithRequiredField], _response.json()) # type: ignore @@ -525,32 +346,7 @@ async def get_and_return_list_of_primitives( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[str], _response.json()) # type: ignore @@ -564,7 +360,7 @@ async def get_and_return_list_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -596,32 +392,7 @@ async def get_and_return_list_of_objects( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -659,32 +430,7 @@ async def get_and_return_set_of_primitives( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Set[str], _response.json()) # type: ignore @@ -698,7 +444,7 @@ async def get_and_return_set_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -730,32 +476,7 @@ async def get_and_return_set_of_objects( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -793,32 +514,7 @@ async def get_and_return_map_prim_to_prim( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-prim"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-prim", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, str], _response.json()) # type: ignore @@ -832,7 +528,7 @@ async def get_and_return_map_of_prim_to_object( self, *, request: typing.Dict[str, ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Dict[str, ObjectWithRequiredField]: """ Parameters @@ -864,32 +560,7 @@ async def get_and_return_map_of_prim_to_object( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-object", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, ObjectWithRequiredField], _response.json()) # type: ignore @@ -903,7 +574,7 @@ async def get_and_return_optional( self, *, request: typing.Optional[ObjectWithRequiredField] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Optional[ObjectWithRequiredField]: """ Parameters @@ -933,32 +604,7 @@ async def get_and_return_optional( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/opt-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/opt-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Optional[ObjectWithRequiredField], _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/infinite-timeout/src/seed/endpoints/enum/client.py b/seed/python-sdk/exhaustive/infinite-timeout/src/seed/endpoints/enum/client.py index 94ee2ac420f..8fcd0668b4b 100644 --- a/seed/python-sdk/exhaustive/infinite-timeout/src/seed/endpoints/enum/client.py +++ b/seed/python-sdk/exhaustive/infinite-timeout/src/seed/endpoints/enum/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.enum.types.weather_report import WeatherReport @@ -49,27 +45,7 @@ def get_and_return_enum( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "enum"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "enum", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(WeatherReport, _response.json()) # type: ignore @@ -112,27 +88,7 @@ async def get_and_return_enum( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "enum"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "enum", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(WeatherReport, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/infinite-timeout/src/seed/endpoints/http_methods/client.py b/seed/python-sdk/exhaustive/infinite-timeout/src/seed/endpoints/http_methods/client.py index 1c8af11a4bd..3bd65f6adda 100644 --- a/seed/python-sdk/exhaustive/infinite-timeout/src/seed/endpoints/http_methods/client.py +++ b/seed/python-sdk/exhaustive/infinite-timeout/src/seed/endpoints/http_methods/client.py @@ -2,7 +2,6 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError @@ -10,8 +9,6 @@ from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.object_with_optional_field import ObjectWithOptionalField @@ -49,26 +46,7 @@ def test_get(self, id: str, *, request_options: typing.Optional[RequestOptions] ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -105,34 +83,8 @@ def test_post( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "http-methods"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "http-methods", method="POST", json={"string": string}, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -172,34 +124,12 @@ def test_put( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PUT", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -296,58 +226,25 @@ def test_patch( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PATCH", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -383,29 +280,7 @@ def test_delete(self, id: str, *, request_options: typing.Optional[RequestOption ) """ _response = self._client_wrapper.httpx_client.request( - method="DELETE", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="DELETE", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -446,26 +321,7 @@ async def test_get(self, id: str, *, request_options: typing.Optional[RequestOpt ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -502,34 +358,8 @@ async def test_post( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "http-methods"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "http-methods", method="POST", json={"string": string}, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -569,34 +399,12 @@ async def test_put( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PUT", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -693,58 +501,25 @@ async def test_patch( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = await self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PATCH", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -780,29 +555,7 @@ async def test_delete(self, id: str, *, request_options: typing.Optional[Request ) """ _response = await self._client_wrapper.httpx_client.request( - method="DELETE", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="DELETE", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/infinite-timeout/src/seed/endpoints/object/client.py b/seed/python-sdk/exhaustive/infinite-timeout/src/seed/endpoints/object/client.py index 83230dec1f4..7e66510fdb0 100644 --- a/seed/python-sdk/exhaustive/infinite-timeout/src/seed/endpoints/object/client.py +++ b/seed/python-sdk/exhaustive/infinite-timeout/src/seed/endpoints/object/client.py @@ -2,7 +2,6 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError @@ -10,8 +9,6 @@ from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.nested_object_with_optional_field import NestedObjectWithOptionalField from ...types.object.types.nested_object_with_required_field import NestedObjectWithRequiredField @@ -110,60 +107,25 @@ def get_and_return_with_optional_field( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -200,36 +162,12 @@ def get_and_return_with_required_field( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-required-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-required-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithRequiredField, _response.json()) # type: ignore @@ -266,36 +204,12 @@ def get_and_return_with_map_of_map( map_={"string": {"string": "string"}}, ) """ - _request: typing.Dict[str, typing.Any] = {"map": map_} _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-map-of-map", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-map-of-map" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"map": map_}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithMapOfMap, _response.json()) # type: ignore @@ -362,40 +276,12 @@ def get_and_return_nested_with_optional_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if nested_object is not OMIT: - _request["NestedObject"] = nested_object _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithOptionalField, _response.json()) # type: ignore @@ -466,37 +352,12 @@ def get_and_return_nested_with_required_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {"string": string, "NestedObject": nested_object} _response = self._client_wrapper.httpx_client.request( + f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", - f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -565,34 +426,11 @@ def get_and_return_nested_with_required_field_as_list( ) """ _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-required-field-list", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-required-field-list" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -690,60 +528,25 @@ async def get_and_return_with_optional_field( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -780,36 +583,12 @@ async def get_and_return_with_required_field( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-required-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-required-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithRequiredField, _response.json()) # type: ignore @@ -846,36 +625,12 @@ async def get_and_return_with_map_of_map( map_={"string": {"string": "string"}}, ) """ - _request: typing.Dict[str, typing.Any] = {"map": map_} _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-map-of-map", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-map-of-map" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"map": map_}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithMapOfMap, _response.json()) # type: ignore @@ -942,40 +697,12 @@ async def get_and_return_nested_with_optional_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if nested_object is not OMIT: - _request["NestedObject"] = nested_object _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithOptionalField, _response.json()) # type: ignore @@ -1046,37 +773,12 @@ async def get_and_return_nested_with_required_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {"string": string, "NestedObject": nested_object} _response = await self._client_wrapper.httpx_client.request( + f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", - f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -1145,34 +847,11 @@ async def get_and_return_nested_with_required_field_as_list( ) """ _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-required-field-list", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-required-field-list" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/infinite-timeout/src/seed/endpoints/params/client.py b/seed/python-sdk/exhaustive/infinite-timeout/src/seed/endpoints/params/client.py index d1f25df27fb..089d9fab5ce 100644 --- a/seed/python-sdk/exhaustive/infinite-timeout/src/seed/endpoints/params/client.py +++ b/seed/python-sdk/exhaustive/infinite-timeout/src/seed/endpoints/params/client.py @@ -1,15 +1,12 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -48,28 +45,7 @@ def get_with_path(self, param: str, *, request_options: typing.Optional[RequestO ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"params/path/{jsonable_encoder(param)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -112,36 +88,7 @@ def get_with_query( ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "number": number, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "number": number}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -188,36 +135,7 @@ def get_with_allow_multiple_query( ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "numer": numer, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "numer": numer}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -260,37 +178,10 @@ def get_with_path_and_query( ) """ _response = self._client_wrapper.httpx_client.request( + f"params/path-query/{jsonable_encoder(param)}", method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path-query/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"query": query}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -333,29 +224,11 @@ def modify_with_path( ) """ _response = self._client_wrapper.httpx_client.request( + f"params/path/{jsonable_encoder(param)}", method="PUT", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -398,28 +271,7 @@ async def get_with_path(self, param: str, *, request_options: typing.Optional[Re ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"params/path/{jsonable_encoder(param)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -462,36 +314,7 @@ async def get_with_query( ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "number": number, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "number": number}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -538,36 +361,7 @@ async def get_with_allow_multiple_query( ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "numer": numer, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "numer": numer}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -610,37 +404,10 @@ async def get_with_path_and_query( ) """ _response = await self._client_wrapper.httpx_client.request( + f"params/path-query/{jsonable_encoder(param)}", method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path-query/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"query": query}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -683,29 +450,11 @@ async def modify_with_path( ) """ _response = await self._client_wrapper.httpx_client.request( + f"params/path/{jsonable_encoder(param)}", method="PUT", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/infinite-timeout/src/seed/endpoints/primitive/client.py b/seed/python-sdk/exhaustive/infinite-timeout/src/seed/endpoints/primitive/client.py index 076383510ff..64c7f6b2ca5 100644 --- a/seed/python-sdk/exhaustive/infinite-timeout/src/seed/endpoints/primitive/client.py +++ b/seed/python-sdk/exhaustive/infinite-timeout/src/seed/endpoints/primitive/client.py @@ -2,16 +2,12 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -48,27 +44,7 @@ def get_and_return_string(self, *, request: str, request_options: typing.Optiona ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/string"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/string", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -104,27 +80,7 @@ def get_and_return_int(self, *, request: int, request_options: typing.Optional[R ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/integer"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/integer", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -160,32 +116,7 @@ def get_and_return_long(self, *, request: int, request_options: typing.Optional[ ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/long"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/long", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -223,27 +154,7 @@ def get_and_return_double( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/double"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/double", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(float, _response.json()) # type: ignore @@ -279,27 +190,7 @@ def get_and_return_bool(self, *, request: bool, request_options: typing.Optional ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/boolean"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/boolean", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -341,32 +232,7 @@ def get_and_return_datetime( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/datetime"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/datetime", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.datetime, _response.json()) # type: ignore @@ -408,32 +274,7 @@ def get_and_return_date( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/date"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/date", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.date, _response.json()) # type: ignore @@ -475,32 +316,7 @@ def get_and_return_uuid( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/uuid"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/uuid", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(uuid.UUID, _response.json()) # type: ignore @@ -536,32 +352,7 @@ def get_and_return_base_64(self, *, request: str, request_options: typing.Option ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/base64"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/base64", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -604,27 +395,7 @@ async def get_and_return_string( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/string"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/string", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -660,27 +431,7 @@ async def get_and_return_int(self, *, request: int, request_options: typing.Opti ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/integer"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/integer", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -718,32 +469,7 @@ async def get_and_return_long( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/long"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/long", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -781,27 +507,7 @@ async def get_and_return_double( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/double"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/double", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(float, _response.json()) # type: ignore @@ -839,27 +545,7 @@ async def get_and_return_bool( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/boolean"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/boolean", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -901,32 +587,7 @@ async def get_and_return_datetime( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/datetime"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/datetime", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.datetime, _response.json()) # type: ignore @@ -968,32 +629,7 @@ async def get_and_return_date( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/date"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/date", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.date, _response.json()) # type: ignore @@ -1035,32 +671,7 @@ async def get_and_return_uuid( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/uuid"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/uuid", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(uuid.UUID, _response.json()) # type: ignore @@ -1098,32 +709,7 @@ async def get_and_return_base_64( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/base64"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/base64", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/infinite-timeout/src/seed/endpoints/union/client.py b/seed/python-sdk/exhaustive/infinite-timeout/src/seed/endpoints/union/client.py index 23757c07bd8..843d9828bc6 100644 --- a/seed/python-sdk/exhaustive/infinite-timeout/src/seed/endpoints/union/client.py +++ b/seed/python-sdk/exhaustive/infinite-timeout/src/seed/endpoints/union/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.union.types.animal import Animal @@ -53,32 +49,7 @@ def get_and_return_union( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "union"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "union", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Animal, _response.json()) # type: ignore @@ -125,32 +96,7 @@ async def get_and_return_union( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "union"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "union", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Animal, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/infinite-timeout/src/seed/inlined_requests/client.py b/seed/python-sdk/exhaustive/infinite-timeout/src/seed/inlined_requests/client.py index 38e428f66e0..bfb17877f08 100644 --- a/seed/python-sdk/exhaustive/infinite-timeout/src/seed/inlined_requests/client.py +++ b/seed/python-sdk/exhaustive/infinite-timeout/src/seed/inlined_requests/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..general_errors.errors.bad_request_body import BadRequestBody from ..general_errors.types.bad_object_request_info import BadObjectRequestInfo @@ -29,7 +25,7 @@ def post_with_object_bodyand_response( string: str, integer: int, nested_object: ObjectWithOptionalField, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> ObjectWithOptionalField: """ POST with custom object in request body, response is an object @@ -87,32 +83,11 @@ def post_with_object_bodyand_response( ) """ _response = self._client_wrapper.httpx_client.request( + "req-bodies/object", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "req-bodies/object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "integer": integer, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -135,7 +110,7 @@ async def post_with_object_bodyand_response( string: str, integer: int, nested_object: ObjectWithOptionalField, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> ObjectWithOptionalField: """ POST with custom object in request body, response is an object @@ -193,32 +168,11 @@ async def post_with_object_bodyand_response( ) """ _response = await self._client_wrapper.httpx_client.request( + "req-bodies/object", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "req-bodies/object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "integer": integer, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/infinite-timeout/src/seed/no_auth/client.py b/seed/python-sdk/exhaustive/infinite-timeout/src/seed/no_auth/client.py index fd4814dde0b..477bf563998 100644 --- a/seed/python-sdk/exhaustive/infinite-timeout/src/seed/no_auth/client.py +++ b/seed/python-sdk/exhaustive/infinite-timeout/src/seed/no_auth/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..general_errors.errors.bad_request_body import BadRequestBody from ..general_errors.types.bad_object_request_info import BadObjectRequestInfo @@ -52,32 +48,7 @@ def post_with_no_auth( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-auth", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -124,32 +95,7 @@ async def post_with_no_auth( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-auth", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/infinite-timeout/src/seed/no_req_body/client.py b/seed/python-sdk/exhaustive/infinite-timeout/src/seed/no_req_body/client.py index f984b6c24d3..7e3fd3ae95f 100644 --- a/seed/python-sdk/exhaustive/infinite-timeout/src/seed/no_req_body/client.py +++ b/seed/python-sdk/exhaustive/infinite-timeout/src/seed/no_req_body/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..types.object.types.object_with_optional_field import ObjectWithOptionalField @@ -42,26 +38,7 @@ def get_with_no_request_body( client.no_req_body.get_with_no_request_body() """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -93,29 +70,7 @@ def post_with_no_request_body(self, *, request_options: typing.Optional[RequestO client.no_req_body.post_with_no_request_body() """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -154,26 +109,7 @@ async def get_with_no_request_body( await client.no_req_body.get_with_no_request_body() """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -205,29 +141,7 @@ async def post_with_no_request_body(self, *, request_options: typing.Optional[Re await client.no_req_body.post_with_no_request_body() """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/infinite-timeout/src/seed/req_with_headers/client.py b/seed/python-sdk/exhaustive/infinite-timeout/src/seed/req_with_headers/client.py index 3e7f80e7435..4ec08e7ee09 100644 --- a/seed/python-sdk/exhaustive/infinite-timeout/src/seed/req_with_headers/client.py +++ b/seed/python-sdk/exhaustive/infinite-timeout/src/seed/req_with_headers/client.py @@ -1,14 +1,10 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -25,7 +21,7 @@ def get_with_custom_header( x_test_service_header: str, x_test_endpoint_header: str, request: str, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -58,33 +54,15 @@ def get_with_custom_header( ) """ _response = self._client_wrapper.httpx_client.request( + "test-headers/custom-header", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "test-headers/custom-header"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-TEST-SERVICE-HEADER": str(x_test_service_header) - if x_test_service_header is not None - else None, - "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) - if x_test_endpoint_header is not None - else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + headers={ + "X-TEST-SERVICE-HEADER": str(x_test_service_header) if x_test_service_header is not None else None, + "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) if x_test_endpoint_header is not None else None, + }, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return @@ -105,7 +83,7 @@ async def get_with_custom_header( x_test_service_header: str, x_test_endpoint_header: str, request: str, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -138,33 +116,15 @@ async def get_with_custom_header( ) """ _response = await self._client_wrapper.httpx_client.request( + "test-headers/custom-header", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "test-headers/custom-header"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-TEST-SERVICE-HEADER": str(x_test_service_header) - if x_test_service_header is not None - else None, - "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) - if x_test_endpoint_header is not None - else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + headers={ + "X-TEST-SERVICE-HEADER": str(x_test_service_header) if x_test_service_header is not None else None, + "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) if x_test_endpoint_header is not None else None, + }, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return diff --git a/seed/python-sdk/exhaustive/inline_request_params/src/seed/core/client_wrapper.py b/seed/python-sdk/exhaustive/inline_request_params/src/seed/core/client_wrapper.py index 5b0c9d5ad91..8d01b584b82 100644 --- a/seed/python-sdk/exhaustive/inline_request_params/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/exhaustive/inline_request_params/src/seed/core/client_wrapper.py @@ -53,7 +53,12 @@ def __init__( httpx_client: httpx.Client, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): @@ -66,4 +71,9 @@ def __init__( httpx_client: httpx.AsyncClient, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/exhaustive/inline_request_params/src/seed/core/http_client.py b/seed/python-sdk/exhaustive/inline_request_params/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/exhaustive/inline_request_params/src/seed/core/http_client.py +++ b/seed/python-sdk/exhaustive/inline_request_params/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/exhaustive/inline_request_params/src/seed/endpoints/container/client.py b/seed/python-sdk/exhaustive/inline_request_params/src/seed/endpoints/container/client.py index c5ab55847c7..e02bf812398 100644 --- a/seed/python-sdk/exhaustive/inline_request_params/src/seed/endpoints/container/client.py +++ b/seed/python-sdk/exhaustive/inline_request_params/src/seed/endpoints/container/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.object_with_required_field import ObjectWithRequiredField @@ -49,32 +45,7 @@ def get_and_return_list_of_primitives( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[str], _response.json()) # type: ignore @@ -88,7 +59,7 @@ def get_and_return_list_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -120,32 +91,7 @@ def get_and_return_list_of_objects( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -183,32 +129,7 @@ def get_and_return_set_of_primitives( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Set[str], _response.json()) # type: ignore @@ -222,7 +143,7 @@ def get_and_return_set_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -254,32 +175,7 @@ def get_and_return_set_of_objects( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -317,32 +213,7 @@ def get_and_return_map_prim_to_prim( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-prim"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-prim", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, str], _response.json()) # type: ignore @@ -356,7 +227,7 @@ def get_and_return_map_of_prim_to_object( self, *, request: typing.Dict[str, ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Dict[str, ObjectWithRequiredField]: """ Parameters @@ -388,32 +259,7 @@ def get_and_return_map_of_prim_to_object( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-object", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, ObjectWithRequiredField], _response.json()) # type: ignore @@ -427,7 +273,7 @@ def get_and_return_optional( self, *, request: typing.Optional[ObjectWithRequiredField] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Optional[ObjectWithRequiredField]: """ Parameters @@ -457,32 +303,7 @@ def get_and_return_optional( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/opt-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/opt-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Optional[ObjectWithRequiredField], _response.json()) # type: ignore @@ -525,32 +346,7 @@ async def get_and_return_list_of_primitives( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[str], _response.json()) # type: ignore @@ -564,7 +360,7 @@ async def get_and_return_list_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -596,32 +392,7 @@ async def get_and_return_list_of_objects( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -659,32 +430,7 @@ async def get_and_return_set_of_primitives( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Set[str], _response.json()) # type: ignore @@ -698,7 +444,7 @@ async def get_and_return_set_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -730,32 +476,7 @@ async def get_and_return_set_of_objects( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -793,32 +514,7 @@ async def get_and_return_map_prim_to_prim( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-prim"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-prim", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, str], _response.json()) # type: ignore @@ -832,7 +528,7 @@ async def get_and_return_map_of_prim_to_object( self, *, request: typing.Dict[str, ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Dict[str, ObjectWithRequiredField]: """ Parameters @@ -864,32 +560,7 @@ async def get_and_return_map_of_prim_to_object( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-object", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, ObjectWithRequiredField], _response.json()) # type: ignore @@ -903,7 +574,7 @@ async def get_and_return_optional( self, *, request: typing.Optional[ObjectWithRequiredField] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Optional[ObjectWithRequiredField]: """ Parameters @@ -933,32 +604,7 @@ async def get_and_return_optional( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/opt-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/opt-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Optional[ObjectWithRequiredField], _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/inline_request_params/src/seed/endpoints/enum/client.py b/seed/python-sdk/exhaustive/inline_request_params/src/seed/endpoints/enum/client.py index 94ee2ac420f..8fcd0668b4b 100644 --- a/seed/python-sdk/exhaustive/inline_request_params/src/seed/endpoints/enum/client.py +++ b/seed/python-sdk/exhaustive/inline_request_params/src/seed/endpoints/enum/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.enum.types.weather_report import WeatherReport @@ -49,27 +45,7 @@ def get_and_return_enum( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "enum"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "enum", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(WeatherReport, _response.json()) # type: ignore @@ -112,27 +88,7 @@ async def get_and_return_enum( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "enum"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "enum", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(WeatherReport, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/inline_request_params/src/seed/endpoints/http_methods/client.py b/seed/python-sdk/exhaustive/inline_request_params/src/seed/endpoints/http_methods/client.py index 1c8af11a4bd..3bd65f6adda 100644 --- a/seed/python-sdk/exhaustive/inline_request_params/src/seed/endpoints/http_methods/client.py +++ b/seed/python-sdk/exhaustive/inline_request_params/src/seed/endpoints/http_methods/client.py @@ -2,7 +2,6 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError @@ -10,8 +9,6 @@ from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.object_with_optional_field import ObjectWithOptionalField @@ -49,26 +46,7 @@ def test_get(self, id: str, *, request_options: typing.Optional[RequestOptions] ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -105,34 +83,8 @@ def test_post( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "http-methods"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "http-methods", method="POST", json={"string": string}, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -172,34 +124,12 @@ def test_put( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PUT", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -296,58 +226,25 @@ def test_patch( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PATCH", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -383,29 +280,7 @@ def test_delete(self, id: str, *, request_options: typing.Optional[RequestOption ) """ _response = self._client_wrapper.httpx_client.request( - method="DELETE", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="DELETE", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -446,26 +321,7 @@ async def test_get(self, id: str, *, request_options: typing.Optional[RequestOpt ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -502,34 +358,8 @@ async def test_post( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "http-methods"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "http-methods", method="POST", json={"string": string}, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -569,34 +399,12 @@ async def test_put( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PUT", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -693,58 +501,25 @@ async def test_patch( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = await self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PATCH", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -780,29 +555,7 @@ async def test_delete(self, id: str, *, request_options: typing.Optional[Request ) """ _response = await self._client_wrapper.httpx_client.request( - method="DELETE", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="DELETE", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/inline_request_params/src/seed/endpoints/object/client.py b/seed/python-sdk/exhaustive/inline_request_params/src/seed/endpoints/object/client.py index 83230dec1f4..7e66510fdb0 100644 --- a/seed/python-sdk/exhaustive/inline_request_params/src/seed/endpoints/object/client.py +++ b/seed/python-sdk/exhaustive/inline_request_params/src/seed/endpoints/object/client.py @@ -2,7 +2,6 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError @@ -10,8 +9,6 @@ from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.nested_object_with_optional_field import NestedObjectWithOptionalField from ...types.object.types.nested_object_with_required_field import NestedObjectWithRequiredField @@ -110,60 +107,25 @@ def get_and_return_with_optional_field( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -200,36 +162,12 @@ def get_and_return_with_required_field( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-required-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-required-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithRequiredField, _response.json()) # type: ignore @@ -266,36 +204,12 @@ def get_and_return_with_map_of_map( map_={"string": {"string": "string"}}, ) """ - _request: typing.Dict[str, typing.Any] = {"map": map_} _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-map-of-map", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-map-of-map" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"map": map_}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithMapOfMap, _response.json()) # type: ignore @@ -362,40 +276,12 @@ def get_and_return_nested_with_optional_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if nested_object is not OMIT: - _request["NestedObject"] = nested_object _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithOptionalField, _response.json()) # type: ignore @@ -466,37 +352,12 @@ def get_and_return_nested_with_required_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {"string": string, "NestedObject": nested_object} _response = self._client_wrapper.httpx_client.request( + f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", - f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -565,34 +426,11 @@ def get_and_return_nested_with_required_field_as_list( ) """ _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-required-field-list", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-required-field-list" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -690,60 +528,25 @@ async def get_and_return_with_optional_field( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -780,36 +583,12 @@ async def get_and_return_with_required_field( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-required-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-required-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithRequiredField, _response.json()) # type: ignore @@ -846,36 +625,12 @@ async def get_and_return_with_map_of_map( map_={"string": {"string": "string"}}, ) """ - _request: typing.Dict[str, typing.Any] = {"map": map_} _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-map-of-map", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-map-of-map" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"map": map_}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithMapOfMap, _response.json()) # type: ignore @@ -942,40 +697,12 @@ async def get_and_return_nested_with_optional_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if nested_object is not OMIT: - _request["NestedObject"] = nested_object _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithOptionalField, _response.json()) # type: ignore @@ -1046,37 +773,12 @@ async def get_and_return_nested_with_required_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {"string": string, "NestedObject": nested_object} _response = await self._client_wrapper.httpx_client.request( + f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", - f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -1145,34 +847,11 @@ async def get_and_return_nested_with_required_field_as_list( ) """ _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-required-field-list", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-required-field-list" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/inline_request_params/src/seed/endpoints/params/client.py b/seed/python-sdk/exhaustive/inline_request_params/src/seed/endpoints/params/client.py index d1f25df27fb..089d9fab5ce 100644 --- a/seed/python-sdk/exhaustive/inline_request_params/src/seed/endpoints/params/client.py +++ b/seed/python-sdk/exhaustive/inline_request_params/src/seed/endpoints/params/client.py @@ -1,15 +1,12 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -48,28 +45,7 @@ def get_with_path(self, param: str, *, request_options: typing.Optional[RequestO ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"params/path/{jsonable_encoder(param)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -112,36 +88,7 @@ def get_with_query( ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "number": number, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "number": number}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -188,36 +135,7 @@ def get_with_allow_multiple_query( ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "numer": numer, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "numer": numer}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -260,37 +178,10 @@ def get_with_path_and_query( ) """ _response = self._client_wrapper.httpx_client.request( + f"params/path-query/{jsonable_encoder(param)}", method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path-query/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"query": query}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -333,29 +224,11 @@ def modify_with_path( ) """ _response = self._client_wrapper.httpx_client.request( + f"params/path/{jsonable_encoder(param)}", method="PUT", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -398,28 +271,7 @@ async def get_with_path(self, param: str, *, request_options: typing.Optional[Re ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"params/path/{jsonable_encoder(param)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -462,36 +314,7 @@ async def get_with_query( ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "number": number, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "number": number}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -538,36 +361,7 @@ async def get_with_allow_multiple_query( ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "numer": numer, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "numer": numer}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -610,37 +404,10 @@ async def get_with_path_and_query( ) """ _response = await self._client_wrapper.httpx_client.request( + f"params/path-query/{jsonable_encoder(param)}", method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path-query/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"query": query}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -683,29 +450,11 @@ async def modify_with_path( ) """ _response = await self._client_wrapper.httpx_client.request( + f"params/path/{jsonable_encoder(param)}", method="PUT", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/inline_request_params/src/seed/endpoints/primitive/client.py b/seed/python-sdk/exhaustive/inline_request_params/src/seed/endpoints/primitive/client.py index 076383510ff..64c7f6b2ca5 100644 --- a/seed/python-sdk/exhaustive/inline_request_params/src/seed/endpoints/primitive/client.py +++ b/seed/python-sdk/exhaustive/inline_request_params/src/seed/endpoints/primitive/client.py @@ -2,16 +2,12 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -48,27 +44,7 @@ def get_and_return_string(self, *, request: str, request_options: typing.Optiona ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/string"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/string", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -104,27 +80,7 @@ def get_and_return_int(self, *, request: int, request_options: typing.Optional[R ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/integer"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/integer", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -160,32 +116,7 @@ def get_and_return_long(self, *, request: int, request_options: typing.Optional[ ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/long"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/long", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -223,27 +154,7 @@ def get_and_return_double( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/double"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/double", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(float, _response.json()) # type: ignore @@ -279,27 +190,7 @@ def get_and_return_bool(self, *, request: bool, request_options: typing.Optional ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/boolean"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/boolean", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -341,32 +232,7 @@ def get_and_return_datetime( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/datetime"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/datetime", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.datetime, _response.json()) # type: ignore @@ -408,32 +274,7 @@ def get_and_return_date( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/date"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/date", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.date, _response.json()) # type: ignore @@ -475,32 +316,7 @@ def get_and_return_uuid( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/uuid"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/uuid", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(uuid.UUID, _response.json()) # type: ignore @@ -536,32 +352,7 @@ def get_and_return_base_64(self, *, request: str, request_options: typing.Option ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/base64"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/base64", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -604,27 +395,7 @@ async def get_and_return_string( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/string"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/string", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -660,27 +431,7 @@ async def get_and_return_int(self, *, request: int, request_options: typing.Opti ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/integer"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/integer", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -718,32 +469,7 @@ async def get_and_return_long( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/long"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/long", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -781,27 +507,7 @@ async def get_and_return_double( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/double"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/double", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(float, _response.json()) # type: ignore @@ -839,27 +545,7 @@ async def get_and_return_bool( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/boolean"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/boolean", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -901,32 +587,7 @@ async def get_and_return_datetime( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/datetime"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/datetime", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.datetime, _response.json()) # type: ignore @@ -968,32 +629,7 @@ async def get_and_return_date( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/date"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/date", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.date, _response.json()) # type: ignore @@ -1035,32 +671,7 @@ async def get_and_return_uuid( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/uuid"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/uuid", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(uuid.UUID, _response.json()) # type: ignore @@ -1098,32 +709,7 @@ async def get_and_return_base_64( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/base64"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/base64", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/inline_request_params/src/seed/endpoints/union/client.py b/seed/python-sdk/exhaustive/inline_request_params/src/seed/endpoints/union/client.py index 23757c07bd8..843d9828bc6 100644 --- a/seed/python-sdk/exhaustive/inline_request_params/src/seed/endpoints/union/client.py +++ b/seed/python-sdk/exhaustive/inline_request_params/src/seed/endpoints/union/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.union.types.animal import Animal @@ -53,32 +49,7 @@ def get_and_return_union( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "union"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "union", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Animal, _response.json()) # type: ignore @@ -125,32 +96,7 @@ async def get_and_return_union( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "union"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "union", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Animal, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/inline_request_params/src/seed/inlined_requests/client.py b/seed/python-sdk/exhaustive/inline_request_params/src/seed/inlined_requests/client.py index 38e428f66e0..bfb17877f08 100644 --- a/seed/python-sdk/exhaustive/inline_request_params/src/seed/inlined_requests/client.py +++ b/seed/python-sdk/exhaustive/inline_request_params/src/seed/inlined_requests/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..general_errors.errors.bad_request_body import BadRequestBody from ..general_errors.types.bad_object_request_info import BadObjectRequestInfo @@ -29,7 +25,7 @@ def post_with_object_bodyand_response( string: str, integer: int, nested_object: ObjectWithOptionalField, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> ObjectWithOptionalField: """ POST with custom object in request body, response is an object @@ -87,32 +83,11 @@ def post_with_object_bodyand_response( ) """ _response = self._client_wrapper.httpx_client.request( + "req-bodies/object", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "req-bodies/object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "integer": integer, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -135,7 +110,7 @@ async def post_with_object_bodyand_response( string: str, integer: int, nested_object: ObjectWithOptionalField, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> ObjectWithOptionalField: """ POST with custom object in request body, response is an object @@ -193,32 +168,11 @@ async def post_with_object_bodyand_response( ) """ _response = await self._client_wrapper.httpx_client.request( + "req-bodies/object", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "req-bodies/object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "integer": integer, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/inline_request_params/src/seed/no_auth/client.py b/seed/python-sdk/exhaustive/inline_request_params/src/seed/no_auth/client.py index fd4814dde0b..477bf563998 100644 --- a/seed/python-sdk/exhaustive/inline_request_params/src/seed/no_auth/client.py +++ b/seed/python-sdk/exhaustive/inline_request_params/src/seed/no_auth/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..general_errors.errors.bad_request_body import BadRequestBody from ..general_errors.types.bad_object_request_info import BadObjectRequestInfo @@ -52,32 +48,7 @@ def post_with_no_auth( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-auth", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -124,32 +95,7 @@ async def post_with_no_auth( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-auth", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/inline_request_params/src/seed/no_req_body/client.py b/seed/python-sdk/exhaustive/inline_request_params/src/seed/no_req_body/client.py index f984b6c24d3..7e3fd3ae95f 100644 --- a/seed/python-sdk/exhaustive/inline_request_params/src/seed/no_req_body/client.py +++ b/seed/python-sdk/exhaustive/inline_request_params/src/seed/no_req_body/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..types.object.types.object_with_optional_field import ObjectWithOptionalField @@ -42,26 +38,7 @@ def get_with_no_request_body( client.no_req_body.get_with_no_request_body() """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -93,29 +70,7 @@ def post_with_no_request_body(self, *, request_options: typing.Optional[RequestO client.no_req_body.post_with_no_request_body() """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -154,26 +109,7 @@ async def get_with_no_request_body( await client.no_req_body.get_with_no_request_body() """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -205,29 +141,7 @@ async def post_with_no_request_body(self, *, request_options: typing.Optional[Re await client.no_req_body.post_with_no_request_body() """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/inline_request_params/src/seed/req_with_headers/client.py b/seed/python-sdk/exhaustive/inline_request_params/src/seed/req_with_headers/client.py index 3e7f80e7435..4ec08e7ee09 100644 --- a/seed/python-sdk/exhaustive/inline_request_params/src/seed/req_with_headers/client.py +++ b/seed/python-sdk/exhaustive/inline_request_params/src/seed/req_with_headers/client.py @@ -1,14 +1,10 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -25,7 +21,7 @@ def get_with_custom_header( x_test_service_header: str, x_test_endpoint_header: str, request: str, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -58,33 +54,15 @@ def get_with_custom_header( ) """ _response = self._client_wrapper.httpx_client.request( + "test-headers/custom-header", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "test-headers/custom-header"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-TEST-SERVICE-HEADER": str(x_test_service_header) - if x_test_service_header is not None - else None, - "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) - if x_test_endpoint_header is not None - else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + headers={ + "X-TEST-SERVICE-HEADER": str(x_test_service_header) if x_test_service_header is not None else None, + "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) if x_test_endpoint_header is not None else None, + }, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return @@ -105,7 +83,7 @@ async def get_with_custom_header( x_test_service_header: str, x_test_endpoint_header: str, request: str, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -138,33 +116,15 @@ async def get_with_custom_header( ) """ _response = await self._client_wrapper.httpx_client.request( + "test-headers/custom-header", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "test-headers/custom-header"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-TEST-SERVICE-HEADER": str(x_test_service_header) - if x_test_service_header is not None - else None, - "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) - if x_test_endpoint_header is not None - else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + headers={ + "X-TEST-SERVICE-HEADER": str(x_test_service_header) if x_test_service_header is not None else None, + "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) if x_test_endpoint_header is not None else None, + }, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return diff --git a/seed/python-sdk/exhaustive/no-custom-config/src/seed/core/client_wrapper.py b/seed/python-sdk/exhaustive/no-custom-config/src/seed/core/client_wrapper.py index 5b0c9d5ad91..8d01b584b82 100644 --- a/seed/python-sdk/exhaustive/no-custom-config/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/exhaustive/no-custom-config/src/seed/core/client_wrapper.py @@ -53,7 +53,12 @@ def __init__( httpx_client: httpx.Client, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): @@ -66,4 +71,9 @@ def __init__( httpx_client: httpx.AsyncClient, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/exhaustive/no-custom-config/src/seed/core/http_client.py b/seed/python-sdk/exhaustive/no-custom-config/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/exhaustive/no-custom-config/src/seed/core/http_client.py +++ b/seed/python-sdk/exhaustive/no-custom-config/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/exhaustive/no-custom-config/src/seed/endpoints/container/client.py b/seed/python-sdk/exhaustive/no-custom-config/src/seed/endpoints/container/client.py index c5ab55847c7..e02bf812398 100644 --- a/seed/python-sdk/exhaustive/no-custom-config/src/seed/endpoints/container/client.py +++ b/seed/python-sdk/exhaustive/no-custom-config/src/seed/endpoints/container/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.object_with_required_field import ObjectWithRequiredField @@ -49,32 +45,7 @@ def get_and_return_list_of_primitives( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[str], _response.json()) # type: ignore @@ -88,7 +59,7 @@ def get_and_return_list_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -120,32 +91,7 @@ def get_and_return_list_of_objects( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -183,32 +129,7 @@ def get_and_return_set_of_primitives( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Set[str], _response.json()) # type: ignore @@ -222,7 +143,7 @@ def get_and_return_set_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -254,32 +175,7 @@ def get_and_return_set_of_objects( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -317,32 +213,7 @@ def get_and_return_map_prim_to_prim( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-prim"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-prim", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, str], _response.json()) # type: ignore @@ -356,7 +227,7 @@ def get_and_return_map_of_prim_to_object( self, *, request: typing.Dict[str, ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Dict[str, ObjectWithRequiredField]: """ Parameters @@ -388,32 +259,7 @@ def get_and_return_map_of_prim_to_object( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-object", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, ObjectWithRequiredField], _response.json()) # type: ignore @@ -427,7 +273,7 @@ def get_and_return_optional( self, *, request: typing.Optional[ObjectWithRequiredField] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Optional[ObjectWithRequiredField]: """ Parameters @@ -457,32 +303,7 @@ def get_and_return_optional( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/opt-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/opt-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Optional[ObjectWithRequiredField], _response.json()) # type: ignore @@ -525,32 +346,7 @@ async def get_and_return_list_of_primitives( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[str], _response.json()) # type: ignore @@ -564,7 +360,7 @@ async def get_and_return_list_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -596,32 +392,7 @@ async def get_and_return_list_of_objects( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -659,32 +430,7 @@ async def get_and_return_set_of_primitives( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Set[str], _response.json()) # type: ignore @@ -698,7 +444,7 @@ async def get_and_return_set_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -730,32 +476,7 @@ async def get_and_return_set_of_objects( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -793,32 +514,7 @@ async def get_and_return_map_prim_to_prim( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-prim"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-prim", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, str], _response.json()) # type: ignore @@ -832,7 +528,7 @@ async def get_and_return_map_of_prim_to_object( self, *, request: typing.Dict[str, ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Dict[str, ObjectWithRequiredField]: """ Parameters @@ -864,32 +560,7 @@ async def get_and_return_map_of_prim_to_object( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-object", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, ObjectWithRequiredField], _response.json()) # type: ignore @@ -903,7 +574,7 @@ async def get_and_return_optional( self, *, request: typing.Optional[ObjectWithRequiredField] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Optional[ObjectWithRequiredField]: """ Parameters @@ -933,32 +604,7 @@ async def get_and_return_optional( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/opt-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/opt-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Optional[ObjectWithRequiredField], _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/no-custom-config/src/seed/endpoints/enum/client.py b/seed/python-sdk/exhaustive/no-custom-config/src/seed/endpoints/enum/client.py index 94ee2ac420f..8fcd0668b4b 100644 --- a/seed/python-sdk/exhaustive/no-custom-config/src/seed/endpoints/enum/client.py +++ b/seed/python-sdk/exhaustive/no-custom-config/src/seed/endpoints/enum/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.enum.types.weather_report import WeatherReport @@ -49,27 +45,7 @@ def get_and_return_enum( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "enum"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "enum", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(WeatherReport, _response.json()) # type: ignore @@ -112,27 +88,7 @@ async def get_and_return_enum( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "enum"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "enum", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(WeatherReport, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/no-custom-config/src/seed/endpoints/http_methods/client.py b/seed/python-sdk/exhaustive/no-custom-config/src/seed/endpoints/http_methods/client.py index 1c8af11a4bd..3bd65f6adda 100644 --- a/seed/python-sdk/exhaustive/no-custom-config/src/seed/endpoints/http_methods/client.py +++ b/seed/python-sdk/exhaustive/no-custom-config/src/seed/endpoints/http_methods/client.py @@ -2,7 +2,6 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError @@ -10,8 +9,6 @@ from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.object_with_optional_field import ObjectWithOptionalField @@ -49,26 +46,7 @@ def test_get(self, id: str, *, request_options: typing.Optional[RequestOptions] ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -105,34 +83,8 @@ def test_post( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "http-methods"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "http-methods", method="POST", json={"string": string}, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -172,34 +124,12 @@ def test_put( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PUT", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -296,58 +226,25 @@ def test_patch( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PATCH", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -383,29 +280,7 @@ def test_delete(self, id: str, *, request_options: typing.Optional[RequestOption ) """ _response = self._client_wrapper.httpx_client.request( - method="DELETE", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="DELETE", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -446,26 +321,7 @@ async def test_get(self, id: str, *, request_options: typing.Optional[RequestOpt ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -502,34 +358,8 @@ async def test_post( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "http-methods"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "http-methods", method="POST", json={"string": string}, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -569,34 +399,12 @@ async def test_put( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PUT", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -693,58 +501,25 @@ async def test_patch( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = await self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PATCH", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -780,29 +555,7 @@ async def test_delete(self, id: str, *, request_options: typing.Optional[Request ) """ _response = await self._client_wrapper.httpx_client.request( - method="DELETE", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="DELETE", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/no-custom-config/src/seed/endpoints/object/client.py b/seed/python-sdk/exhaustive/no-custom-config/src/seed/endpoints/object/client.py index 83230dec1f4..7e66510fdb0 100644 --- a/seed/python-sdk/exhaustive/no-custom-config/src/seed/endpoints/object/client.py +++ b/seed/python-sdk/exhaustive/no-custom-config/src/seed/endpoints/object/client.py @@ -2,7 +2,6 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError @@ -10,8 +9,6 @@ from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.nested_object_with_optional_field import NestedObjectWithOptionalField from ...types.object.types.nested_object_with_required_field import NestedObjectWithRequiredField @@ -110,60 +107,25 @@ def get_and_return_with_optional_field( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -200,36 +162,12 @@ def get_and_return_with_required_field( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-required-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-required-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithRequiredField, _response.json()) # type: ignore @@ -266,36 +204,12 @@ def get_and_return_with_map_of_map( map_={"string": {"string": "string"}}, ) """ - _request: typing.Dict[str, typing.Any] = {"map": map_} _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-map-of-map", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-map-of-map" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"map": map_}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithMapOfMap, _response.json()) # type: ignore @@ -362,40 +276,12 @@ def get_and_return_nested_with_optional_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if nested_object is not OMIT: - _request["NestedObject"] = nested_object _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithOptionalField, _response.json()) # type: ignore @@ -466,37 +352,12 @@ def get_and_return_nested_with_required_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {"string": string, "NestedObject": nested_object} _response = self._client_wrapper.httpx_client.request( + f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", - f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -565,34 +426,11 @@ def get_and_return_nested_with_required_field_as_list( ) """ _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-required-field-list", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-required-field-list" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -690,60 +528,25 @@ async def get_and_return_with_optional_field( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -780,36 +583,12 @@ async def get_and_return_with_required_field( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-required-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-required-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithRequiredField, _response.json()) # type: ignore @@ -846,36 +625,12 @@ async def get_and_return_with_map_of_map( map_={"string": {"string": "string"}}, ) """ - _request: typing.Dict[str, typing.Any] = {"map": map_} _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-map-of-map", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-map-of-map" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"map": map_}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithMapOfMap, _response.json()) # type: ignore @@ -942,40 +697,12 @@ async def get_and_return_nested_with_optional_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if nested_object is not OMIT: - _request["NestedObject"] = nested_object _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithOptionalField, _response.json()) # type: ignore @@ -1046,37 +773,12 @@ async def get_and_return_nested_with_required_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {"string": string, "NestedObject": nested_object} _response = await self._client_wrapper.httpx_client.request( + f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", - f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -1145,34 +847,11 @@ async def get_and_return_nested_with_required_field_as_list( ) """ _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-required-field-list", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-required-field-list" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/no-custom-config/src/seed/endpoints/params/client.py b/seed/python-sdk/exhaustive/no-custom-config/src/seed/endpoints/params/client.py index d1f25df27fb..089d9fab5ce 100644 --- a/seed/python-sdk/exhaustive/no-custom-config/src/seed/endpoints/params/client.py +++ b/seed/python-sdk/exhaustive/no-custom-config/src/seed/endpoints/params/client.py @@ -1,15 +1,12 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -48,28 +45,7 @@ def get_with_path(self, param: str, *, request_options: typing.Optional[RequestO ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"params/path/{jsonable_encoder(param)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -112,36 +88,7 @@ def get_with_query( ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "number": number, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "number": number}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -188,36 +135,7 @@ def get_with_allow_multiple_query( ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "numer": numer, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "numer": numer}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -260,37 +178,10 @@ def get_with_path_and_query( ) """ _response = self._client_wrapper.httpx_client.request( + f"params/path-query/{jsonable_encoder(param)}", method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path-query/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"query": query}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -333,29 +224,11 @@ def modify_with_path( ) """ _response = self._client_wrapper.httpx_client.request( + f"params/path/{jsonable_encoder(param)}", method="PUT", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -398,28 +271,7 @@ async def get_with_path(self, param: str, *, request_options: typing.Optional[Re ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"params/path/{jsonable_encoder(param)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -462,36 +314,7 @@ async def get_with_query( ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "number": number, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "number": number}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -538,36 +361,7 @@ async def get_with_allow_multiple_query( ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "numer": numer, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "numer": numer}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -610,37 +404,10 @@ async def get_with_path_and_query( ) """ _response = await self._client_wrapper.httpx_client.request( + f"params/path-query/{jsonable_encoder(param)}", method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path-query/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"query": query}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -683,29 +450,11 @@ async def modify_with_path( ) """ _response = await self._client_wrapper.httpx_client.request( + f"params/path/{jsonable_encoder(param)}", method="PUT", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/no-custom-config/src/seed/endpoints/primitive/client.py b/seed/python-sdk/exhaustive/no-custom-config/src/seed/endpoints/primitive/client.py index 076383510ff..64c7f6b2ca5 100644 --- a/seed/python-sdk/exhaustive/no-custom-config/src/seed/endpoints/primitive/client.py +++ b/seed/python-sdk/exhaustive/no-custom-config/src/seed/endpoints/primitive/client.py @@ -2,16 +2,12 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -48,27 +44,7 @@ def get_and_return_string(self, *, request: str, request_options: typing.Optiona ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/string"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/string", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -104,27 +80,7 @@ def get_and_return_int(self, *, request: int, request_options: typing.Optional[R ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/integer"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/integer", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -160,32 +116,7 @@ def get_and_return_long(self, *, request: int, request_options: typing.Optional[ ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/long"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/long", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -223,27 +154,7 @@ def get_and_return_double( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/double"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/double", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(float, _response.json()) # type: ignore @@ -279,27 +190,7 @@ def get_and_return_bool(self, *, request: bool, request_options: typing.Optional ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/boolean"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/boolean", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -341,32 +232,7 @@ def get_and_return_datetime( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/datetime"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/datetime", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.datetime, _response.json()) # type: ignore @@ -408,32 +274,7 @@ def get_and_return_date( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/date"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/date", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.date, _response.json()) # type: ignore @@ -475,32 +316,7 @@ def get_and_return_uuid( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/uuid"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/uuid", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(uuid.UUID, _response.json()) # type: ignore @@ -536,32 +352,7 @@ def get_and_return_base_64(self, *, request: str, request_options: typing.Option ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/base64"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/base64", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -604,27 +395,7 @@ async def get_and_return_string( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/string"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/string", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -660,27 +431,7 @@ async def get_and_return_int(self, *, request: int, request_options: typing.Opti ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/integer"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/integer", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -718,32 +469,7 @@ async def get_and_return_long( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/long"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/long", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -781,27 +507,7 @@ async def get_and_return_double( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/double"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/double", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(float, _response.json()) # type: ignore @@ -839,27 +545,7 @@ async def get_and_return_bool( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/boolean"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/boolean", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -901,32 +587,7 @@ async def get_and_return_datetime( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/datetime"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/datetime", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.datetime, _response.json()) # type: ignore @@ -968,32 +629,7 @@ async def get_and_return_date( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/date"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/date", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.date, _response.json()) # type: ignore @@ -1035,32 +671,7 @@ async def get_and_return_uuid( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/uuid"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/uuid", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(uuid.UUID, _response.json()) # type: ignore @@ -1098,32 +709,7 @@ async def get_and_return_base_64( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/base64"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/base64", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/no-custom-config/src/seed/endpoints/union/client.py b/seed/python-sdk/exhaustive/no-custom-config/src/seed/endpoints/union/client.py index 23757c07bd8..843d9828bc6 100644 --- a/seed/python-sdk/exhaustive/no-custom-config/src/seed/endpoints/union/client.py +++ b/seed/python-sdk/exhaustive/no-custom-config/src/seed/endpoints/union/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.union.types.animal import Animal @@ -53,32 +49,7 @@ def get_and_return_union( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "union"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "union", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Animal, _response.json()) # type: ignore @@ -125,32 +96,7 @@ async def get_and_return_union( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "union"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "union", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Animal, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/no-custom-config/src/seed/inlined_requests/client.py b/seed/python-sdk/exhaustive/no-custom-config/src/seed/inlined_requests/client.py index 38e428f66e0..bfb17877f08 100644 --- a/seed/python-sdk/exhaustive/no-custom-config/src/seed/inlined_requests/client.py +++ b/seed/python-sdk/exhaustive/no-custom-config/src/seed/inlined_requests/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..general_errors.errors.bad_request_body import BadRequestBody from ..general_errors.types.bad_object_request_info import BadObjectRequestInfo @@ -29,7 +25,7 @@ def post_with_object_bodyand_response( string: str, integer: int, nested_object: ObjectWithOptionalField, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> ObjectWithOptionalField: """ POST with custom object in request body, response is an object @@ -87,32 +83,11 @@ def post_with_object_bodyand_response( ) """ _response = self._client_wrapper.httpx_client.request( + "req-bodies/object", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "req-bodies/object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "integer": integer, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -135,7 +110,7 @@ async def post_with_object_bodyand_response( string: str, integer: int, nested_object: ObjectWithOptionalField, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> ObjectWithOptionalField: """ POST with custom object in request body, response is an object @@ -193,32 +168,11 @@ async def post_with_object_bodyand_response( ) """ _response = await self._client_wrapper.httpx_client.request( + "req-bodies/object", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "req-bodies/object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "integer": integer, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/no-custom-config/src/seed/no_auth/client.py b/seed/python-sdk/exhaustive/no-custom-config/src/seed/no_auth/client.py index fd4814dde0b..477bf563998 100644 --- a/seed/python-sdk/exhaustive/no-custom-config/src/seed/no_auth/client.py +++ b/seed/python-sdk/exhaustive/no-custom-config/src/seed/no_auth/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..general_errors.errors.bad_request_body import BadRequestBody from ..general_errors.types.bad_object_request_info import BadObjectRequestInfo @@ -52,32 +48,7 @@ def post_with_no_auth( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-auth", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -124,32 +95,7 @@ async def post_with_no_auth( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-auth", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/no-custom-config/src/seed/no_req_body/client.py b/seed/python-sdk/exhaustive/no-custom-config/src/seed/no_req_body/client.py index f984b6c24d3..7e3fd3ae95f 100644 --- a/seed/python-sdk/exhaustive/no-custom-config/src/seed/no_req_body/client.py +++ b/seed/python-sdk/exhaustive/no-custom-config/src/seed/no_req_body/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..types.object.types.object_with_optional_field import ObjectWithOptionalField @@ -42,26 +38,7 @@ def get_with_no_request_body( client.no_req_body.get_with_no_request_body() """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -93,29 +70,7 @@ def post_with_no_request_body(self, *, request_options: typing.Optional[RequestO client.no_req_body.post_with_no_request_body() """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -154,26 +109,7 @@ async def get_with_no_request_body( await client.no_req_body.get_with_no_request_body() """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -205,29 +141,7 @@ async def post_with_no_request_body(self, *, request_options: typing.Optional[Re await client.no_req_body.post_with_no_request_body() """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/no-custom-config/src/seed/req_with_headers/client.py b/seed/python-sdk/exhaustive/no-custom-config/src/seed/req_with_headers/client.py index 3e7f80e7435..4ec08e7ee09 100644 --- a/seed/python-sdk/exhaustive/no-custom-config/src/seed/req_with_headers/client.py +++ b/seed/python-sdk/exhaustive/no-custom-config/src/seed/req_with_headers/client.py @@ -1,14 +1,10 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -25,7 +21,7 @@ def get_with_custom_header( x_test_service_header: str, x_test_endpoint_header: str, request: str, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -58,33 +54,15 @@ def get_with_custom_header( ) """ _response = self._client_wrapper.httpx_client.request( + "test-headers/custom-header", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "test-headers/custom-header"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-TEST-SERVICE-HEADER": str(x_test_service_header) - if x_test_service_header is not None - else None, - "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) - if x_test_endpoint_header is not None - else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + headers={ + "X-TEST-SERVICE-HEADER": str(x_test_service_header) if x_test_service_header is not None else None, + "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) if x_test_endpoint_header is not None else None, + }, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return @@ -105,7 +83,7 @@ async def get_with_custom_header( x_test_service_header: str, x_test_endpoint_header: str, request: str, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -138,33 +116,15 @@ async def get_with_custom_header( ) """ _response = await self._client_wrapper.httpx_client.request( + "test-headers/custom-header", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "test-headers/custom-header"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-TEST-SERVICE-HEADER": str(x_test_service_header) - if x_test_service_header is not None - else None, - "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) - if x_test_endpoint_header is not None - else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + headers={ + "X-TEST-SERVICE-HEADER": str(x_test_service_header) if x_test_service_header is not None else None, + "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) if x_test_endpoint_header is not None else None, + }, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return diff --git a/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/core/client_wrapper.py b/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/core/client_wrapper.py index 5b0c9d5ad91..8d01b584b82 100644 --- a/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/core/client_wrapper.py @@ -53,7 +53,12 @@ def __init__( httpx_client: httpx.Client, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): @@ -66,4 +71,9 @@ def __init__( httpx_client: httpx.AsyncClient, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/core/http_client.py b/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/core/http_client.py +++ b/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/endpoints/container/client.py b/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/endpoints/container/client.py index c5ab55847c7..e02bf812398 100644 --- a/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/endpoints/container/client.py +++ b/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/endpoints/container/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.object_with_required_field import ObjectWithRequiredField @@ -49,32 +45,7 @@ def get_and_return_list_of_primitives( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[str], _response.json()) # type: ignore @@ -88,7 +59,7 @@ def get_and_return_list_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -120,32 +91,7 @@ def get_and_return_list_of_objects( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -183,32 +129,7 @@ def get_and_return_set_of_primitives( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Set[str], _response.json()) # type: ignore @@ -222,7 +143,7 @@ def get_and_return_set_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -254,32 +175,7 @@ def get_and_return_set_of_objects( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -317,32 +213,7 @@ def get_and_return_map_prim_to_prim( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-prim"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-prim", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, str], _response.json()) # type: ignore @@ -356,7 +227,7 @@ def get_and_return_map_of_prim_to_object( self, *, request: typing.Dict[str, ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Dict[str, ObjectWithRequiredField]: """ Parameters @@ -388,32 +259,7 @@ def get_and_return_map_of_prim_to_object( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-object", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, ObjectWithRequiredField], _response.json()) # type: ignore @@ -427,7 +273,7 @@ def get_and_return_optional( self, *, request: typing.Optional[ObjectWithRequiredField] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Optional[ObjectWithRequiredField]: """ Parameters @@ -457,32 +303,7 @@ def get_and_return_optional( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/opt-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/opt-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Optional[ObjectWithRequiredField], _response.json()) # type: ignore @@ -525,32 +346,7 @@ async def get_and_return_list_of_primitives( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[str], _response.json()) # type: ignore @@ -564,7 +360,7 @@ async def get_and_return_list_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -596,32 +392,7 @@ async def get_and_return_list_of_objects( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -659,32 +430,7 @@ async def get_and_return_set_of_primitives( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Set[str], _response.json()) # type: ignore @@ -698,7 +444,7 @@ async def get_and_return_set_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -730,32 +476,7 @@ async def get_and_return_set_of_objects( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -793,32 +514,7 @@ async def get_and_return_map_prim_to_prim( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-prim"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-prim", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, str], _response.json()) # type: ignore @@ -832,7 +528,7 @@ async def get_and_return_map_of_prim_to_object( self, *, request: typing.Dict[str, ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Dict[str, ObjectWithRequiredField]: """ Parameters @@ -864,32 +560,7 @@ async def get_and_return_map_of_prim_to_object( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-object", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, ObjectWithRequiredField], _response.json()) # type: ignore @@ -903,7 +574,7 @@ async def get_and_return_optional( self, *, request: typing.Optional[ObjectWithRequiredField] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Optional[ObjectWithRequiredField]: """ Parameters @@ -933,32 +604,7 @@ async def get_and_return_optional( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/opt-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/opt-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Optional[ObjectWithRequiredField], _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/endpoints/enum/client.py b/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/endpoints/enum/client.py index 94ee2ac420f..8fcd0668b4b 100644 --- a/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/endpoints/enum/client.py +++ b/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/endpoints/enum/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.enum.types.weather_report import WeatherReport @@ -49,27 +45,7 @@ def get_and_return_enum( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "enum"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "enum", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(WeatherReport, _response.json()) # type: ignore @@ -112,27 +88,7 @@ async def get_and_return_enum( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "enum"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "enum", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(WeatherReport, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/endpoints/http_methods/client.py b/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/endpoints/http_methods/client.py index 1c8af11a4bd..3bd65f6adda 100644 --- a/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/endpoints/http_methods/client.py +++ b/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/endpoints/http_methods/client.py @@ -2,7 +2,6 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError @@ -10,8 +9,6 @@ from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.object_with_optional_field import ObjectWithOptionalField @@ -49,26 +46,7 @@ def test_get(self, id: str, *, request_options: typing.Optional[RequestOptions] ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -105,34 +83,8 @@ def test_post( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "http-methods"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "http-methods", method="POST", json={"string": string}, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -172,34 +124,12 @@ def test_put( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PUT", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -296,58 +226,25 @@ def test_patch( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PATCH", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -383,29 +280,7 @@ def test_delete(self, id: str, *, request_options: typing.Optional[RequestOption ) """ _response = self._client_wrapper.httpx_client.request( - method="DELETE", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="DELETE", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -446,26 +321,7 @@ async def test_get(self, id: str, *, request_options: typing.Optional[RequestOpt ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -502,34 +358,8 @@ async def test_post( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "http-methods"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "http-methods", method="POST", json={"string": string}, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -569,34 +399,12 @@ async def test_put( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PUT", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -693,58 +501,25 @@ async def test_patch( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = await self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PATCH", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -780,29 +555,7 @@ async def test_delete(self, id: str, *, request_options: typing.Optional[Request ) """ _response = await self._client_wrapper.httpx_client.request( - method="DELETE", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="DELETE", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/endpoints/object/client.py b/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/endpoints/object/client.py index 83230dec1f4..7e66510fdb0 100644 --- a/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/endpoints/object/client.py +++ b/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/endpoints/object/client.py @@ -2,7 +2,6 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError @@ -10,8 +9,6 @@ from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.nested_object_with_optional_field import NestedObjectWithOptionalField from ...types.object.types.nested_object_with_required_field import NestedObjectWithRequiredField @@ -110,60 +107,25 @@ def get_and_return_with_optional_field( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -200,36 +162,12 @@ def get_and_return_with_required_field( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-required-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-required-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithRequiredField, _response.json()) # type: ignore @@ -266,36 +204,12 @@ def get_and_return_with_map_of_map( map_={"string": {"string": "string"}}, ) """ - _request: typing.Dict[str, typing.Any] = {"map": map_} _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-map-of-map", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-map-of-map" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"map": map_}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithMapOfMap, _response.json()) # type: ignore @@ -362,40 +276,12 @@ def get_and_return_nested_with_optional_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if nested_object is not OMIT: - _request["NestedObject"] = nested_object _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithOptionalField, _response.json()) # type: ignore @@ -466,37 +352,12 @@ def get_and_return_nested_with_required_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {"string": string, "NestedObject": nested_object} _response = self._client_wrapper.httpx_client.request( + f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", - f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -565,34 +426,11 @@ def get_and_return_nested_with_required_field_as_list( ) """ _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-required-field-list", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-required-field-list" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -690,60 +528,25 @@ async def get_and_return_with_optional_field( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -780,36 +583,12 @@ async def get_and_return_with_required_field( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-required-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-required-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithRequiredField, _response.json()) # type: ignore @@ -846,36 +625,12 @@ async def get_and_return_with_map_of_map( map_={"string": {"string": "string"}}, ) """ - _request: typing.Dict[str, typing.Any] = {"map": map_} _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-map-of-map", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-map-of-map" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"map": map_}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithMapOfMap, _response.json()) # type: ignore @@ -942,40 +697,12 @@ async def get_and_return_nested_with_optional_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if nested_object is not OMIT: - _request["NestedObject"] = nested_object _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithOptionalField, _response.json()) # type: ignore @@ -1046,37 +773,12 @@ async def get_and_return_nested_with_required_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {"string": string, "NestedObject": nested_object} _response = await self._client_wrapper.httpx_client.request( + f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", - f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -1145,34 +847,11 @@ async def get_and_return_nested_with_required_field_as_list( ) """ _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-required-field-list", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-required-field-list" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/endpoints/params/client.py b/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/endpoints/params/client.py index d1f25df27fb..089d9fab5ce 100644 --- a/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/endpoints/params/client.py +++ b/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/endpoints/params/client.py @@ -1,15 +1,12 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -48,28 +45,7 @@ def get_with_path(self, param: str, *, request_options: typing.Optional[RequestO ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"params/path/{jsonable_encoder(param)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -112,36 +88,7 @@ def get_with_query( ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "number": number, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "number": number}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -188,36 +135,7 @@ def get_with_allow_multiple_query( ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "numer": numer, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "numer": numer}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -260,37 +178,10 @@ def get_with_path_and_query( ) """ _response = self._client_wrapper.httpx_client.request( + f"params/path-query/{jsonable_encoder(param)}", method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path-query/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"query": query}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -333,29 +224,11 @@ def modify_with_path( ) """ _response = self._client_wrapper.httpx_client.request( + f"params/path/{jsonable_encoder(param)}", method="PUT", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -398,28 +271,7 @@ async def get_with_path(self, param: str, *, request_options: typing.Optional[Re ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"params/path/{jsonable_encoder(param)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -462,36 +314,7 @@ async def get_with_query( ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "number": number, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "number": number}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -538,36 +361,7 @@ async def get_with_allow_multiple_query( ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "numer": numer, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "numer": numer}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -610,37 +404,10 @@ async def get_with_path_and_query( ) """ _response = await self._client_wrapper.httpx_client.request( + f"params/path-query/{jsonable_encoder(param)}", method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path-query/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"query": query}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -683,29 +450,11 @@ async def modify_with_path( ) """ _response = await self._client_wrapper.httpx_client.request( + f"params/path/{jsonable_encoder(param)}", method="PUT", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/endpoints/primitive/client.py b/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/endpoints/primitive/client.py index 076383510ff..64c7f6b2ca5 100644 --- a/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/endpoints/primitive/client.py +++ b/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/endpoints/primitive/client.py @@ -2,16 +2,12 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -48,27 +44,7 @@ def get_and_return_string(self, *, request: str, request_options: typing.Optiona ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/string"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/string", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -104,27 +80,7 @@ def get_and_return_int(self, *, request: int, request_options: typing.Optional[R ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/integer"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/integer", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -160,32 +116,7 @@ def get_and_return_long(self, *, request: int, request_options: typing.Optional[ ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/long"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/long", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -223,27 +154,7 @@ def get_and_return_double( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/double"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/double", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(float, _response.json()) # type: ignore @@ -279,27 +190,7 @@ def get_and_return_bool(self, *, request: bool, request_options: typing.Optional ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/boolean"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/boolean", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -341,32 +232,7 @@ def get_and_return_datetime( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/datetime"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/datetime", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.datetime, _response.json()) # type: ignore @@ -408,32 +274,7 @@ def get_and_return_date( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/date"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/date", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.date, _response.json()) # type: ignore @@ -475,32 +316,7 @@ def get_and_return_uuid( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/uuid"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/uuid", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(uuid.UUID, _response.json()) # type: ignore @@ -536,32 +352,7 @@ def get_and_return_base_64(self, *, request: str, request_options: typing.Option ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/base64"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/base64", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -604,27 +395,7 @@ async def get_and_return_string( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/string"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/string", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -660,27 +431,7 @@ async def get_and_return_int(self, *, request: int, request_options: typing.Opti ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/integer"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/integer", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -718,32 +469,7 @@ async def get_and_return_long( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/long"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/long", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -781,27 +507,7 @@ async def get_and_return_double( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/double"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/double", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(float, _response.json()) # type: ignore @@ -839,27 +545,7 @@ async def get_and_return_bool( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/boolean"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/boolean", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -901,32 +587,7 @@ async def get_and_return_datetime( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/datetime"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/datetime", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.datetime, _response.json()) # type: ignore @@ -968,32 +629,7 @@ async def get_and_return_date( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/date"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/date", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.date, _response.json()) # type: ignore @@ -1035,32 +671,7 @@ async def get_and_return_uuid( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/uuid"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/uuid", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(uuid.UUID, _response.json()) # type: ignore @@ -1098,32 +709,7 @@ async def get_and_return_base_64( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/base64"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/base64", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/endpoints/union/client.py b/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/endpoints/union/client.py index 23757c07bd8..843d9828bc6 100644 --- a/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/endpoints/union/client.py +++ b/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/endpoints/union/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.union.types.animal import Animal @@ -53,32 +49,7 @@ def get_and_return_union( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "union"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "union", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Animal, _response.json()) # type: ignore @@ -125,32 +96,7 @@ async def get_and_return_union( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "union"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "union", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Animal, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/inlined_requests/client.py b/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/inlined_requests/client.py index 38e428f66e0..bfb17877f08 100644 --- a/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/inlined_requests/client.py +++ b/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/inlined_requests/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..general_errors.errors.bad_request_body import BadRequestBody from ..general_errors.types.bad_object_request_info import BadObjectRequestInfo @@ -29,7 +25,7 @@ def post_with_object_bodyand_response( string: str, integer: int, nested_object: ObjectWithOptionalField, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> ObjectWithOptionalField: """ POST with custom object in request body, response is an object @@ -87,32 +83,11 @@ def post_with_object_bodyand_response( ) """ _response = self._client_wrapper.httpx_client.request( + "req-bodies/object", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "req-bodies/object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "integer": integer, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -135,7 +110,7 @@ async def post_with_object_bodyand_response( string: str, integer: int, nested_object: ObjectWithOptionalField, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> ObjectWithOptionalField: """ POST with custom object in request body, response is an object @@ -193,32 +168,11 @@ async def post_with_object_bodyand_response( ) """ _response = await self._client_wrapper.httpx_client.request( + "req-bodies/object", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "req-bodies/object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "integer": integer, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/no_auth/client.py b/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/no_auth/client.py index fd4814dde0b..477bf563998 100644 --- a/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/no_auth/client.py +++ b/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/no_auth/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..general_errors.errors.bad_request_body import BadRequestBody from ..general_errors.types.bad_object_request_info import BadObjectRequestInfo @@ -52,32 +48,7 @@ def post_with_no_auth( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-auth", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -124,32 +95,7 @@ async def post_with_no_auth( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-auth", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/no_req_body/client.py b/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/no_req_body/client.py index f984b6c24d3..7e3fd3ae95f 100644 --- a/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/no_req_body/client.py +++ b/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/no_req_body/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..types.object.types.object_with_optional_field import ObjectWithOptionalField @@ -42,26 +38,7 @@ def get_with_no_request_body( client.no_req_body.get_with_no_request_body() """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -93,29 +70,7 @@ def post_with_no_request_body(self, *, request_options: typing.Optional[RequestO client.no_req_body.post_with_no_request_body() """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -154,26 +109,7 @@ async def get_with_no_request_body( await client.no_req_body.get_with_no_request_body() """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -205,29 +141,7 @@ async def post_with_no_request_body(self, *, request_options: typing.Optional[Re await client.no_req_body.post_with_no_request_body() """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/req_with_headers/client.py b/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/req_with_headers/client.py index 3e7f80e7435..4ec08e7ee09 100644 --- a/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/req_with_headers/client.py +++ b/seed/python-sdk/exhaustive/pydantic-extra-fields/src/seed/req_with_headers/client.py @@ -1,14 +1,10 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -25,7 +21,7 @@ def get_with_custom_header( x_test_service_header: str, x_test_endpoint_header: str, request: str, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -58,33 +54,15 @@ def get_with_custom_header( ) """ _response = self._client_wrapper.httpx_client.request( + "test-headers/custom-header", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "test-headers/custom-header"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-TEST-SERVICE-HEADER": str(x_test_service_header) - if x_test_service_header is not None - else None, - "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) - if x_test_endpoint_header is not None - else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + headers={ + "X-TEST-SERVICE-HEADER": str(x_test_service_header) if x_test_service_header is not None else None, + "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) if x_test_endpoint_header is not None else None, + }, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return @@ -105,7 +83,7 @@ async def get_with_custom_header( x_test_service_header: str, x_test_endpoint_header: str, request: str, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -138,33 +116,15 @@ async def get_with_custom_header( ) """ _response = await self._client_wrapper.httpx_client.request( + "test-headers/custom-header", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "test-headers/custom-header"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-TEST-SERVICE-HEADER": str(x_test_service_header) - if x_test_service_header is not None - else None, - "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) - if x_test_endpoint_header is not None - else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + headers={ + "X-TEST-SERVICE-HEADER": str(x_test_service_header) if x_test_service_header is not None else None, + "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) if x_test_endpoint_header is not None else None, + }, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return diff --git a/seed/python-sdk/exhaustive/pydantic-v1/src/seed/core/client_wrapper.py b/seed/python-sdk/exhaustive/pydantic-v1/src/seed/core/client_wrapper.py index 5b0c9d5ad91..8d01b584b82 100644 --- a/seed/python-sdk/exhaustive/pydantic-v1/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/exhaustive/pydantic-v1/src/seed/core/client_wrapper.py @@ -53,7 +53,12 @@ def __init__( httpx_client: httpx.Client, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): @@ -66,4 +71,9 @@ def __init__( httpx_client: httpx.AsyncClient, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/exhaustive/pydantic-v1/src/seed/core/http_client.py b/seed/python-sdk/exhaustive/pydantic-v1/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/exhaustive/pydantic-v1/src/seed/core/http_client.py +++ b/seed/python-sdk/exhaustive/pydantic-v1/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/exhaustive/pydantic-v1/src/seed/endpoints/container/client.py b/seed/python-sdk/exhaustive/pydantic-v1/src/seed/endpoints/container/client.py index c5ab55847c7..e02bf812398 100644 --- a/seed/python-sdk/exhaustive/pydantic-v1/src/seed/endpoints/container/client.py +++ b/seed/python-sdk/exhaustive/pydantic-v1/src/seed/endpoints/container/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.object_with_required_field import ObjectWithRequiredField @@ -49,32 +45,7 @@ def get_and_return_list_of_primitives( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[str], _response.json()) # type: ignore @@ -88,7 +59,7 @@ def get_and_return_list_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -120,32 +91,7 @@ def get_and_return_list_of_objects( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -183,32 +129,7 @@ def get_and_return_set_of_primitives( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Set[str], _response.json()) # type: ignore @@ -222,7 +143,7 @@ def get_and_return_set_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -254,32 +175,7 @@ def get_and_return_set_of_objects( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -317,32 +213,7 @@ def get_and_return_map_prim_to_prim( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-prim"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-prim", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, str], _response.json()) # type: ignore @@ -356,7 +227,7 @@ def get_and_return_map_of_prim_to_object( self, *, request: typing.Dict[str, ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Dict[str, ObjectWithRequiredField]: """ Parameters @@ -388,32 +259,7 @@ def get_and_return_map_of_prim_to_object( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-object", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, ObjectWithRequiredField], _response.json()) # type: ignore @@ -427,7 +273,7 @@ def get_and_return_optional( self, *, request: typing.Optional[ObjectWithRequiredField] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Optional[ObjectWithRequiredField]: """ Parameters @@ -457,32 +303,7 @@ def get_and_return_optional( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/opt-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/opt-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Optional[ObjectWithRequiredField], _response.json()) # type: ignore @@ -525,32 +346,7 @@ async def get_and_return_list_of_primitives( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[str], _response.json()) # type: ignore @@ -564,7 +360,7 @@ async def get_and_return_list_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -596,32 +392,7 @@ async def get_and_return_list_of_objects( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -659,32 +430,7 @@ async def get_and_return_set_of_primitives( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Set[str], _response.json()) # type: ignore @@ -698,7 +444,7 @@ async def get_and_return_set_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -730,32 +476,7 @@ async def get_and_return_set_of_objects( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -793,32 +514,7 @@ async def get_and_return_map_prim_to_prim( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-prim"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-prim", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, str], _response.json()) # type: ignore @@ -832,7 +528,7 @@ async def get_and_return_map_of_prim_to_object( self, *, request: typing.Dict[str, ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Dict[str, ObjectWithRequiredField]: """ Parameters @@ -864,32 +560,7 @@ async def get_and_return_map_of_prim_to_object( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-object", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, ObjectWithRequiredField], _response.json()) # type: ignore @@ -903,7 +574,7 @@ async def get_and_return_optional( self, *, request: typing.Optional[ObjectWithRequiredField] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Optional[ObjectWithRequiredField]: """ Parameters @@ -933,32 +604,7 @@ async def get_and_return_optional( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/opt-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/opt-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Optional[ObjectWithRequiredField], _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/pydantic-v1/src/seed/endpoints/enum/client.py b/seed/python-sdk/exhaustive/pydantic-v1/src/seed/endpoints/enum/client.py index 94ee2ac420f..8fcd0668b4b 100644 --- a/seed/python-sdk/exhaustive/pydantic-v1/src/seed/endpoints/enum/client.py +++ b/seed/python-sdk/exhaustive/pydantic-v1/src/seed/endpoints/enum/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.enum.types.weather_report import WeatherReport @@ -49,27 +45,7 @@ def get_and_return_enum( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "enum"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "enum", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(WeatherReport, _response.json()) # type: ignore @@ -112,27 +88,7 @@ async def get_and_return_enum( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "enum"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "enum", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(WeatherReport, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/pydantic-v1/src/seed/endpoints/http_methods/client.py b/seed/python-sdk/exhaustive/pydantic-v1/src/seed/endpoints/http_methods/client.py index 1c8af11a4bd..3bd65f6adda 100644 --- a/seed/python-sdk/exhaustive/pydantic-v1/src/seed/endpoints/http_methods/client.py +++ b/seed/python-sdk/exhaustive/pydantic-v1/src/seed/endpoints/http_methods/client.py @@ -2,7 +2,6 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError @@ -10,8 +9,6 @@ from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.object_with_optional_field import ObjectWithOptionalField @@ -49,26 +46,7 @@ def test_get(self, id: str, *, request_options: typing.Optional[RequestOptions] ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -105,34 +83,8 @@ def test_post( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "http-methods"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "http-methods", method="POST", json={"string": string}, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -172,34 +124,12 @@ def test_put( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PUT", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -296,58 +226,25 @@ def test_patch( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PATCH", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -383,29 +280,7 @@ def test_delete(self, id: str, *, request_options: typing.Optional[RequestOption ) """ _response = self._client_wrapper.httpx_client.request( - method="DELETE", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="DELETE", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -446,26 +321,7 @@ async def test_get(self, id: str, *, request_options: typing.Optional[RequestOpt ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -502,34 +358,8 @@ async def test_post( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "http-methods"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "http-methods", method="POST", json={"string": string}, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -569,34 +399,12 @@ async def test_put( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PUT", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -693,58 +501,25 @@ async def test_patch( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = await self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PATCH", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -780,29 +555,7 @@ async def test_delete(self, id: str, *, request_options: typing.Optional[Request ) """ _response = await self._client_wrapper.httpx_client.request( - method="DELETE", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="DELETE", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/pydantic-v1/src/seed/endpoints/object/client.py b/seed/python-sdk/exhaustive/pydantic-v1/src/seed/endpoints/object/client.py index 83230dec1f4..7e66510fdb0 100644 --- a/seed/python-sdk/exhaustive/pydantic-v1/src/seed/endpoints/object/client.py +++ b/seed/python-sdk/exhaustive/pydantic-v1/src/seed/endpoints/object/client.py @@ -2,7 +2,6 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError @@ -10,8 +9,6 @@ from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.nested_object_with_optional_field import NestedObjectWithOptionalField from ...types.object.types.nested_object_with_required_field import NestedObjectWithRequiredField @@ -110,60 +107,25 @@ def get_and_return_with_optional_field( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -200,36 +162,12 @@ def get_and_return_with_required_field( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-required-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-required-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithRequiredField, _response.json()) # type: ignore @@ -266,36 +204,12 @@ def get_and_return_with_map_of_map( map_={"string": {"string": "string"}}, ) """ - _request: typing.Dict[str, typing.Any] = {"map": map_} _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-map-of-map", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-map-of-map" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"map": map_}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithMapOfMap, _response.json()) # type: ignore @@ -362,40 +276,12 @@ def get_and_return_nested_with_optional_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if nested_object is not OMIT: - _request["NestedObject"] = nested_object _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithOptionalField, _response.json()) # type: ignore @@ -466,37 +352,12 @@ def get_and_return_nested_with_required_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {"string": string, "NestedObject": nested_object} _response = self._client_wrapper.httpx_client.request( + f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", - f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -565,34 +426,11 @@ def get_and_return_nested_with_required_field_as_list( ) """ _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-required-field-list", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-required-field-list" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -690,60 +528,25 @@ async def get_and_return_with_optional_field( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -780,36 +583,12 @@ async def get_and_return_with_required_field( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-required-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-required-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithRequiredField, _response.json()) # type: ignore @@ -846,36 +625,12 @@ async def get_and_return_with_map_of_map( map_={"string": {"string": "string"}}, ) """ - _request: typing.Dict[str, typing.Any] = {"map": map_} _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-map-of-map", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-map-of-map" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"map": map_}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithMapOfMap, _response.json()) # type: ignore @@ -942,40 +697,12 @@ async def get_and_return_nested_with_optional_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if nested_object is not OMIT: - _request["NestedObject"] = nested_object _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithOptionalField, _response.json()) # type: ignore @@ -1046,37 +773,12 @@ async def get_and_return_nested_with_required_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {"string": string, "NestedObject": nested_object} _response = await self._client_wrapper.httpx_client.request( + f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", - f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -1145,34 +847,11 @@ async def get_and_return_nested_with_required_field_as_list( ) """ _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-required-field-list", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-required-field-list" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/pydantic-v1/src/seed/endpoints/params/client.py b/seed/python-sdk/exhaustive/pydantic-v1/src/seed/endpoints/params/client.py index d1f25df27fb..089d9fab5ce 100644 --- a/seed/python-sdk/exhaustive/pydantic-v1/src/seed/endpoints/params/client.py +++ b/seed/python-sdk/exhaustive/pydantic-v1/src/seed/endpoints/params/client.py @@ -1,15 +1,12 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -48,28 +45,7 @@ def get_with_path(self, param: str, *, request_options: typing.Optional[RequestO ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"params/path/{jsonable_encoder(param)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -112,36 +88,7 @@ def get_with_query( ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "number": number, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "number": number}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -188,36 +135,7 @@ def get_with_allow_multiple_query( ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "numer": numer, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "numer": numer}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -260,37 +178,10 @@ def get_with_path_and_query( ) """ _response = self._client_wrapper.httpx_client.request( + f"params/path-query/{jsonable_encoder(param)}", method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path-query/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"query": query}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -333,29 +224,11 @@ def modify_with_path( ) """ _response = self._client_wrapper.httpx_client.request( + f"params/path/{jsonable_encoder(param)}", method="PUT", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -398,28 +271,7 @@ async def get_with_path(self, param: str, *, request_options: typing.Optional[Re ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"params/path/{jsonable_encoder(param)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -462,36 +314,7 @@ async def get_with_query( ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "number": number, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "number": number}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -538,36 +361,7 @@ async def get_with_allow_multiple_query( ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "numer": numer, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "numer": numer}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -610,37 +404,10 @@ async def get_with_path_and_query( ) """ _response = await self._client_wrapper.httpx_client.request( + f"params/path-query/{jsonable_encoder(param)}", method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path-query/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"query": query}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -683,29 +450,11 @@ async def modify_with_path( ) """ _response = await self._client_wrapper.httpx_client.request( + f"params/path/{jsonable_encoder(param)}", method="PUT", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/pydantic-v1/src/seed/endpoints/primitive/client.py b/seed/python-sdk/exhaustive/pydantic-v1/src/seed/endpoints/primitive/client.py index 076383510ff..64c7f6b2ca5 100644 --- a/seed/python-sdk/exhaustive/pydantic-v1/src/seed/endpoints/primitive/client.py +++ b/seed/python-sdk/exhaustive/pydantic-v1/src/seed/endpoints/primitive/client.py @@ -2,16 +2,12 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -48,27 +44,7 @@ def get_and_return_string(self, *, request: str, request_options: typing.Optiona ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/string"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/string", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -104,27 +80,7 @@ def get_and_return_int(self, *, request: int, request_options: typing.Optional[R ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/integer"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/integer", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -160,32 +116,7 @@ def get_and_return_long(self, *, request: int, request_options: typing.Optional[ ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/long"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/long", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -223,27 +154,7 @@ def get_and_return_double( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/double"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/double", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(float, _response.json()) # type: ignore @@ -279,27 +190,7 @@ def get_and_return_bool(self, *, request: bool, request_options: typing.Optional ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/boolean"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/boolean", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -341,32 +232,7 @@ def get_and_return_datetime( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/datetime"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/datetime", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.datetime, _response.json()) # type: ignore @@ -408,32 +274,7 @@ def get_and_return_date( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/date"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/date", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.date, _response.json()) # type: ignore @@ -475,32 +316,7 @@ def get_and_return_uuid( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/uuid"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/uuid", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(uuid.UUID, _response.json()) # type: ignore @@ -536,32 +352,7 @@ def get_and_return_base_64(self, *, request: str, request_options: typing.Option ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/base64"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/base64", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -604,27 +395,7 @@ async def get_and_return_string( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/string"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/string", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -660,27 +431,7 @@ async def get_and_return_int(self, *, request: int, request_options: typing.Opti ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/integer"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/integer", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -718,32 +469,7 @@ async def get_and_return_long( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/long"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/long", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -781,27 +507,7 @@ async def get_and_return_double( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/double"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/double", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(float, _response.json()) # type: ignore @@ -839,27 +545,7 @@ async def get_and_return_bool( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/boolean"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/boolean", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -901,32 +587,7 @@ async def get_and_return_datetime( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/datetime"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/datetime", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.datetime, _response.json()) # type: ignore @@ -968,32 +629,7 @@ async def get_and_return_date( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/date"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/date", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.date, _response.json()) # type: ignore @@ -1035,32 +671,7 @@ async def get_and_return_uuid( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/uuid"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/uuid", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(uuid.UUID, _response.json()) # type: ignore @@ -1098,32 +709,7 @@ async def get_and_return_base_64( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/base64"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/base64", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/pydantic-v1/src/seed/endpoints/union/client.py b/seed/python-sdk/exhaustive/pydantic-v1/src/seed/endpoints/union/client.py index 23757c07bd8..843d9828bc6 100644 --- a/seed/python-sdk/exhaustive/pydantic-v1/src/seed/endpoints/union/client.py +++ b/seed/python-sdk/exhaustive/pydantic-v1/src/seed/endpoints/union/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.union.types.animal import Animal @@ -53,32 +49,7 @@ def get_and_return_union( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "union"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "union", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Animal, _response.json()) # type: ignore @@ -125,32 +96,7 @@ async def get_and_return_union( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "union"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "union", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Animal, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/pydantic-v1/src/seed/inlined_requests/client.py b/seed/python-sdk/exhaustive/pydantic-v1/src/seed/inlined_requests/client.py index 38e428f66e0..bfb17877f08 100644 --- a/seed/python-sdk/exhaustive/pydantic-v1/src/seed/inlined_requests/client.py +++ b/seed/python-sdk/exhaustive/pydantic-v1/src/seed/inlined_requests/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..general_errors.errors.bad_request_body import BadRequestBody from ..general_errors.types.bad_object_request_info import BadObjectRequestInfo @@ -29,7 +25,7 @@ def post_with_object_bodyand_response( string: str, integer: int, nested_object: ObjectWithOptionalField, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> ObjectWithOptionalField: """ POST with custom object in request body, response is an object @@ -87,32 +83,11 @@ def post_with_object_bodyand_response( ) """ _response = self._client_wrapper.httpx_client.request( + "req-bodies/object", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "req-bodies/object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "integer": integer, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -135,7 +110,7 @@ async def post_with_object_bodyand_response( string: str, integer: int, nested_object: ObjectWithOptionalField, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> ObjectWithOptionalField: """ POST with custom object in request body, response is an object @@ -193,32 +168,11 @@ async def post_with_object_bodyand_response( ) """ _response = await self._client_wrapper.httpx_client.request( + "req-bodies/object", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "req-bodies/object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "integer": integer, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/pydantic-v1/src/seed/no_auth/client.py b/seed/python-sdk/exhaustive/pydantic-v1/src/seed/no_auth/client.py index fd4814dde0b..477bf563998 100644 --- a/seed/python-sdk/exhaustive/pydantic-v1/src/seed/no_auth/client.py +++ b/seed/python-sdk/exhaustive/pydantic-v1/src/seed/no_auth/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..general_errors.errors.bad_request_body import BadRequestBody from ..general_errors.types.bad_object_request_info import BadObjectRequestInfo @@ -52,32 +48,7 @@ def post_with_no_auth( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-auth", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -124,32 +95,7 @@ async def post_with_no_auth( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-auth", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/pydantic-v1/src/seed/no_req_body/client.py b/seed/python-sdk/exhaustive/pydantic-v1/src/seed/no_req_body/client.py index f984b6c24d3..7e3fd3ae95f 100644 --- a/seed/python-sdk/exhaustive/pydantic-v1/src/seed/no_req_body/client.py +++ b/seed/python-sdk/exhaustive/pydantic-v1/src/seed/no_req_body/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..types.object.types.object_with_optional_field import ObjectWithOptionalField @@ -42,26 +38,7 @@ def get_with_no_request_body( client.no_req_body.get_with_no_request_body() """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -93,29 +70,7 @@ def post_with_no_request_body(self, *, request_options: typing.Optional[RequestO client.no_req_body.post_with_no_request_body() """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -154,26 +109,7 @@ async def get_with_no_request_body( await client.no_req_body.get_with_no_request_body() """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -205,29 +141,7 @@ async def post_with_no_request_body(self, *, request_options: typing.Optional[Re await client.no_req_body.post_with_no_request_body() """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/pydantic-v1/src/seed/req_with_headers/client.py b/seed/python-sdk/exhaustive/pydantic-v1/src/seed/req_with_headers/client.py index 3e7f80e7435..4ec08e7ee09 100644 --- a/seed/python-sdk/exhaustive/pydantic-v1/src/seed/req_with_headers/client.py +++ b/seed/python-sdk/exhaustive/pydantic-v1/src/seed/req_with_headers/client.py @@ -1,14 +1,10 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -25,7 +21,7 @@ def get_with_custom_header( x_test_service_header: str, x_test_endpoint_header: str, request: str, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -58,33 +54,15 @@ def get_with_custom_header( ) """ _response = self._client_wrapper.httpx_client.request( + "test-headers/custom-header", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "test-headers/custom-header"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-TEST-SERVICE-HEADER": str(x_test_service_header) - if x_test_service_header is not None - else None, - "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) - if x_test_endpoint_header is not None - else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + headers={ + "X-TEST-SERVICE-HEADER": str(x_test_service_header) if x_test_service_header is not None else None, + "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) if x_test_endpoint_header is not None else None, + }, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return @@ -105,7 +83,7 @@ async def get_with_custom_header( x_test_service_header: str, x_test_endpoint_header: str, request: str, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -138,33 +116,15 @@ async def get_with_custom_header( ) """ _response = await self._client_wrapper.httpx_client.request( + "test-headers/custom-header", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "test-headers/custom-header"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-TEST-SERVICE-HEADER": str(x_test_service_header) - if x_test_service_header is not None - else None, - "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) - if x_test_endpoint_header is not None - else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + headers={ + "X-TEST-SERVICE-HEADER": str(x_test_service_header) if x_test_service_header is not None else None, + "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) if x_test_endpoint_header is not None else None, + }, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return diff --git a/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/core/client_wrapper.py b/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/core/client_wrapper.py index 5b0c9d5ad91..8d01b584b82 100644 --- a/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/core/client_wrapper.py @@ -53,7 +53,12 @@ def __init__( httpx_client: httpx.Client, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): @@ -66,4 +71,9 @@ def __init__( httpx_client: httpx.AsyncClient, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/core/http_client.py b/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/core/http_client.py +++ b/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/endpoints/container/client.py b/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/endpoints/container/client.py index 5ff9a60a6ce..6fed4d0f11c 100644 --- a/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/endpoints/container/client.py +++ b/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/endpoints/container/client.py @@ -1,14 +1,10 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...core.unchecked_base_model import construct_type from ...types.object.types.object_with_required_field import ObjectWithRequiredField @@ -49,32 +45,7 @@ def get_and_return_list_of_primitives( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(typing.List[str], construct_type(type_=typing.List[str], object_=_response.json())) # type: ignore @@ -88,7 +59,7 @@ def get_and_return_list_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -120,32 +91,7 @@ def get_and_return_list_of_objects( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(typing.List[ObjectWithRequiredField], construct_type(type_=typing.List[ObjectWithRequiredField], object_=_response.json())) # type: ignore @@ -183,32 +129,7 @@ def get_and_return_set_of_primitives( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(typing.Set[str], construct_type(type_=typing.Set[str], object_=_response.json())) # type: ignore @@ -222,7 +143,7 @@ def get_and_return_set_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -254,32 +175,7 @@ def get_and_return_set_of_objects( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(typing.List[ObjectWithRequiredField], construct_type(type_=typing.List[ObjectWithRequiredField], object_=_response.json())) # type: ignore @@ -317,32 +213,7 @@ def get_and_return_map_prim_to_prim( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-prim"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-prim", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(typing.Dict[str, str], construct_type(type_=typing.Dict[str, str], object_=_response.json())) # type: ignore @@ -356,7 +227,7 @@ def get_and_return_map_of_prim_to_object( self, *, request: typing.Dict[str, ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Dict[str, ObjectWithRequiredField]: """ Parameters @@ -388,32 +259,7 @@ def get_and_return_map_of_prim_to_object( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-object", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(typing.Dict[str, ObjectWithRequiredField], construct_type(type_=typing.Dict[str, ObjectWithRequiredField], object_=_response.json())) # type: ignore @@ -427,7 +273,7 @@ def get_and_return_optional( self, *, request: typing.Optional[ObjectWithRequiredField] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Optional[ObjectWithRequiredField]: """ Parameters @@ -457,32 +303,7 @@ def get_and_return_optional( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/opt-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/opt-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(typing.Optional[ObjectWithRequiredField], construct_type(type_=typing.Optional[ObjectWithRequiredField], object_=_response.json())) # type: ignore @@ -525,32 +346,7 @@ async def get_and_return_list_of_primitives( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(typing.List[str], construct_type(type_=typing.List[str], object_=_response.json())) # type: ignore @@ -564,7 +360,7 @@ async def get_and_return_list_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -596,32 +392,7 @@ async def get_and_return_list_of_objects( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(typing.List[ObjectWithRequiredField], construct_type(type_=typing.List[ObjectWithRequiredField], object_=_response.json())) # type: ignore @@ -659,32 +430,7 @@ async def get_and_return_set_of_primitives( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(typing.Set[str], construct_type(type_=typing.Set[str], object_=_response.json())) # type: ignore @@ -698,7 +444,7 @@ async def get_and_return_set_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -730,32 +476,7 @@ async def get_and_return_set_of_objects( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(typing.List[ObjectWithRequiredField], construct_type(type_=typing.List[ObjectWithRequiredField], object_=_response.json())) # type: ignore @@ -793,32 +514,7 @@ async def get_and_return_map_prim_to_prim( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-prim"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-prim", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(typing.Dict[str, str], construct_type(type_=typing.Dict[str, str], object_=_response.json())) # type: ignore @@ -832,7 +528,7 @@ async def get_and_return_map_of_prim_to_object( self, *, request: typing.Dict[str, ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Dict[str, ObjectWithRequiredField]: """ Parameters @@ -864,32 +560,7 @@ async def get_and_return_map_of_prim_to_object( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-object", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(typing.Dict[str, ObjectWithRequiredField], construct_type(type_=typing.Dict[str, ObjectWithRequiredField], object_=_response.json())) # type: ignore @@ -903,7 +574,7 @@ async def get_and_return_optional( self, *, request: typing.Optional[ObjectWithRequiredField] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Optional[ObjectWithRequiredField]: """ Parameters @@ -933,32 +604,7 @@ async def get_and_return_optional( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/opt-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/opt-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(typing.Optional[ObjectWithRequiredField], construct_type(type_=typing.Optional[ObjectWithRequiredField], object_=_response.json())) # type: ignore diff --git a/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/endpoints/enum/client.py b/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/endpoints/enum/client.py index 0469a2cae77..7483218d13e 100644 --- a/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/endpoints/enum/client.py +++ b/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/endpoints/enum/client.py @@ -1,14 +1,10 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...core.unchecked_base_model import construct_type from ...types.enum.types.weather_report import WeatherReport @@ -49,27 +45,7 @@ def get_and_return_enum( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "enum"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "enum", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(WeatherReport, construct_type(type_=WeatherReport, object_=_response.json())) # type: ignore @@ -112,27 +88,7 @@ async def get_and_return_enum( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "enum"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "enum", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(WeatherReport, construct_type(type_=WeatherReport, object_=_response.json())) # type: ignore diff --git a/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/endpoints/http_methods/client.py b/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/endpoints/http_methods/client.py index 22289887f90..794000dce5b 100644 --- a/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/endpoints/http_methods/client.py +++ b/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/endpoints/http_methods/client.py @@ -2,15 +2,12 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...core.unchecked_base_model import construct_type from ...types.object.types.object_with_optional_field import ObjectWithOptionalField @@ -49,26 +46,7 @@ def test_get(self, id: str, *, request_options: typing.Optional[RequestOptions] ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return typing.cast(str, construct_type(type_=str, object_=_response.json())) # type: ignore @@ -105,34 +83,8 @@ def test_post( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "http-methods"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "http-methods", method="POST", json={"string": string}, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(ObjectWithOptionalField, construct_type(type_=ObjectWithOptionalField, object_=_response.json())) # type: ignore @@ -172,34 +124,12 @@ def test_put( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PUT", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return typing.cast(ObjectWithOptionalField, construct_type(type_=ObjectWithOptionalField, object_=_response.json())) # type: ignore @@ -296,58 +226,25 @@ def test_patch( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PATCH", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return typing.cast(ObjectWithOptionalField, construct_type(type_=ObjectWithOptionalField, object_=_response.json())) # type: ignore @@ -383,29 +280,7 @@ def test_delete(self, id: str, *, request_options: typing.Optional[RequestOption ) """ _response = self._client_wrapper.httpx_client.request( - method="DELETE", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="DELETE", request_options=request_options ) if 200 <= _response.status_code < 300: return typing.cast(bool, construct_type(type_=bool, object_=_response.json())) # type: ignore @@ -446,26 +321,7 @@ async def test_get(self, id: str, *, request_options: typing.Optional[RequestOpt ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return typing.cast(str, construct_type(type_=str, object_=_response.json())) # type: ignore @@ -502,34 +358,8 @@ async def test_post( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "http-methods"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "http-methods", method="POST", json={"string": string}, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(ObjectWithOptionalField, construct_type(type_=ObjectWithOptionalField, object_=_response.json())) # type: ignore @@ -569,34 +399,12 @@ async def test_put( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PUT", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return typing.cast(ObjectWithOptionalField, construct_type(type_=ObjectWithOptionalField, object_=_response.json())) # type: ignore @@ -693,58 +501,25 @@ async def test_patch( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = await self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PATCH", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return typing.cast(ObjectWithOptionalField, construct_type(type_=ObjectWithOptionalField, object_=_response.json())) # type: ignore @@ -780,29 +555,7 @@ async def test_delete(self, id: str, *, request_options: typing.Optional[Request ) """ _response = await self._client_wrapper.httpx_client.request( - method="DELETE", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="DELETE", request_options=request_options ) if 200 <= _response.status_code < 300: return typing.cast(bool, construct_type(type_=bool, object_=_response.json())) # type: ignore diff --git a/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/endpoints/object/client.py b/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/endpoints/object/client.py index 11dff96f2a5..72cbe4fdd30 100644 --- a/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/endpoints/object/client.py +++ b/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/endpoints/object/client.py @@ -2,15 +2,12 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...core.unchecked_base_model import construct_type from ...types.object.types.nested_object_with_optional_field import NestedObjectWithOptionalField @@ -110,60 +107,25 @@ def get_and_return_with_optional_field( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return typing.cast(ObjectWithOptionalField, construct_type(type_=ObjectWithOptionalField, object_=_response.json())) # type: ignore @@ -200,36 +162,12 @@ def get_and_return_with_required_field( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-required-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-required-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return typing.cast(ObjectWithRequiredField, construct_type(type_=ObjectWithRequiredField, object_=_response.json())) # type: ignore @@ -266,36 +204,12 @@ def get_and_return_with_map_of_map( map_={"string": {"string": "string"}}, ) """ - _request: typing.Dict[str, typing.Any] = {"map": map_} _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-map-of-map", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-map-of-map" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"map": map_}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return typing.cast(ObjectWithMapOfMap, construct_type(type_=ObjectWithMapOfMap, object_=_response.json())) # type: ignore @@ -362,40 +276,12 @@ def get_and_return_nested_with_optional_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if nested_object is not OMIT: - _request["NestedObject"] = nested_object _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return typing.cast(NestedObjectWithOptionalField, construct_type(type_=NestedObjectWithOptionalField, object_=_response.json())) # type: ignore @@ -466,37 +352,12 @@ def get_and_return_nested_with_required_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {"string": string, "NestedObject": nested_object} _response = self._client_wrapper.httpx_client.request( + f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", - f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return typing.cast(NestedObjectWithRequiredField, construct_type(type_=NestedObjectWithRequiredField, object_=_response.json())) # type: ignore @@ -565,34 +426,11 @@ def get_and_return_nested_with_required_field_as_list( ) """ _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-required-field-list", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-required-field-list" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return typing.cast(NestedObjectWithRequiredField, construct_type(type_=NestedObjectWithRequiredField, object_=_response.json())) # type: ignore @@ -690,60 +528,25 @@ async def get_and_return_with_optional_field( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return typing.cast(ObjectWithOptionalField, construct_type(type_=ObjectWithOptionalField, object_=_response.json())) # type: ignore @@ -780,36 +583,12 @@ async def get_and_return_with_required_field( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-required-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-required-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return typing.cast(ObjectWithRequiredField, construct_type(type_=ObjectWithRequiredField, object_=_response.json())) # type: ignore @@ -846,36 +625,12 @@ async def get_and_return_with_map_of_map( map_={"string": {"string": "string"}}, ) """ - _request: typing.Dict[str, typing.Any] = {"map": map_} _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-map-of-map", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-map-of-map" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"map": map_}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return typing.cast(ObjectWithMapOfMap, construct_type(type_=ObjectWithMapOfMap, object_=_response.json())) # type: ignore @@ -942,40 +697,12 @@ async def get_and_return_nested_with_optional_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if nested_object is not OMIT: - _request["NestedObject"] = nested_object _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return typing.cast(NestedObjectWithOptionalField, construct_type(type_=NestedObjectWithOptionalField, object_=_response.json())) # type: ignore @@ -1046,37 +773,12 @@ async def get_and_return_nested_with_required_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {"string": string, "NestedObject": nested_object} _response = await self._client_wrapper.httpx_client.request( + f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", - f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return typing.cast(NestedObjectWithRequiredField, construct_type(type_=NestedObjectWithRequiredField, object_=_response.json())) # type: ignore @@ -1145,34 +847,11 @@ async def get_and_return_nested_with_required_field_as_list( ) """ _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-required-field-list", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-required-field-list" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return typing.cast(NestedObjectWithRequiredField, construct_type(type_=NestedObjectWithRequiredField, object_=_response.json())) # type: ignore diff --git a/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/endpoints/params/client.py b/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/endpoints/params/client.py index c7e91dbc3e7..c26646b1766 100644 --- a/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/endpoints/params/client.py +++ b/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/endpoints/params/client.py @@ -1,14 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...core.unchecked_base_model import construct_type @@ -48,28 +45,7 @@ def get_with_path(self, param: str, *, request_options: typing.Optional[RequestO ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"params/path/{jsonable_encoder(param)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return typing.cast(str, construct_type(type_=str, object_=_response.json())) # type: ignore @@ -112,36 +88,7 @@ def get_with_query( ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "number": number, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "number": number}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -188,36 +135,7 @@ def get_with_allow_multiple_query( ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "numer": numer, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "numer": numer}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -260,37 +178,10 @@ def get_with_path_and_query( ) """ _response = self._client_wrapper.httpx_client.request( + f"params/path-query/{jsonable_encoder(param)}", method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path-query/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"query": query}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -333,29 +224,11 @@ def modify_with_path( ) """ _response = self._client_wrapper.httpx_client.request( + f"params/path/{jsonable_encoder(param)}", method="PUT", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return typing.cast(str, construct_type(type_=str, object_=_response.json())) # type: ignore @@ -398,28 +271,7 @@ async def get_with_path(self, param: str, *, request_options: typing.Optional[Re ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"params/path/{jsonable_encoder(param)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return typing.cast(str, construct_type(type_=str, object_=_response.json())) # type: ignore @@ -462,36 +314,7 @@ async def get_with_query( ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "number": number, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "number": number}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -538,36 +361,7 @@ async def get_with_allow_multiple_query( ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "numer": numer, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "numer": numer}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -610,37 +404,10 @@ async def get_with_path_and_query( ) """ _response = await self._client_wrapper.httpx_client.request( + f"params/path-query/{jsonable_encoder(param)}", method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path-query/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"query": query}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -683,29 +450,11 @@ async def modify_with_path( ) """ _response = await self._client_wrapper.httpx_client.request( + f"params/path/{jsonable_encoder(param)}", method="PUT", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return typing.cast(str, construct_type(type_=str, object_=_response.json())) # type: ignore diff --git a/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/endpoints/primitive/client.py b/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/endpoints/primitive/client.py index f1976c7eb37..75978f25a33 100644 --- a/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/endpoints/primitive/client.py +++ b/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/endpoints/primitive/client.py @@ -2,15 +2,11 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...core.unchecked_base_model import construct_type @@ -48,27 +44,7 @@ def get_and_return_string(self, *, request: str, request_options: typing.Optiona ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/string"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/string", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(str, construct_type(type_=str, object_=_response.json())) # type: ignore @@ -104,27 +80,7 @@ def get_and_return_int(self, *, request: int, request_options: typing.Optional[R ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/integer"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/integer", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(int, construct_type(type_=int, object_=_response.json())) # type: ignore @@ -160,32 +116,7 @@ def get_and_return_long(self, *, request: int, request_options: typing.Optional[ ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/long"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/long", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(int, construct_type(type_=int, object_=_response.json())) # type: ignore @@ -223,27 +154,7 @@ def get_and_return_double( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/double"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/double", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(float, construct_type(type_=float, object_=_response.json())) # type: ignore @@ -279,27 +190,7 @@ def get_and_return_bool(self, *, request: bool, request_options: typing.Optional ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/boolean"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/boolean", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(bool, construct_type(type_=bool, object_=_response.json())) # type: ignore @@ -341,32 +232,7 @@ def get_and_return_datetime( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/datetime"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/datetime", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(dt.datetime, construct_type(type_=dt.datetime, object_=_response.json())) # type: ignore @@ -408,32 +274,7 @@ def get_and_return_date( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/date"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/date", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(dt.date, construct_type(type_=dt.date, object_=_response.json())) # type: ignore @@ -475,32 +316,7 @@ def get_and_return_uuid( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/uuid"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/uuid", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(uuid.UUID, construct_type(type_=uuid.UUID, object_=_response.json())) # type: ignore @@ -536,32 +352,7 @@ def get_and_return_base_64(self, *, request: str, request_options: typing.Option ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/base64"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/base64", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(str, construct_type(type_=str, object_=_response.json())) # type: ignore @@ -604,27 +395,7 @@ async def get_and_return_string( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/string"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/string", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(str, construct_type(type_=str, object_=_response.json())) # type: ignore @@ -660,27 +431,7 @@ async def get_and_return_int(self, *, request: int, request_options: typing.Opti ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/integer"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/integer", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(int, construct_type(type_=int, object_=_response.json())) # type: ignore @@ -718,32 +469,7 @@ async def get_and_return_long( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/long"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/long", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(int, construct_type(type_=int, object_=_response.json())) # type: ignore @@ -781,27 +507,7 @@ async def get_and_return_double( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/double"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/double", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(float, construct_type(type_=float, object_=_response.json())) # type: ignore @@ -839,27 +545,7 @@ async def get_and_return_bool( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/boolean"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/boolean", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(bool, construct_type(type_=bool, object_=_response.json())) # type: ignore @@ -901,32 +587,7 @@ async def get_and_return_datetime( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/datetime"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/datetime", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(dt.datetime, construct_type(type_=dt.datetime, object_=_response.json())) # type: ignore @@ -968,32 +629,7 @@ async def get_and_return_date( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/date"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/date", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(dt.date, construct_type(type_=dt.date, object_=_response.json())) # type: ignore @@ -1035,32 +671,7 @@ async def get_and_return_uuid( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/uuid"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/uuid", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(uuid.UUID, construct_type(type_=uuid.UUID, object_=_response.json())) # type: ignore @@ -1098,32 +709,7 @@ async def get_and_return_base_64( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/base64"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/base64", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(str, construct_type(type_=str, object_=_response.json())) # type: ignore diff --git a/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/endpoints/union/client.py b/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/endpoints/union/client.py index be2bec0297f..536d170f803 100644 --- a/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/endpoints/union/client.py +++ b/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/endpoints/union/client.py @@ -1,14 +1,10 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...core.unchecked_base_model import construct_type from ...types.union.types.animal import Animal @@ -53,32 +49,7 @@ def get_and_return_union( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "union"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "union", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(Animal, construct_type(type_=Animal, object_=_response.json())) # type: ignore @@ -125,32 +96,7 @@ async def get_and_return_union( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "union"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "union", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(Animal, construct_type(type_=Animal, object_=_response.json())) # type: ignore diff --git a/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/inlined_requests/client.py b/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/inlined_requests/client.py index b7367e3c6aa..a705d711d4c 100644 --- a/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/inlined_requests/client.py +++ b/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/inlined_requests/client.py @@ -1,14 +1,10 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..core.unchecked_base_model import construct_type from ..general_errors.errors.bad_request_body import BadRequestBody @@ -29,7 +25,7 @@ def post_with_object_bodyand_response( string: str, integer: int, nested_object: ObjectWithOptionalField, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> ObjectWithOptionalField: """ POST with custom object in request body, response is an object @@ -87,32 +83,11 @@ def post_with_object_bodyand_response( ) """ _response = self._client_wrapper.httpx_client.request( + "req-bodies/object", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "req-bodies/object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "integer": integer, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return typing.cast(ObjectWithOptionalField, construct_type(type_=ObjectWithOptionalField, object_=_response.json())) # type: ignore @@ -137,7 +112,7 @@ async def post_with_object_bodyand_response( string: str, integer: int, nested_object: ObjectWithOptionalField, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> ObjectWithOptionalField: """ POST with custom object in request body, response is an object @@ -195,32 +170,11 @@ async def post_with_object_bodyand_response( ) """ _response = await self._client_wrapper.httpx_client.request( + "req-bodies/object", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "req-bodies/object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "integer": integer, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return typing.cast(ObjectWithOptionalField, construct_type(type_=ObjectWithOptionalField, object_=_response.json())) # type: ignore diff --git a/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/no_auth/client.py b/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/no_auth/client.py index 19fd1dc4a0d..bd795ffda49 100644 --- a/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/no_auth/client.py +++ b/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/no_auth/client.py @@ -1,14 +1,10 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..core.unchecked_base_model import construct_type from ..general_errors.errors.bad_request_body import BadRequestBody @@ -52,32 +48,7 @@ def post_with_no_auth( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-auth", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(bool, construct_type(type_=bool, object_=_response.json())) # type: ignore @@ -126,32 +97,7 @@ async def post_with_no_auth( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-auth", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return typing.cast(bool, construct_type(type_=bool, object_=_response.json())) # type: ignore diff --git a/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/no_req_body/client.py b/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/no_req_body/client.py index 5def0d702a7..d9ff046402f 100644 --- a/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/no_req_body/client.py +++ b/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/no_req_body/client.py @@ -1,14 +1,10 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..core.unchecked_base_model import construct_type from ..types.object.types.object_with_optional_field import ObjectWithOptionalField @@ -42,26 +38,7 @@ def get_with_no_request_body( client.no_req_body.get_with_no_request_body() """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return typing.cast(ObjectWithOptionalField, construct_type(type_=ObjectWithOptionalField, object_=_response.json())) # type: ignore @@ -93,29 +70,7 @@ def post_with_no_request_body(self, *, request_options: typing.Optional[RequestO client.no_req_body.post_with_no_request_body() """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return typing.cast(str, construct_type(type_=str, object_=_response.json())) # type: ignore @@ -154,26 +109,7 @@ async def get_with_no_request_body( await client.no_req_body.get_with_no_request_body() """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return typing.cast(ObjectWithOptionalField, construct_type(type_=ObjectWithOptionalField, object_=_response.json())) # type: ignore @@ -205,29 +141,7 @@ async def post_with_no_request_body(self, *, request_options: typing.Optional[Re await client.no_req_body.post_with_no_request_body() """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return typing.cast(str, construct_type(type_=str, object_=_response.json())) # type: ignore diff --git a/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/req_with_headers/client.py b/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/req_with_headers/client.py index 3e7f80e7435..4ec08e7ee09 100644 --- a/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/req_with_headers/client.py +++ b/seed/python-sdk/exhaustive/skip-pydantic-validation/src/seed/req_with_headers/client.py @@ -1,14 +1,10 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -25,7 +21,7 @@ def get_with_custom_header( x_test_service_header: str, x_test_endpoint_header: str, request: str, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -58,33 +54,15 @@ def get_with_custom_header( ) """ _response = self._client_wrapper.httpx_client.request( + "test-headers/custom-header", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "test-headers/custom-header"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-TEST-SERVICE-HEADER": str(x_test_service_header) - if x_test_service_header is not None - else None, - "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) - if x_test_endpoint_header is not None - else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + headers={ + "X-TEST-SERVICE-HEADER": str(x_test_service_header) if x_test_service_header is not None else None, + "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) if x_test_endpoint_header is not None else None, + }, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return @@ -105,7 +83,7 @@ async def get_with_custom_header( x_test_service_header: str, x_test_endpoint_header: str, request: str, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -138,33 +116,15 @@ async def get_with_custom_header( ) """ _response = await self._client_wrapper.httpx_client.request( + "test-headers/custom-header", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "test-headers/custom-header"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-TEST-SERVICE-HEADER": str(x_test_service_header) - if x_test_service_header is not None - else None, - "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) - if x_test_endpoint_header is not None - else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + headers={ + "X-TEST-SERVICE-HEADER": str(x_test_service_header) if x_test_service_header is not None else None, + "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) if x_test_endpoint_header is not None else None, + }, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return diff --git a/seed/python-sdk/exhaustive/union-utils/src/seed/core/client_wrapper.py b/seed/python-sdk/exhaustive/union-utils/src/seed/core/client_wrapper.py index 5b0c9d5ad91..8d01b584b82 100644 --- a/seed/python-sdk/exhaustive/union-utils/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/exhaustive/union-utils/src/seed/core/client_wrapper.py @@ -53,7 +53,12 @@ def __init__( httpx_client: httpx.Client, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): @@ -66,4 +71,9 @@ def __init__( httpx_client: httpx.AsyncClient, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/exhaustive/union-utils/src/seed/core/http_client.py b/seed/python-sdk/exhaustive/union-utils/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/exhaustive/union-utils/src/seed/core/http_client.py +++ b/seed/python-sdk/exhaustive/union-utils/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/exhaustive/union-utils/src/seed/endpoints/container/client.py b/seed/python-sdk/exhaustive/union-utils/src/seed/endpoints/container/client.py index c5ab55847c7..e02bf812398 100644 --- a/seed/python-sdk/exhaustive/union-utils/src/seed/endpoints/container/client.py +++ b/seed/python-sdk/exhaustive/union-utils/src/seed/endpoints/container/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.object_with_required_field import ObjectWithRequiredField @@ -49,32 +45,7 @@ def get_and_return_list_of_primitives( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[str], _response.json()) # type: ignore @@ -88,7 +59,7 @@ def get_and_return_list_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -120,32 +91,7 @@ def get_and_return_list_of_objects( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -183,32 +129,7 @@ def get_and_return_set_of_primitives( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Set[str], _response.json()) # type: ignore @@ -222,7 +143,7 @@ def get_and_return_set_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -254,32 +175,7 @@ def get_and_return_set_of_objects( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -317,32 +213,7 @@ def get_and_return_map_prim_to_prim( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-prim"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-prim", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, str], _response.json()) # type: ignore @@ -356,7 +227,7 @@ def get_and_return_map_of_prim_to_object( self, *, request: typing.Dict[str, ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Dict[str, ObjectWithRequiredField]: """ Parameters @@ -388,32 +259,7 @@ def get_and_return_map_of_prim_to_object( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-object", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, ObjectWithRequiredField], _response.json()) # type: ignore @@ -427,7 +273,7 @@ def get_and_return_optional( self, *, request: typing.Optional[ObjectWithRequiredField] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Optional[ObjectWithRequiredField]: """ Parameters @@ -457,32 +303,7 @@ def get_and_return_optional( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/opt-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/opt-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Optional[ObjectWithRequiredField], _response.json()) # type: ignore @@ -525,32 +346,7 @@ async def get_and_return_list_of_primitives( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[str], _response.json()) # type: ignore @@ -564,7 +360,7 @@ async def get_and_return_list_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -596,32 +392,7 @@ async def get_and_return_list_of_objects( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/list-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/list-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -659,32 +430,7 @@ async def get_and_return_set_of_primitives( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-primitives"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-primitives", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Set[str], _response.json()) # type: ignore @@ -698,7 +444,7 @@ async def get_and_return_set_of_objects( self, *, request: typing.Sequence[ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.List[ObjectWithRequiredField]: """ Parameters @@ -730,32 +476,7 @@ async def get_and_return_set_of_objects( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/set-of-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/set-of-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[ObjectWithRequiredField], _response.json()) # type: ignore @@ -793,32 +514,7 @@ async def get_and_return_map_prim_to_prim( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-prim"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-prim", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, str], _response.json()) # type: ignore @@ -832,7 +528,7 @@ async def get_and_return_map_of_prim_to_object( self, *, request: typing.Dict[str, ObjectWithRequiredField], - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Dict[str, ObjectWithRequiredField]: """ Parameters @@ -864,32 +560,7 @@ async def get_and_return_map_of_prim_to_object( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/map-prim-to-object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/map-prim-to-object", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Dict[str, ObjectWithRequiredField], _response.json()) # type: ignore @@ -903,7 +574,7 @@ async def get_and_return_optional( self, *, request: typing.Optional[ObjectWithRequiredField] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> typing.Optional[ObjectWithRequiredField]: """ Parameters @@ -933,32 +604,7 @@ async def get_and_return_optional( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "container/opt-objects"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "container/opt-objects", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.Optional[ObjectWithRequiredField], _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/union-utils/src/seed/endpoints/enum/client.py b/seed/python-sdk/exhaustive/union-utils/src/seed/endpoints/enum/client.py index 94ee2ac420f..8fcd0668b4b 100644 --- a/seed/python-sdk/exhaustive/union-utils/src/seed/endpoints/enum/client.py +++ b/seed/python-sdk/exhaustive/union-utils/src/seed/endpoints/enum/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.enum.types.weather_report import WeatherReport @@ -49,27 +45,7 @@ def get_and_return_enum( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "enum"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "enum", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(WeatherReport, _response.json()) # type: ignore @@ -112,27 +88,7 @@ async def get_and_return_enum( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "enum"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "enum", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(WeatherReport, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/union-utils/src/seed/endpoints/http_methods/client.py b/seed/python-sdk/exhaustive/union-utils/src/seed/endpoints/http_methods/client.py index 1c8af11a4bd..3bd65f6adda 100644 --- a/seed/python-sdk/exhaustive/union-utils/src/seed/endpoints/http_methods/client.py +++ b/seed/python-sdk/exhaustive/union-utils/src/seed/endpoints/http_methods/client.py @@ -2,7 +2,6 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError @@ -10,8 +9,6 @@ from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.object_with_optional_field import ObjectWithOptionalField @@ -49,26 +46,7 @@ def test_get(self, id: str, *, request_options: typing.Optional[RequestOptions] ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -105,34 +83,8 @@ def test_post( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "http-methods"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "http-methods", method="POST", json={"string": string}, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -172,34 +124,12 @@ def test_put( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PUT", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -296,58 +226,25 @@ def test_patch( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PATCH", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -383,29 +280,7 @@ def test_delete(self, id: str, *, request_options: typing.Optional[RequestOption ) """ _response = self._client_wrapper.httpx_client.request( - method="DELETE", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="DELETE", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -446,26 +321,7 @@ async def test_get(self, id: str, *, request_options: typing.Optional[RequestOpt ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -502,34 +358,8 @@ async def test_post( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "http-methods"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "http-methods", method="POST", json={"string": string}, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -569,34 +399,12 @@ async def test_put( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PUT", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -693,58 +501,25 @@ async def test_patch( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = await self._client_wrapper.httpx_client.request( + f"http-methods/{jsonable_encoder(id)}", method="PATCH", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -780,29 +555,7 @@ async def test_delete(self, id: str, *, request_options: typing.Optional[Request ) """ _response = await self._client_wrapper.httpx_client.request( - method="DELETE", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"http-methods/{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"http-methods/{jsonable_encoder(id)}", method="DELETE", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/union-utils/src/seed/endpoints/object/client.py b/seed/python-sdk/exhaustive/union-utils/src/seed/endpoints/object/client.py index 83230dec1f4..7e66510fdb0 100644 --- a/seed/python-sdk/exhaustive/union-utils/src/seed/endpoints/object/client.py +++ b/seed/python-sdk/exhaustive/union-utils/src/seed/endpoints/object/client.py @@ -2,7 +2,6 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError @@ -10,8 +9,6 @@ from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.object.types.nested_object_with_optional_field import NestedObjectWithOptionalField from ...types.object.types.nested_object_with_required_field import NestedObjectWithRequiredField @@ -110,60 +107,25 @@ def get_and_return_with_optional_field( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -200,36 +162,12 @@ def get_and_return_with_required_field( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-required-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-required-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithRequiredField, _response.json()) # type: ignore @@ -266,36 +204,12 @@ def get_and_return_with_map_of_map( map_={"string": {"string": "string"}}, ) """ - _request: typing.Dict[str, typing.Any] = {"map": map_} _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-with-map-of-map", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-map-of-map" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"map": map_}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithMapOfMap, _response.json()) # type: ignore @@ -362,40 +276,12 @@ def get_and_return_nested_with_optional_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if nested_object is not OMIT: - _request["NestedObject"] = nested_object _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithOptionalField, _response.json()) # type: ignore @@ -466,37 +352,12 @@ def get_and_return_nested_with_required_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {"string": string, "NestedObject": nested_object} _response = self._client_wrapper.httpx_client.request( + f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", - f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -565,34 +426,11 @@ def get_and_return_nested_with_required_field_as_list( ) """ _response = self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-required-field-list", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-required-field-list" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -690,60 +528,25 @@ async def get_and_return_with_optional_field( map_={1: "string"}, ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if integer is not OMIT: - _request["integer"] = integer - if long_ is not OMIT: - _request["long"] = long_ - if double is not OMIT: - _request["double"] = double - if bool_ is not OMIT: - _request["bool"] = bool_ - if datetime is not OMIT: - _request["datetime"] = datetime - if date is not OMIT: - _request["date"] = date - if uuid_ is not OMIT: - _request["uuid"] = uuid_ - if base_64 is not OMIT: - _request["base64"] = base_64 - if list_ is not OMIT: - _request["list"] = list_ - if set_ is not OMIT: - _request["set"] = set_ - if map_ is not OMIT: - _request["map"] = map_ _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "string": string, + "integer": integer, + "long": long_, + "double": double, + "bool": bool_, + "datetime": datetime, + "date": date, + "uuid": uuid_, + "base64": base_64, + "list": list_, + "set": set_, + "map": map_, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -780,36 +583,12 @@ async def get_and_return_with_required_field( string="string", ) """ - _request: typing.Dict[str, typing.Any] = {"string": string} _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-required-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-required-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithRequiredField, _response.json()) # type: ignore @@ -846,36 +625,12 @@ async def get_and_return_with_map_of_map( map_={"string": {"string": "string"}}, ) """ - _request: typing.Dict[str, typing.Any] = {"map": map_} _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-with-map-of-map", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-with-map-of-map" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"map": map_}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithMapOfMap, _response.json()) # type: ignore @@ -942,40 +697,12 @@ async def get_and_return_nested_with_optional_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {} - if string is not OMIT: - _request["string"] = string - if nested_object is not OMIT: - _request["NestedObject"] = nested_object _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-optional-field", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-optional-field" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithOptionalField, _response.json()) # type: ignore @@ -1046,37 +773,12 @@ async def get_and_return_nested_with_required_field( ), ) """ - _request: typing.Dict[str, typing.Any] = {"string": string, "NestedObject": nested_object} _response = await self._client_wrapper.httpx_client.request( + f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", - f"object/get-and-return-nested-with-required-field/{jsonable_encoder(string_)}", - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore @@ -1145,34 +847,11 @@ async def get_and_return_nested_with_required_field_as_list( ) """ _response = await self._client_wrapper.httpx_client.request( + "object/get-and-return-nested-with-required-field-list", method="POST", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", "object/get-and-return-nested-with-required-field-list" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(NestedObjectWithRequiredField, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/union-utils/src/seed/endpoints/params/client.py b/seed/python-sdk/exhaustive/union-utils/src/seed/endpoints/params/client.py index d1f25df27fb..089d9fab5ce 100644 --- a/seed/python-sdk/exhaustive/union-utils/src/seed/endpoints/params/client.py +++ b/seed/python-sdk/exhaustive/union-utils/src/seed/endpoints/params/client.py @@ -1,15 +1,12 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -48,28 +45,7 @@ def get_with_path(self, param: str, *, request_options: typing.Optional[RequestO ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"params/path/{jsonable_encoder(param)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -112,36 +88,7 @@ def get_with_query( ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "number": number, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "number": number}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -188,36 +135,7 @@ def get_with_allow_multiple_query( ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "numer": numer, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "numer": numer}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -260,37 +178,10 @@ def get_with_path_and_query( ) """ _response = self._client_wrapper.httpx_client.request( + f"params/path-query/{jsonable_encoder(param)}", method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path-query/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"query": query}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -333,29 +224,11 @@ def modify_with_path( ) """ _response = self._client_wrapper.httpx_client.request( + f"params/path/{jsonable_encoder(param)}", method="PUT", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -398,28 +271,7 @@ async def get_with_path(self, param: str, *, request_options: typing.Optional[Re ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"params/path/{jsonable_encoder(param)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -462,36 +314,7 @@ async def get_with_query( ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "number": number, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "number": number}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -538,36 +361,7 @@ async def get_with_allow_multiple_query( ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - "numer": numer, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "params", method="GET", params={"query": query, "numer": numer}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -610,37 +404,10 @@ async def get_with_path_and_query( ) """ _response = await self._client_wrapper.httpx_client.request( + f"params/path-query/{jsonable_encoder(param)}", method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path-query/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "query": query, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"query": query}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return @@ -683,29 +450,11 @@ async def modify_with_path( ) """ _response = await self._client_wrapper.httpx_client.request( + f"params/path/{jsonable_encoder(param)}", method="PUT", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"params/path/{jsonable_encoder(param)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/union-utils/src/seed/endpoints/primitive/client.py b/seed/python-sdk/exhaustive/union-utils/src/seed/endpoints/primitive/client.py index 076383510ff..64c7f6b2ca5 100644 --- a/seed/python-sdk/exhaustive/union-utils/src/seed/endpoints/primitive/client.py +++ b/seed/python-sdk/exhaustive/union-utils/src/seed/endpoints/primitive/client.py @@ -2,16 +2,12 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -48,27 +44,7 @@ def get_and_return_string(self, *, request: str, request_options: typing.Optiona ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/string"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/string", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -104,27 +80,7 @@ def get_and_return_int(self, *, request: int, request_options: typing.Optional[R ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/integer"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/integer", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -160,32 +116,7 @@ def get_and_return_long(self, *, request: int, request_options: typing.Optional[ ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/long"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/long", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -223,27 +154,7 @@ def get_and_return_double( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/double"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/double", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(float, _response.json()) # type: ignore @@ -279,27 +190,7 @@ def get_and_return_bool(self, *, request: bool, request_options: typing.Optional ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/boolean"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/boolean", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -341,32 +232,7 @@ def get_and_return_datetime( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/datetime"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/datetime", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.datetime, _response.json()) # type: ignore @@ -408,32 +274,7 @@ def get_and_return_date( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/date"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/date", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.date, _response.json()) # type: ignore @@ -475,32 +316,7 @@ def get_and_return_uuid( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/uuid"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/uuid", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(uuid.UUID, _response.json()) # type: ignore @@ -536,32 +352,7 @@ def get_and_return_base_64(self, *, request: str, request_options: typing.Option ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/base64"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/base64", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -604,27 +395,7 @@ async def get_and_return_string( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/string"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/string", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -660,27 +431,7 @@ async def get_and_return_int(self, *, request: int, request_options: typing.Opti ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/integer"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/integer", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -718,32 +469,7 @@ async def get_and_return_long( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/long"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/long", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(int, _response.json()) # type: ignore @@ -781,27 +507,7 @@ async def get_and_return_double( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/double"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/double", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(float, _response.json()) # type: ignore @@ -839,27 +545,7 @@ async def get_and_return_bool( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/boolean"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/boolean", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -901,32 +587,7 @@ async def get_and_return_datetime( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/datetime"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/datetime", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.datetime, _response.json()) # type: ignore @@ -968,32 +629,7 @@ async def get_and_return_date( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/date"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/date", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(dt.date, _response.json()) # type: ignore @@ -1035,32 +671,7 @@ async def get_and_return_uuid( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/uuid"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/uuid", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(uuid.UUID, _response.json()) # type: ignore @@ -1098,32 +709,7 @@ async def get_and_return_base_64( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "primitive/base64"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "primitive/base64", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/union-utils/src/seed/endpoints/union/client.py b/seed/python-sdk/exhaustive/union-utils/src/seed/endpoints/union/client.py index 23757c07bd8..843d9828bc6 100644 --- a/seed/python-sdk/exhaustive/union-utils/src/seed/endpoints/union/client.py +++ b/seed/python-sdk/exhaustive/union-utils/src/seed/endpoints/union/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from ...types.union.types.animal import Animal @@ -53,32 +49,7 @@ def get_and_return_union( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "union"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "union", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Animal, _response.json()) # type: ignore @@ -125,32 +96,7 @@ async def get_and_return_union( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "union"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "union", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Animal, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/union-utils/src/seed/inlined_requests/client.py b/seed/python-sdk/exhaustive/union-utils/src/seed/inlined_requests/client.py index 38e428f66e0..bfb17877f08 100644 --- a/seed/python-sdk/exhaustive/union-utils/src/seed/inlined_requests/client.py +++ b/seed/python-sdk/exhaustive/union-utils/src/seed/inlined_requests/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..general_errors.errors.bad_request_body import BadRequestBody from ..general_errors.types.bad_object_request_info import BadObjectRequestInfo @@ -29,7 +25,7 @@ def post_with_object_bodyand_response( string: str, integer: int, nested_object: ObjectWithOptionalField, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> ObjectWithOptionalField: """ POST with custom object in request body, response is an object @@ -87,32 +83,11 @@ def post_with_object_bodyand_response( ) """ _response = self._client_wrapper.httpx_client.request( + "req-bodies/object", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "req-bodies/object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "integer": integer, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -135,7 +110,7 @@ async def post_with_object_bodyand_response( string: str, integer: int, nested_object: ObjectWithOptionalField, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> ObjectWithOptionalField: """ POST with custom object in request body, response is an object @@ -193,32 +168,11 @@ async def post_with_object_bodyand_response( ) """ _response = await self._client_wrapper.httpx_client.request( + "req-bodies/object", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "req-bodies/object"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"string": string, "integer": integer, "NestedObject": nested_object}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"string": string, "integer": integer, "NestedObject": nested_object}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/union-utils/src/seed/no_auth/client.py b/seed/python-sdk/exhaustive/union-utils/src/seed/no_auth/client.py index fd4814dde0b..477bf563998 100644 --- a/seed/python-sdk/exhaustive/union-utils/src/seed/no_auth/client.py +++ b/seed/python-sdk/exhaustive/union-utils/src/seed/no_auth/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..general_errors.errors.bad_request_body import BadRequestBody from ..general_errors.types.bad_object_request_info import BadObjectRequestInfo @@ -52,32 +48,7 @@ def post_with_no_auth( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-auth", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -124,32 +95,7 @@ async def post_with_no_auth( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-auth"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-auth", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/union-utils/src/seed/no_req_body/client.py b/seed/python-sdk/exhaustive/union-utils/src/seed/no_req_body/client.py index f984b6c24d3..7e3fd3ae95f 100644 --- a/seed/python-sdk/exhaustive/union-utils/src/seed/no_req_body/client.py +++ b/seed/python-sdk/exhaustive/union-utils/src/seed/no_req_body/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..types.object.types.object_with_optional_field import ObjectWithOptionalField @@ -42,26 +38,7 @@ def get_with_no_request_body( client.no_req_body.get_with_no_request_body() """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -93,29 +70,7 @@ def post_with_no_request_body(self, *, request_options: typing.Optional[RequestO client.no_req_body.post_with_no_request_body() """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -154,26 +109,7 @@ async def get_with_no_request_body( await client.no_req_body.get_with_no_request_body() """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(ObjectWithOptionalField, _response.json()) # type: ignore @@ -205,29 +141,7 @@ async def post_with_no_request_body(self, *, request_options: typing.Optional[Re await client.no_req_body.post_with_no_request_body() """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "no-req-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "no-req-body", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/exhaustive/union-utils/src/seed/req_with_headers/client.py b/seed/python-sdk/exhaustive/union-utils/src/seed/req_with_headers/client.py index 3e7f80e7435..4ec08e7ee09 100644 --- a/seed/python-sdk/exhaustive/union-utils/src/seed/req_with_headers/client.py +++ b/seed/python-sdk/exhaustive/union-utils/src/seed/req_with_headers/client.py @@ -1,14 +1,10 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -25,7 +21,7 @@ def get_with_custom_header( x_test_service_header: str, x_test_endpoint_header: str, request: str, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -58,33 +54,15 @@ def get_with_custom_header( ) """ _response = self._client_wrapper.httpx_client.request( + "test-headers/custom-header", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "test-headers/custom-header"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-TEST-SERVICE-HEADER": str(x_test_service_header) - if x_test_service_header is not None - else None, - "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) - if x_test_endpoint_header is not None - else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + headers={ + "X-TEST-SERVICE-HEADER": str(x_test_service_header) if x_test_service_header is not None else None, + "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) if x_test_endpoint_header is not None else None, + }, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return @@ -105,7 +83,7 @@ async def get_with_custom_header( x_test_service_header: str, x_test_endpoint_header: str, request: str, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -138,33 +116,15 @@ async def get_with_custom_header( ) """ _response = await self._client_wrapper.httpx_client.request( + "test-headers/custom-header", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "test-headers/custom-header"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-TEST-SERVICE-HEADER": str(x_test_service_header) - if x_test_service_header is not None - else None, - "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) - if x_test_endpoint_header is not None - else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json=request, + headers={ + "X-TEST-SERVICE-HEADER": str(x_test_service_header) if x_test_service_header is not None else None, + "X-TEST-ENDPOINT-HEADER": str(x_test_endpoint_header) if x_test_endpoint_header is not None else None, + }, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return diff --git a/seed/python-sdk/extends/src/seed/core/client_wrapper.py b/seed/python-sdk/extends/src/seed/core/client_wrapper.py index d2e3fb9cc2d..38194bdd05a 100644 --- a/seed/python-sdk/extends/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/extends/src/seed/core/client_wrapper.py @@ -30,10 +30,20 @@ def get_timeout(self) -> typing.Optional[float]: class SyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/extends/src/seed/core/http_client.py b/seed/python-sdk/extends/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/extends/src/seed/core/http_client.py +++ b/seed/python-sdk/extends/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/extra-properties/src/seed/core/client_wrapper.py b/seed/python-sdk/extra-properties/src/seed/core/client_wrapper.py index 8aa46ff95fe..c47c9897194 100644 --- a/seed/python-sdk/extra-properties/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/extra-properties/src/seed/core/client_wrapper.py @@ -30,10 +30,20 @@ def get_timeout(self) -> typing.Optional[float]: class SyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/extra-properties/src/seed/core/http_client.py b/seed/python-sdk/extra-properties/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/extra-properties/src/seed/core/http_client.py +++ b/seed/python-sdk/extra-properties/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/extra-properties/src/seed/user/client.py b/seed/python-sdk/extra-properties/src/seed/user/client.py index 66695fb63c6..94ac0a5fc60 100644 --- a/seed/python-sdk/extra-properties/src/seed/user/client.py +++ b/seed/python-sdk/extra-properties/src/seed/user/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from .types.user import User @@ -46,32 +42,11 @@ def create_user(self, *, name: str, request_options: typing.Optional[RequestOpti ) """ _response = self._client_wrapper.httpx_client.request( + "user", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "user"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"name": name, "_type": "CreateUserRequest", "_version": "v1"}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"name": name, "_type": "CreateUserRequest", "_version": "v1"}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"name": name, "_type": "CreateUserRequest", "_version": "v1"}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(User, _response.json()) # type: ignore @@ -111,32 +86,11 @@ async def create_user(self, *, name: str, request_options: typing.Optional[Reque ) """ _response = await self._client_wrapper.httpx_client.request( + "user", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "user"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"name": name, "_type": "CreateUserRequest", "_version": "v1"}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"name": name, "_type": "CreateUserRequest", "_version": "v1"}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"name": name, "_type": "CreateUserRequest", "_version": "v1"}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(User, _response.json()) # type: ignore diff --git a/seed/python-sdk/file-download/src/seed/core/client_wrapper.py b/seed/python-sdk/file-download/src/seed/core/client_wrapper.py index 8405c543cac..cee8e5684af 100644 --- a/seed/python-sdk/file-download/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/file-download/src/seed/core/client_wrapper.py @@ -30,10 +30,20 @@ def get_timeout(self) -> typing.Optional[float]: class SyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/file-download/src/seed/core/http_client.py b/seed/python-sdk/file-download/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/file-download/src/seed/core/http_client.py +++ b/seed/python-sdk/file-download/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/file-download/src/seed/service/client.py b/seed/python-sdk/file-download/src/seed/service/client.py index cba9c646736..54e7b9ec9b6 100644 --- a/seed/python-sdk/file-download/src/seed/service/client.py +++ b/seed/python-sdk/file-download/src/seed/service/client.py @@ -5,9 +5,6 @@ from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions @@ -35,31 +32,7 @@ def download_file(self, *, request_options: typing.Optional[RequestOptions] = No ) client.service.download_file() """ - with self._client_wrapper.httpx_client.stream( - method="POST", - url=self._client_wrapper.get_base_url(), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore - ) as _response: + with self._client_wrapper.httpx_client.stream(method="POST", request_options=request_options) as _response: if 200 <= _response.status_code < 300: for _chunk in _response.iter_bytes(): yield _chunk @@ -99,29 +72,7 @@ async def download_file( await client.service.download_file() """ async with self._client_wrapper.httpx_client.stream( - method="POST", - url=self._client_wrapper.get_base_url(), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + method="POST", request_options=request_options ) as _response: if 200 <= _response.status_code < 300: async for _chunk in _response.aiter_bytes(): diff --git a/seed/python-sdk/file-upload/src/seed/core/client_wrapper.py b/seed/python-sdk/file-upload/src/seed/core/client_wrapper.py index 4cfcda4821b..dfe35a2131d 100644 --- a/seed/python-sdk/file-upload/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/file-upload/src/seed/core/client_wrapper.py @@ -30,10 +30,20 @@ def get_timeout(self) -> typing.Optional[float]: class SyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/file-upload/src/seed/core/http_client.py b/seed/python-sdk/file-upload/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/file-upload/src/seed/core/http_client.py +++ b/seed/python-sdk/file-upload/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/file-upload/src/seed/service/client.py b/seed/python-sdk/file-upload/src/seed/service/client.py index e9c1f6ee69d..1bd8770a6a4 100644 --- a/seed/python-sdk/file-upload/src/seed/service/client.py +++ b/seed/python-sdk/file-upload/src/seed/service/client.py @@ -1,14 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from .. import core from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder -from ..core.query_encoder import encode_query from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from .types.my_object import MyObject @@ -33,7 +30,7 @@ def post( maybe_file_list: typing.Optional[typing.List[core.File]] = None, maybe_integer: typing.Optional[int] = None, optional_list_of_strings: typing.Optional[typing.List[str]] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -78,56 +75,22 @@ def post( """ _response = self._client_wrapper.httpx_client.request( method="POST", - url=self._client_wrapper.get_base_url(), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) + data=remove_none_from_dict( + { + "maybeString": maybe_string, + "integer": integer, + "maybeInteger": maybe_integer, + "optionalListOfStrings": optional_list_of_strings, + "listOfObjects": list_of_objects, + } ), - data=jsonable_encoder( - remove_none_from_dict( - { - "maybeString": maybe_string, - "integer": integer, - "maybeInteger": maybe_integer, - "optionalListOfStrings": optional_list_of_strings, - "listOfObjects": list_of_objects, - } - ) - ) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder( - remove_none_from_dict( - { - "maybeString": maybe_string, - "integer": integer, - "maybeInteger": maybe_integer, - "optionalListOfStrings": optional_list_of_strings, - "listOfObjects": list_of_objects, - } - ) - ), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, files=core.convert_file_dict_to_httpx_tuples( remove_none_from_dict( {"file": file, "fileList": file_list, "maybeFile": maybe_file, "maybeFileList": maybe_file_list} ) ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return @@ -161,33 +124,12 @@ def just_file(self, *, file: core.File, request_options: typing.Optional[Request client.service.just_file() """ _response = self._client_wrapper.httpx_client.request( + "just-file", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "just-file"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - data=jsonable_encoder(remove_none_from_dict({})) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(remove_none_from_dict({})), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, + data=remove_none_from_dict({}), files=core.convert_file_dict_to_httpx_tuples(remove_none_from_dict({"file": file})), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return @@ -206,7 +148,7 @@ def just_file_with_query_params( maybe_string: typing.Optional[str] = None, maybe_integer: typing.Optional[int] = None, optional_list_of_strings: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -247,46 +189,19 @@ def just_file_with_query_params( ) """ _response = self._client_wrapper.httpx_client.request( + "just-file-with-query-params", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "just-file-with-query-params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "maybeString": maybe_string, - "integer": integer, - "maybeInteger": maybe_integer, - "listOfStrings": list_of_strings, - "optionalListOfStrings": optional_list_of_strings, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - data=jsonable_encoder(remove_none_from_dict({})) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(remove_none_from_dict({})), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + params={ + "maybeString": maybe_string, + "integer": integer, + "maybeInteger": maybe_integer, + "listOfStrings": list_of_strings, + "optionalListOfStrings": optional_list_of_strings, }, + data=remove_none_from_dict({}), files=core.convert_file_dict_to_httpx_tuples(remove_none_from_dict({"file": file})), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return @@ -313,7 +228,7 @@ async def post( maybe_file_list: typing.Optional[typing.List[core.File]] = None, maybe_integer: typing.Optional[int] = None, optional_list_of_strings: typing.Optional[typing.List[str]] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -358,56 +273,22 @@ async def post( """ _response = await self._client_wrapper.httpx_client.request( method="POST", - url=self._client_wrapper.get_base_url(), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) + data=remove_none_from_dict( + { + "maybeString": maybe_string, + "integer": integer, + "maybeInteger": maybe_integer, + "optionalListOfStrings": optional_list_of_strings, + "listOfObjects": list_of_objects, + } ), - data=jsonable_encoder( - remove_none_from_dict( - { - "maybeString": maybe_string, - "integer": integer, - "maybeInteger": maybe_integer, - "optionalListOfStrings": optional_list_of_strings, - "listOfObjects": list_of_objects, - } - ) - ) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder( - remove_none_from_dict( - { - "maybeString": maybe_string, - "integer": integer, - "maybeInteger": maybe_integer, - "optionalListOfStrings": optional_list_of_strings, - "listOfObjects": list_of_objects, - } - ) - ), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, files=core.convert_file_dict_to_httpx_tuples( remove_none_from_dict( {"file": file, "fileList": file_list, "maybeFile": maybe_file, "maybeFileList": maybe_file_list} ) ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return @@ -441,33 +322,12 @@ async def just_file(self, *, file: core.File, request_options: typing.Optional[R await client.service.just_file() """ _response = await self._client_wrapper.httpx_client.request( + "just-file", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "just-file"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - data=jsonable_encoder(remove_none_from_dict({})) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(remove_none_from_dict({})), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, + data=remove_none_from_dict({}), files=core.convert_file_dict_to_httpx_tuples(remove_none_from_dict({"file": file})), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return @@ -486,7 +346,7 @@ async def just_file_with_query_params( maybe_string: typing.Optional[str] = None, maybe_integer: typing.Optional[int] = None, optional_list_of_strings: typing.Optional[typing.Union[str, typing.Sequence[str]]] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> None: """ Parameters @@ -527,46 +387,19 @@ async def just_file_with_query_params( ) """ _response = await self._client_wrapper.httpx_client.request( + "just-file-with-query-params", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "just-file-with-query-params"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "maybeString": maybe_string, - "integer": integer, - "maybeInteger": maybe_integer, - "listOfStrings": list_of_strings, - "optionalListOfStrings": optional_list_of_strings, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - data=jsonable_encoder(remove_none_from_dict({})) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(remove_none_from_dict({})), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + params={ + "maybeString": maybe_string, + "integer": integer, + "maybeInteger": maybe_integer, + "listOfStrings": list_of_strings, + "optionalListOfStrings": optional_list_of_strings, }, + data=remove_none_from_dict({}), files=core.convert_file_dict_to_httpx_tuples(remove_none_from_dict({"file": file})), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return diff --git a/seed/python-sdk/folders/src/seed/a/b/client.py b/seed/python-sdk/folders/src/seed/a/b/client.py index 689a3953fa2..36dce69ccad 100644 --- a/seed/python-sdk/folders/src/seed/a/b/client.py +++ b/seed/python-sdk/folders/src/seed/a/b/client.py @@ -5,9 +5,6 @@ from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions @@ -35,31 +32,7 @@ def foo(self, *, request_options: typing.Optional[RequestOptions] = None) -> Non ) client.a.b.foo() """ - _response = self._client_wrapper.httpx_client.request( - method="POST", - url=self._client_wrapper.get_base_url(), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore - ) + _response = self._client_wrapper.httpx_client.request(method="POST", request_options=request_options) if 200 <= _response.status_code < 300: return try: @@ -93,31 +66,7 @@ async def foo(self, *, request_options: typing.Optional[RequestOptions] = None) ) await client.a.b.foo() """ - _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=self._client_wrapper.get_base_url(), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore - ) + _response = await self._client_wrapper.httpx_client.request(method="POST", request_options=request_options) if 200 <= _response.status_code < 300: return try: diff --git a/seed/python-sdk/folders/src/seed/a/c/client.py b/seed/python-sdk/folders/src/seed/a/c/client.py index a0f46ab2d32..6f4e7e1c960 100644 --- a/seed/python-sdk/folders/src/seed/a/c/client.py +++ b/seed/python-sdk/folders/src/seed/a/c/client.py @@ -5,9 +5,6 @@ from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions @@ -35,31 +32,7 @@ def foo(self, *, request_options: typing.Optional[RequestOptions] = None) -> Non ) client.a.c.foo() """ - _response = self._client_wrapper.httpx_client.request( - method="POST", - url=self._client_wrapper.get_base_url(), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore - ) + _response = self._client_wrapper.httpx_client.request(method="POST", request_options=request_options) if 200 <= _response.status_code < 300: return try: @@ -93,31 +66,7 @@ async def foo(self, *, request_options: typing.Optional[RequestOptions] = None) ) await client.a.c.foo() """ - _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=self._client_wrapper.get_base_url(), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore - ) + _response = await self._client_wrapper.httpx_client.request(method="POST", request_options=request_options) if 200 <= _response.status_code < 300: return try: diff --git a/seed/python-sdk/folders/src/seed/client.py b/seed/python-sdk/folders/src/seed/client.py index 12014868da2..40785e32f0e 100644 --- a/seed/python-sdk/folders/src/seed/client.py +++ b/seed/python-sdk/folders/src/seed/client.py @@ -8,9 +8,6 @@ from .a.client import AClient, AsyncAClient from .core.api_error import ApiError from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from .core.jsonable_encoder import jsonable_encoder -from .core.query_encoder import encode_query -from .core.remove_none_from_dict import remove_none_from_dict from .core.request_options import RequestOptions from .folder.client import AsyncFolderClient, FolderClient @@ -83,31 +80,7 @@ def foo(self, *, request_options: typing.Optional[RequestOptions] = None) -> Non ) client.foo() """ - _response = self._client_wrapper.httpx_client.request( - method="POST", - url=self._client_wrapper.get_base_url(), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore - ) + _response = self._client_wrapper.httpx_client.request(method="POST", request_options=request_options) if 200 <= _response.status_code < 300: return try: @@ -185,31 +158,7 @@ async def foo(self, *, request_options: typing.Optional[RequestOptions] = None) ) await client.foo() """ - _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=self._client_wrapper.get_base_url(), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore - ) + _response = await self._client_wrapper.httpx_client.request(method="POST", request_options=request_options) if 200 <= _response.status_code < 300: return try: diff --git a/seed/python-sdk/folders/src/seed/core/client_wrapper.py b/seed/python-sdk/folders/src/seed/core/client_wrapper.py index a42de63097e..71f786114c6 100644 --- a/seed/python-sdk/folders/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/folders/src/seed/core/client_wrapper.py @@ -30,10 +30,20 @@ def get_timeout(self) -> typing.Optional[float]: class SyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/folders/src/seed/core/http_client.py b/seed/python-sdk/folders/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/folders/src/seed/core/http_client.py +++ b/seed/python-sdk/folders/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/folders/src/seed/folder/client.py b/seed/python-sdk/folders/src/seed/folder/client.py index 4ca461f1f5e..df6ab436bcb 100644 --- a/seed/python-sdk/folders/src/seed/folder/client.py +++ b/seed/python-sdk/folders/src/seed/folder/client.py @@ -5,9 +5,6 @@ from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from .service.client import AsyncServiceClient, ServiceClient @@ -37,31 +34,7 @@ def foo(self, *, request_options: typing.Optional[RequestOptions] = None) -> Non ) client.folder.foo() """ - _response = self._client_wrapper.httpx_client.request( - method="POST", - url=self._client_wrapper.get_base_url(), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore - ) + _response = self._client_wrapper.httpx_client.request(method="POST", request_options=request_options) if 200 <= _response.status_code < 300: return try: @@ -96,31 +69,7 @@ async def foo(self, *, request_options: typing.Optional[RequestOptions] = None) ) await client.folder.foo() """ - _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=self._client_wrapper.get_base_url(), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore - ) + _response = await self._client_wrapper.httpx_client.request(method="POST", request_options=request_options) if 200 <= _response.status_code < 300: return try: diff --git a/seed/python-sdk/folders/src/seed/folder/service/client.py b/seed/python-sdk/folders/src/seed/folder/service/client.py index 29b98eb7b41..be83b5d3f21 100644 --- a/seed/python-sdk/folders/src/seed/folder/service/client.py +++ b/seed/python-sdk/folders/src/seed/folder/service/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ...core.api_error import ApiError from ...core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ...core.jsonable_encoder import jsonable_encoder from ...core.pydantic_utilities import pydantic_v1 -from ...core.query_encoder import encode_query -from ...core.remove_none_from_dict import remove_none_from_dict from ...core.request_options import RequestOptions from .errors.not_found_error import NotFoundError @@ -41,28 +37,7 @@ def endpoint(self, *, request_options: typing.Optional[RequestOptions] = None) - ) client.folder.service.endpoint() """ - _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "service"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore - ) + _response = self._client_wrapper.httpx_client.request("service", method="GET", request_options=request_options) if 200 <= _response.status_code < 300: return try: @@ -96,32 +71,7 @@ def unknown_request(self, *, request: typing.Any, request_options: typing.Option ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "service"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "service", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return @@ -159,26 +109,7 @@ async def endpoint(self, *, request_options: typing.Optional[RequestOptions] = N await client.folder.service.endpoint() """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "service"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "service", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -215,32 +146,7 @@ async def unknown_request( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "service"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "service", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return diff --git a/seed/python-sdk/idempotency-headers/src/seed/core/client_wrapper.py b/seed/python-sdk/idempotency-headers/src/seed/core/client_wrapper.py index 454bff23411..918a9e30a0f 100644 --- a/seed/python-sdk/idempotency-headers/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/idempotency-headers/src/seed/core/client_wrapper.py @@ -51,7 +51,12 @@ def __init__( httpx_client: httpx.Client, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): @@ -64,4 +69,9 @@ def __init__( httpx_client: httpx.AsyncClient, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/idempotency-headers/src/seed/core/http_client.py b/seed/python-sdk/idempotency-headers/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/idempotency-headers/src/seed/core/http_client.py +++ b/seed/python-sdk/idempotency-headers/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/idempotency-headers/src/seed/payment/client.py b/seed/python-sdk/idempotency-headers/src/seed/payment/client.py index 95d0d8adb8d..1707a9ee618 100644 --- a/seed/python-sdk/idempotency-headers/src/seed/payment/client.py +++ b/seed/python-sdk/idempotency-headers/src/seed/payment/client.py @@ -1,7 +1,6 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError @@ -9,8 +8,6 @@ from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from .types.currency import Currency @@ -63,36 +60,15 @@ def create( ) """ _response = self._client_wrapper.httpx_client.request( + "payment", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "payment"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"amount": amount, "currency": currency}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"amount": amount, "currency": currency}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={"amount": amount, "currency": currency}, + headers={ + "Idempotency-Key": str(idempotency_key) if idempotency_key is not None else None, + "Idempotency-Expiration": str(idempotency_expiration) if idempotency_expiration is not None else None, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "Idempotency-Key": str(idempotency_key) if idempotency_key is not None else None, - "Idempotency-Expiration": str(idempotency_expiration) - if idempotency_expiration is not None - else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(uuid.UUID, _response.json()) # type: ignore @@ -128,31 +104,7 @@ def delete(self, payment_id: str, *, request_options: typing.Optional[RequestOpt ) """ _response = self._client_wrapper.httpx_client.request( - method="DELETE", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"payment/{jsonable_encoder(payment_id)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"payment/{jsonable_encoder(payment_id)}", method="DELETE", request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -208,36 +160,15 @@ async def create( ) """ _response = await self._client_wrapper.httpx_client.request( + "payment", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "payment"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"amount": amount, "currency": currency}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"amount": amount, "currency": currency}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={"amount": amount, "currency": currency}, + headers={ + "Idempotency-Key": str(idempotency_key) if idempotency_key is not None else None, + "Idempotency-Expiration": str(idempotency_expiration) if idempotency_expiration is not None else None, }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "Idempotency-Key": str(idempotency_key) if idempotency_key is not None else None, - "Idempotency-Expiration": str(idempotency_expiration) - if idempotency_expiration is not None - else None, - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(uuid.UUID, _response.json()) # type: ignore @@ -273,31 +204,7 @@ async def delete(self, payment_id: str, *, request_options: typing.Optional[Requ ) """ _response = await self._client_wrapper.httpx_client.request( - method="DELETE", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"payment/{jsonable_encoder(payment_id)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"payment/{jsonable_encoder(payment_id)}", method="DELETE", request_options=request_options ) if 200 <= _response.status_code < 300: return diff --git a/seed/python-sdk/imdb/src/seed/core/client_wrapper.py b/seed/python-sdk/imdb/src/seed/core/client_wrapper.py index d20995227aa..97c8b5064a8 100644 --- a/seed/python-sdk/imdb/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/imdb/src/seed/core/client_wrapper.py @@ -53,7 +53,12 @@ def __init__( httpx_client: httpx.Client, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): @@ -66,4 +71,9 @@ def __init__( httpx_client: httpx.AsyncClient, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/imdb/src/seed/core/http_client.py b/seed/python-sdk/imdb/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/imdb/src/seed/core/http_client.py +++ b/seed/python-sdk/imdb/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/imdb/src/seed/imdb/client.py b/seed/python-sdk/imdb/src/seed/imdb/client.py index 7ed1976bc23..59481e280b0 100644 --- a/seed/python-sdk/imdb/src/seed/imdb/client.py +++ b/seed/python-sdk/imdb/src/seed/imdb/client.py @@ -1,15 +1,12 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from .errors.movie_does_not_exist_error import MovieDoesNotExistError from .types.movie import Movie @@ -55,34 +52,12 @@ def create_movie( rating=1.1, ) """ - _request: typing.Dict[str, typing.Any] = {"title": title, "rating": rating} _response = self._client_wrapper.httpx_client.request( + "movies/create-movie", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "movies/create-movie"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"title": title, "rating": rating}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(MovieId, _response.json()) # type: ignore @@ -118,26 +93,7 @@ def get_movie(self, movie_id: MovieId, *, request_options: typing.Optional[Reque ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"movies/{jsonable_encoder(movie_id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"movies/{jsonable_encoder(movie_id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Movie, _response.json()) # type: ignore @@ -186,34 +142,12 @@ async def create_movie( rating=1.1, ) """ - _request: typing.Dict[str, typing.Any] = {"title": title, "rating": rating} _response = await self._client_wrapper.httpx_client.request( + "movies/create-movie", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "movies/create-movie"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"title": title, "rating": rating}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(MovieId, _response.json()) # type: ignore @@ -249,26 +183,7 @@ async def get_movie(self, movie_id: MovieId, *, request_options: typing.Optional ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"movies/{jsonable_encoder(movie_id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"movies/{jsonable_encoder(movie_id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Movie, _response.json()) # type: ignore diff --git a/seed/python-sdk/literal/src/seed/core/client_wrapper.py b/seed/python-sdk/literal/src/seed/core/client_wrapper.py index 5db15514d7d..296afedfe49 100644 --- a/seed/python-sdk/literal/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/literal/src/seed/core/client_wrapper.py @@ -32,10 +32,20 @@ def get_timeout(self) -> typing.Optional[float]: class SyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/literal/src/seed/core/http_client.py b/seed/python-sdk/literal/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/literal/src/seed/core/http_client.py +++ b/seed/python-sdk/literal/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/literal/src/seed/headers/client.py b/seed/python-sdk/literal/src/seed/headers/client.py index 1605541999a..173a9b1d79e 100644 --- a/seed/python-sdk/literal/src/seed/headers/client.py +++ b/seed/python-sdk/literal/src/seed/headers/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..types.send_response import SendResponse @@ -46,34 +42,12 @@ def send(self, *, query: str, request_options: typing.Optional[RequestOptions] = ) """ _response = self._client_wrapper.httpx_client.request( + "headers", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "headers"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"query": query}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"query": query}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-Endpoint-Version": "02-12-2024", - "X-Async": "true", - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"query": query}, + headers={"X-Endpoint-Version": "02-12-2024", "X-Async": "true"}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(SendResponse, _response.json()) # type: ignore @@ -113,34 +87,12 @@ async def send(self, *, query: str, request_options: typing.Optional[RequestOpti ) """ _response = await self._client_wrapper.httpx_client.request( + "headers", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "headers"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"query": query}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"query": query}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - "X-Endpoint-Version": "02-12-2024", - "X-Async": "true", - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"query": query}, + headers={"X-Endpoint-Version": "02-12-2024", "X-Async": "true"}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(SendResponse, _response.json()) # type: ignore diff --git a/seed/python-sdk/literal/src/seed/inlined/client.py b/seed/python-sdk/literal/src/seed/inlined/client.py index e0f903a2d1d..ed5d04bd105 100644 --- a/seed/python-sdk/literal/src/seed/inlined/client.py +++ b/seed/python-sdk/literal/src/seed/inlined/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..types.send_response import SendResponse @@ -26,7 +22,7 @@ def send( *, query: str, temperature: typing.Optional[float] = OMIT, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> SendResponse: """ Parameters @@ -54,40 +50,12 @@ def send( query="What is the weather today", ) """ - _request: typing.Dict[str, typing.Any] = { - "query": query, - "prompt": "You are a helpful assistant", - "stream": False, - } - if temperature is not OMIT: - _request["temperature"] = temperature _response = self._client_wrapper.httpx_client.request( + "inlined", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "inlined"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"query": query, "temperature": temperature, "prompt": "You are a helpful assistant", "stream": False}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(SendResponse, _response.json()) # type: ignore @@ -107,7 +75,7 @@ async def send( *, query: str, temperature: typing.Optional[float] = OMIT, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> SendResponse: """ Parameters @@ -135,40 +103,12 @@ async def send( query="What is the weather today", ) """ - _request: typing.Dict[str, typing.Any] = { - "query": query, - "prompt": "You are a helpful assistant", - "stream": False, - } - if temperature is not OMIT: - _request["temperature"] = temperature _response = await self._client_wrapper.httpx_client.request( + "inlined", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "inlined"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"query": query, "temperature": temperature, "prompt": "You are a helpful assistant", "stream": False}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(SendResponse, _response.json()) # type: ignore diff --git a/seed/python-sdk/literal/src/seed/path/client.py b/seed/python-sdk/literal/src/seed/path/client.py index 09f6f721e05..60a68182243 100644 --- a/seed/python-sdk/literal/src/seed/path/client.py +++ b/seed/python-sdk/literal/src/seed/path/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..types.send_response import SendResponse @@ -39,29 +35,7 @@ def send(self, *, request_options: typing.Optional[RequestOptions] = None) -> Se client.path.send() """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"path/123"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"path/123", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(SendResponse, _response.json()) # type: ignore @@ -97,29 +71,7 @@ async def send(self, *, request_options: typing.Optional[RequestOptions] = None) await client.path.send() """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"path/123"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"path/123", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(SendResponse, _response.json()) # type: ignore diff --git a/seed/python-sdk/literal/src/seed/query/client.py b/seed/python-sdk/literal/src/seed/query/client.py index d840ff1fd2f..7b86e6a9e64 100644 --- a/seed/python-sdk/literal/src/seed/query/client.py +++ b/seed/python-sdk/literal/src/seed/query/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..types.send_response import SendResponse @@ -43,40 +39,10 @@ def send(self, *, query: str, request_options: typing.Optional[RequestOptions] = ) """ _response = self._client_wrapper.httpx_client.request( + "query", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "query"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "prompt": "You are a helpful assistant", - "query": query, - "stream": False, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"prompt": "You are a helpful assistant", "query": query, "stream": False}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(SendResponse, _response.json()) # type: ignore @@ -116,40 +82,10 @@ async def send(self, *, query: str, request_options: typing.Optional[RequestOpti ) """ _response = await self._client_wrapper.httpx_client.request( + "query", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "query"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "prompt": "You are a helpful assistant", - "query": query, - "stream": False, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"prompt": "You are a helpful assistant", "query": query, "stream": False}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(SendResponse, _response.json()) # type: ignore diff --git a/seed/python-sdk/literal/src/seed/reference/client.py b/seed/python-sdk/literal/src/seed/reference/client.py index 24265ba808c..c0b34a33175 100644 --- a/seed/python-sdk/literal/src/seed/reference/client.py +++ b/seed/python-sdk/literal/src/seed/reference/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..types.send_response import SendResponse @@ -47,38 +43,12 @@ def send(self, *, query: str, request_options: typing.Optional[RequestOptions] = query="What is the weather today", ) """ - _request: typing.Dict[str, typing.Any] = { - "query": query, - "prompt": "You are a helpful assistant", - "stream": False, - } _response = self._client_wrapper.httpx_client.request( + "reference", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "reference"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"query": query, "prompt": "You are a helpful assistant", "stream": False}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(SendResponse, _response.json()) # type: ignore @@ -119,38 +89,12 @@ async def send(self, *, query: str, request_options: typing.Optional[RequestOpti query="What is the weather today", ) """ - _request: typing.Dict[str, typing.Any] = { - "query": query, - "prompt": "You are a helpful assistant", - "stream": False, - } _response = await self._client_wrapper.httpx_client.request( + "reference", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "reference"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"query": query, "prompt": "You are a helpful assistant", "stream": False}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(SendResponse, _response.json()) # type: ignore diff --git a/seed/python-sdk/mixed-case/src/seed/core/client_wrapper.py b/seed/python-sdk/mixed-case/src/seed/core/client_wrapper.py index 0fb560027c7..d8fe9ab628a 100644 --- a/seed/python-sdk/mixed-case/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/mixed-case/src/seed/core/client_wrapper.py @@ -30,10 +30,20 @@ def get_timeout(self) -> typing.Optional[float]: class SyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/mixed-case/src/seed/core/http_client.py b/seed/python-sdk/mixed-case/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/mixed-case/src/seed/core/http_client.py +++ b/seed/python-sdk/mixed-case/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/mixed-case/src/seed/service/client.py b/seed/python-sdk/mixed-case/src/seed/service/client.py index 6442eed2068..1a813da1199 100644 --- a/seed/python-sdk/mixed-case/src/seed/service/client.py +++ b/seed/python-sdk/mixed-case/src/seed/service/client.py @@ -2,15 +2,12 @@ import datetime as dt import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from .types.resource import Resource @@ -44,28 +41,7 @@ def get_resource(self, resource_id: str, *, request_options: typing.Optional[Req ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"resource/{jsonable_encoder(resource_id)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"resource/{jsonable_encoder(resource_id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Resource, _response.json()) # type: ignore @@ -109,36 +85,10 @@ def list_resources( ) """ _response = self._client_wrapper.httpx_client.request( + "resource", method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "resource"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "page_limit": page_limit, - "beforeDate": str(before_date), - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"page_limit": page_limit, "beforeDate": str(before_date)}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[Resource], _response.json()) # type: ignore @@ -180,28 +130,7 @@ async def get_resource( ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"resource/{jsonable_encoder(resource_id)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"resource/{jsonable_encoder(resource_id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Resource, _response.json()) # type: ignore @@ -245,36 +174,10 @@ async def list_resources( ) """ _response = await self._client_wrapper.httpx_client.request( + "resource", method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "resource"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "page_limit": page_limit, - "beforeDate": str(before_date), - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"page_limit": page_limit, "beforeDate": str(before_date)}, + request_options=request_options, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[Resource], _response.json()) # type: ignore diff --git a/seed/python-sdk/multi-line-docs/src/seed/core/client_wrapper.py b/seed/python-sdk/multi-line-docs/src/seed/core/client_wrapper.py index 5e163362060..ed66db48b7f 100644 --- a/seed/python-sdk/multi-line-docs/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/multi-line-docs/src/seed/core/client_wrapper.py @@ -30,10 +30,20 @@ def get_timeout(self) -> typing.Optional[float]: class SyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/multi-line-docs/src/seed/core/http_client.py b/seed/python-sdk/multi-line-docs/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/multi-line-docs/src/seed/core/http_client.py +++ b/seed/python-sdk/multi-line-docs/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/multi-line-docs/src/seed/user/client.py b/seed/python-sdk/multi-line-docs/src/seed/user/client.py index e0a1ce58f47..08d04e531e7 100644 --- a/seed/python-sdk/multi-line-docs/src/seed/user/client.py +++ b/seed/python-sdk/multi-line-docs/src/seed/user/client.py @@ -1,15 +1,12 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from .types.user import User @@ -51,26 +48,7 @@ def get_user(self, user_id: str, *, request_options: typing.Optional[RequestOpti ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"users/{jsonable_encoder(user_id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"users/{jsonable_encoder(user_id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -118,36 +96,8 @@ def create_user( age=1, ) """ - _request: typing.Dict[str, typing.Any] = {"name": name} - if age is not OMIT: - _request["age"] = age _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "users"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "users", method="POST", json={"name": name, "age": age}, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(User, _response.json()) # type: ignore @@ -192,26 +142,7 @@ async def get_user(self, user_id: str, *, request_options: typing.Optional[Reque ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"users/{jsonable_encoder(user_id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"users/{jsonable_encoder(user_id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -259,36 +190,8 @@ async def create_user( age=1, ) """ - _request: typing.Dict[str, typing.Any] = {"name": name} - if age is not OMIT: - _request["age"] = age _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "users"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "users", method="POST", json={"name": name, "age": age}, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(User, _response.json()) # type: ignore diff --git a/seed/python-sdk/multi-url-environment/src/seed/core/client_wrapper.py b/seed/python-sdk/multi-url-environment/src/seed/core/client_wrapper.py index 58f1beb09c3..5668f943302 100644 --- a/seed/python-sdk/multi-url-environment/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/multi-url-environment/src/seed/core/client_wrapper.py @@ -52,7 +52,9 @@ def __init__( httpx_client: httpx.Client, ): super().__init__(token=token, environment=environment, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, base_headers=self.get_headers(), base_timeout=self.get_timeout() + ) class AsyncClientWrapper(BaseClientWrapper): @@ -65,4 +67,6 @@ def __init__( httpx_client: httpx.AsyncClient, ): super().__init__(token=token, environment=environment, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, base_headers=self.get_headers(), base_timeout=self.get_timeout() + ) diff --git a/seed/python-sdk/multi-url-environment/src/seed/core/http_client.py b/seed/python-sdk/multi-url-environment/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/multi-url-environment/src/seed/core/http_client.py +++ b/seed/python-sdk/multi-url-environment/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/multi-url-environment/src/seed/ec_2/client.py b/seed/python-sdk/multi-url-environment/src/seed/ec_2/client.py index 1c84739dbee..e14d54d2ea3 100644 --- a/seed/python-sdk/multi-url-environment/src/seed/ec_2/client.py +++ b/seed/python-sdk/multi-url-environment/src/seed/ec_2/client.py @@ -1,14 +1,10 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -44,32 +40,12 @@ def boot_instance(self, *, size: str, request_options: typing.Optional[RequestOp ) """ _response = self._client_wrapper.httpx_client.request( + "ec2/boot", + base_url=self._client_wrapper.get_environment().ec_2, method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_environment().ec_2}/", "ec2/boot"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"size": size}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"size": size}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"size": size}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return @@ -109,32 +85,12 @@ async def boot_instance(self, *, size: str, request_options: typing.Optional[Req ) """ _response = await self._client_wrapper.httpx_client.request( + "ec2/boot", + base_url=self._client_wrapper.get_environment().ec_2, method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_environment().ec_2}/", "ec2/boot"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"size": size}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"size": size}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"size": size}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return diff --git a/seed/python-sdk/multi-url-environment/src/seed/s_3/client.py b/seed/python-sdk/multi-url-environment/src/seed/s_3/client.py index 10d34cf45ca..1655564e116 100644 --- a/seed/python-sdk/multi-url-environment/src/seed/s_3/client.py +++ b/seed/python-sdk/multi-url-environment/src/seed/s_3/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -45,32 +41,12 @@ def get_presigned_url(self, *, s_3_key: str, request_options: typing.Optional[Re ) """ _response = self._client_wrapper.httpx_client.request( + "s3/presigned-url", + base_url=self._client_wrapper.get_environment().s_3, method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_environment().s_3}/", "s3/presigned-url"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"s3Key": s_3_key}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"s3Key": s_3_key}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"s3Key": s_3_key}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -110,32 +86,12 @@ async def get_presigned_url(self, *, s_3_key: str, request_options: typing.Optio ) """ _response = await self._client_wrapper.httpx_client.request( + "s3/presigned-url", + base_url=self._client_wrapper.get_environment().s_3, method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_environment().s_3}/", "s3/presigned-url"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"s3Key": s_3_key}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"s3Key": s_3_key}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"s3Key": s_3_key}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/no-environment/src/seed/core/client_wrapper.py b/seed/python-sdk/no-environment/src/seed/core/client_wrapper.py index 887caa82d77..1c4f8de0630 100644 --- a/seed/python-sdk/no-environment/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/no-environment/src/seed/core/client_wrapper.py @@ -51,7 +51,12 @@ def __init__( httpx_client: httpx.Client, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): @@ -64,4 +69,9 @@ def __init__( httpx_client: httpx.AsyncClient, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/no-environment/src/seed/core/http_client.py b/seed/python-sdk/no-environment/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/no-environment/src/seed/core/http_client.py +++ b/seed/python-sdk/no-environment/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/no-environment/src/seed/dummy/client.py b/seed/python-sdk/no-environment/src/seed/dummy/client.py index 26c54f975ff..44ba67f20f7 100644 --- a/seed/python-sdk/no-environment/src/seed/dummy/client.py +++ b/seed/python-sdk/no-environment/src/seed/dummy/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions @@ -38,28 +34,7 @@ def get_dummy(self, *, request_options: typing.Optional[RequestOptions] = None) ) client.dummy.get_dummy() """ - _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "dummy"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore - ) + _response = self._client_wrapper.httpx_client.request("dummy", method="GET", request_options=request_options) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore try: @@ -95,26 +70,7 @@ async def get_dummy(self, *, request_options: typing.Optional[RequestOptions] = await client.dummy.get_dummy() """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "dummy"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "dummy", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/oauth-client-credentials-default/src/seed/auth/client.py b/seed/python-sdk/oauth-client-credentials-default/src/seed/auth/client.py index 9cad3254b00..00abe00bb54 100644 --- a/seed/python-sdk/oauth-client-credentials-default/src/seed/auth/client.py +++ b/seed/python-sdk/oauth-client-credentials-default/src/seed/auth/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from .types.token_response import TokenResponse @@ -53,36 +49,11 @@ def get_token( ) """ _response = self._client_wrapper.httpx_client.request( + "token", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "token"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder( - {"client_id": client_id, "client_secret": client_secret, "grant_type": "client_credentials"} - ) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder( - {"client_id": client_id, "client_secret": client_secret, "grant_type": "client_credentials"} - ), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"client_id": client_id, "client_secret": client_secret, "grant_type": "client_credentials"}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(TokenResponse, _response.json()) # type: ignore @@ -129,36 +100,11 @@ async def get_token( ) """ _response = await self._client_wrapper.httpx_client.request( + "token", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "token"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder( - {"client_id": client_id, "client_secret": client_secret, "grant_type": "client_credentials"} - ) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder( - {"client_id": client_id, "client_secret": client_secret, "grant_type": "client_credentials"} - ), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"client_id": client_id, "client_secret": client_secret, "grant_type": "client_credentials"}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(TokenResponse, _response.json()) # type: ignore diff --git a/seed/python-sdk/oauth-client-credentials-default/src/seed/core/client_wrapper.py b/seed/python-sdk/oauth-client-credentials-default/src/seed/core/client_wrapper.py index abaefdd0ba7..aa6ef36d7b7 100644 --- a/seed/python-sdk/oauth-client-credentials-default/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/oauth-client-credentials-default/src/seed/core/client_wrapper.py @@ -53,7 +53,12 @@ def __init__( httpx_client: httpx.Client, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): @@ -66,4 +71,9 @@ def __init__( httpx_client: httpx.AsyncClient, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/oauth-client-credentials-default/src/seed/core/http_client.py b/seed/python-sdk/oauth-client-credentials-default/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/oauth-client-credentials-default/src/seed/core/http_client.py +++ b/seed/python-sdk/oauth-client-credentials-default/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/oauth-client-credentials-environment-variables/src/seed/auth/client.py b/seed/python-sdk/oauth-client-credentials-environment-variables/src/seed/auth/client.py index c039165f3d3..7fa4dea06ea 100644 --- a/seed/python-sdk/oauth-client-credentials-environment-variables/src/seed/auth/client.py +++ b/seed/python-sdk/oauth-client-credentials-environment-variables/src/seed/auth/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from .types.token_response import TokenResponse @@ -27,7 +23,7 @@ def get_token_with_client_credentials( client_id: str, client_secret: str, scope: typing.Optional[str] = OMIT, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> TokenResponse: """ Parameters @@ -58,41 +54,18 @@ def get_token_with_client_credentials( scope="string", ) """ - _request: typing.Dict[str, typing.Any] = { - "client_id": client_id, - "client_secret": client_secret, - "audience": "https://api.example.com", - "grant_type": "client_credentials", - } - if scope is not OMIT: - _request["scope"] = scope _response = self._client_wrapper.httpx_client.request( + "token", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "token"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "client_id": client_id, + "client_secret": client_secret, + "scope": scope, + "audience": "https://api.example.com", + "grant_type": "client_credentials", }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(TokenResponse, _response.json()) # type: ignore @@ -109,7 +82,7 @@ def refresh_token( client_secret: str, refresh_token: str, scope: typing.Optional[str] = OMIT, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> TokenResponse: """ Parameters @@ -143,42 +116,19 @@ def refresh_token( scope="string", ) """ - _request: typing.Dict[str, typing.Any] = { - "client_id": client_id, - "client_secret": client_secret, - "refresh_token": refresh_token, - "audience": "https://api.example.com", - "grant_type": "refresh_token", - } - if scope is not OMIT: - _request["scope"] = scope _response = self._client_wrapper.httpx_client.request( + "token", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "token"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "client_id": client_id, + "client_secret": client_secret, + "refresh_token": refresh_token, + "scope": scope, + "audience": "https://api.example.com", + "grant_type": "refresh_token", }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(TokenResponse, _response.json()) # type: ignore @@ -199,7 +149,7 @@ async def get_token_with_client_credentials( client_id: str, client_secret: str, scope: typing.Optional[str] = OMIT, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> TokenResponse: """ Parameters @@ -230,41 +180,18 @@ async def get_token_with_client_credentials( scope="string", ) """ - _request: typing.Dict[str, typing.Any] = { - "client_id": client_id, - "client_secret": client_secret, - "audience": "https://api.example.com", - "grant_type": "client_credentials", - } - if scope is not OMIT: - _request["scope"] = scope _response = await self._client_wrapper.httpx_client.request( + "token", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "token"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "client_id": client_id, + "client_secret": client_secret, + "scope": scope, + "audience": "https://api.example.com", + "grant_type": "client_credentials", }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(TokenResponse, _response.json()) # type: ignore @@ -281,7 +208,7 @@ async def refresh_token( client_secret: str, refresh_token: str, scope: typing.Optional[str] = OMIT, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> TokenResponse: """ Parameters @@ -315,42 +242,19 @@ async def refresh_token( scope="string", ) """ - _request: typing.Dict[str, typing.Any] = { - "client_id": client_id, - "client_secret": client_secret, - "refresh_token": refresh_token, - "audience": "https://api.example.com", - "grant_type": "refresh_token", - } - if scope is not OMIT: - _request["scope"] = scope _response = await self._client_wrapper.httpx_client.request( + "token", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "token"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "client_id": client_id, + "client_secret": client_secret, + "refresh_token": refresh_token, + "scope": scope, + "audience": "https://api.example.com", + "grant_type": "refresh_token", }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(TokenResponse, _response.json()) # type: ignore diff --git a/seed/python-sdk/oauth-client-credentials-environment-variables/src/seed/core/client_wrapper.py b/seed/python-sdk/oauth-client-credentials-environment-variables/src/seed/core/client_wrapper.py index dfcbb10be8a..22713e57f78 100644 --- a/seed/python-sdk/oauth-client-credentials-environment-variables/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/oauth-client-credentials-environment-variables/src/seed/core/client_wrapper.py @@ -53,7 +53,12 @@ def __init__( httpx_client: httpx.Client, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): @@ -66,4 +71,9 @@ def __init__( httpx_client: httpx.AsyncClient, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/oauth-client-credentials-environment-variables/src/seed/core/http_client.py b/seed/python-sdk/oauth-client-credentials-environment-variables/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/oauth-client-credentials-environment-variables/src/seed/core/http_client.py +++ b/seed/python-sdk/oauth-client-credentials-environment-variables/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/oauth-client-credentials-nested-root/src/seed/auth/client.py b/seed/python-sdk/oauth-client-credentials-nested-root/src/seed/auth/client.py index 615a3f55a7a..46771ac39d7 100644 --- a/seed/python-sdk/oauth-client-credentials-nested-root/src/seed/auth/client.py +++ b/seed/python-sdk/oauth-client-credentials-nested-root/src/seed/auth/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from .types.token_response import TokenResponse @@ -27,7 +23,7 @@ def get_token( client_id: str, client_secret: str, scope: typing.Optional[str] = OMIT, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> TokenResponse: """ Parameters @@ -60,41 +56,18 @@ def get_token( scope="string", ) """ - _request: typing.Dict[str, typing.Any] = { - "client_id": client_id, - "client_secret": client_secret, - "audience": "https://api.example.com", - "grant_type": "client_credentials", - } - if scope is not OMIT: - _request["scope"] = scope _response = self._client_wrapper.httpx_client.request( + "token", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "token"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "client_id": client_id, + "client_secret": client_secret, + "scope": scope, + "audience": "https://api.example.com", + "grant_type": "client_credentials", }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(TokenResponse, _response.json()) # type: ignore @@ -115,7 +88,7 @@ async def get_token( client_id: str, client_secret: str, scope: typing.Optional[str] = OMIT, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> TokenResponse: """ Parameters @@ -148,41 +121,18 @@ async def get_token( scope="string", ) """ - _request: typing.Dict[str, typing.Any] = { - "client_id": client_id, - "client_secret": client_secret, - "audience": "https://api.example.com", - "grant_type": "client_credentials", - } - if scope is not OMIT: - _request["scope"] = scope _response = await self._client_wrapper.httpx_client.request( + "token", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "token"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "client_id": client_id, + "client_secret": client_secret, + "scope": scope, + "audience": "https://api.example.com", + "grant_type": "client_credentials", }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(TokenResponse, _response.json()) # type: ignore diff --git a/seed/python-sdk/oauth-client-credentials-nested-root/src/seed/core/client_wrapper.py b/seed/python-sdk/oauth-client-credentials-nested-root/src/seed/core/client_wrapper.py index 81c5599226c..d3190064d99 100644 --- a/seed/python-sdk/oauth-client-credentials-nested-root/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/oauth-client-credentials-nested-root/src/seed/core/client_wrapper.py @@ -53,7 +53,12 @@ def __init__( httpx_client: httpx.Client, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): @@ -66,4 +71,9 @@ def __init__( httpx_client: httpx.AsyncClient, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/oauth-client-credentials-nested-root/src/seed/core/http_client.py b/seed/python-sdk/oauth-client-credentials-nested-root/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/oauth-client-credentials-nested-root/src/seed/core/http_client.py +++ b/seed/python-sdk/oauth-client-credentials-nested-root/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/oauth-client-credentials/src/seed/auth/client.py b/seed/python-sdk/oauth-client-credentials/src/seed/auth/client.py index a55508b33f1..7fc9d0c8225 100644 --- a/seed/python-sdk/oauth-client-credentials/src/seed/auth/client.py +++ b/seed/python-sdk/oauth-client-credentials/src/seed/auth/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from .types.token_response import TokenResponse @@ -27,7 +23,7 @@ def get_token_with_client_credentials( client_id: str, client_secret: str, scope: typing.Optional[str] = OMIT, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> TokenResponse: """ Parameters @@ -60,41 +56,18 @@ def get_token_with_client_credentials( scope="string", ) """ - _request: typing.Dict[str, typing.Any] = { - "client_id": client_id, - "client_secret": client_secret, - "audience": "https://api.example.com", - "grant_type": "client_credentials", - } - if scope is not OMIT: - _request["scope"] = scope _response = self._client_wrapper.httpx_client.request( + "token", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "token"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "client_id": client_id, + "client_secret": client_secret, + "scope": scope, + "audience": "https://api.example.com", + "grant_type": "client_credentials", }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(TokenResponse, _response.json()) # type: ignore @@ -111,7 +84,7 @@ def refresh_token( client_secret: str, refresh_token: str, scope: typing.Optional[str] = OMIT, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> TokenResponse: """ Parameters @@ -147,42 +120,19 @@ def refresh_token( scope="string", ) """ - _request: typing.Dict[str, typing.Any] = { - "client_id": client_id, - "client_secret": client_secret, - "refresh_token": refresh_token, - "audience": "https://api.example.com", - "grant_type": "refresh_token", - } - if scope is not OMIT: - _request["scope"] = scope _response = self._client_wrapper.httpx_client.request( + "token", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "token"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "client_id": client_id, + "client_secret": client_secret, + "refresh_token": refresh_token, + "scope": scope, + "audience": "https://api.example.com", + "grant_type": "refresh_token", }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(TokenResponse, _response.json()) # type: ignore @@ -203,7 +153,7 @@ async def get_token_with_client_credentials( client_id: str, client_secret: str, scope: typing.Optional[str] = OMIT, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> TokenResponse: """ Parameters @@ -236,41 +186,18 @@ async def get_token_with_client_credentials( scope="string", ) """ - _request: typing.Dict[str, typing.Any] = { - "client_id": client_id, - "client_secret": client_secret, - "audience": "https://api.example.com", - "grant_type": "client_credentials", - } - if scope is not OMIT: - _request["scope"] = scope _response = await self._client_wrapper.httpx_client.request( + "token", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "token"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "client_id": client_id, + "client_secret": client_secret, + "scope": scope, + "audience": "https://api.example.com", + "grant_type": "client_credentials", }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(TokenResponse, _response.json()) # type: ignore @@ -287,7 +214,7 @@ async def refresh_token( client_secret: str, refresh_token: str, scope: typing.Optional[str] = OMIT, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> TokenResponse: """ Parameters @@ -323,42 +250,19 @@ async def refresh_token( scope="string", ) """ - _request: typing.Dict[str, typing.Any] = { - "client_id": client_id, - "client_secret": client_secret, - "refresh_token": refresh_token, - "audience": "https://api.example.com", - "grant_type": "refresh_token", - } - if scope is not OMIT: - _request["scope"] = scope _response = await self._client_wrapper.httpx_client.request( + "token", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "token"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(_request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(_request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), + json={ + "client_id": client_id, + "client_secret": client_secret, + "refresh_token": refresh_token, + "scope": scope, + "audience": "https://api.example.com", + "grant_type": "refresh_token", }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(TokenResponse, _response.json()) # type: ignore diff --git a/seed/python-sdk/oauth-client-credentials/src/seed/core/client_wrapper.py b/seed/python-sdk/oauth-client-credentials/src/seed/core/client_wrapper.py index cc742325655..611565d5835 100644 --- a/seed/python-sdk/oauth-client-credentials/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/oauth-client-credentials/src/seed/core/client_wrapper.py @@ -53,7 +53,12 @@ def __init__( httpx_client: httpx.Client, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): @@ -66,4 +71,9 @@ def __init__( httpx_client: httpx.AsyncClient, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/oauth-client-credentials/src/seed/core/http_client.py b/seed/python-sdk/oauth-client-credentials/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/oauth-client-credentials/src/seed/core/http_client.py +++ b/seed/python-sdk/oauth-client-credentials/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/object/src/seed/core/client_wrapper.py b/seed/python-sdk/object/src/seed/core/client_wrapper.py index 4d8ae245e2a..6f333d1a597 100644 --- a/seed/python-sdk/object/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/object/src/seed/core/client_wrapper.py @@ -30,10 +30,20 @@ def get_timeout(self) -> typing.Optional[float]: class SyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/object/src/seed/core/http_client.py b/seed/python-sdk/object/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/object/src/seed/core/http_client.py +++ b/seed/python-sdk/object/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/objects-with-imports/src/seed/core/client_wrapper.py b/seed/python-sdk/objects-with-imports/src/seed/core/client_wrapper.py index 62b09652764..2a5da8ebb4d 100644 --- a/seed/python-sdk/objects-with-imports/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/objects-with-imports/src/seed/core/client_wrapper.py @@ -30,10 +30,20 @@ def get_timeout(self) -> typing.Optional[float]: class SyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/objects-with-imports/src/seed/core/http_client.py b/seed/python-sdk/objects-with-imports/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/objects-with-imports/src/seed/core/http_client.py +++ b/seed/python-sdk/objects-with-imports/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/optional/src/seed/core/client_wrapper.py b/seed/python-sdk/optional/src/seed/core/client_wrapper.py index e38e5251f72..694b3c4cc14 100644 --- a/seed/python-sdk/optional/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/optional/src/seed/core/client_wrapper.py @@ -30,10 +30,20 @@ def get_timeout(self) -> typing.Optional[float]: class SyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/optional/src/seed/core/http_client.py b/seed/python-sdk/optional/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/optional/src/seed/core/http_client.py +++ b/seed/python-sdk/optional/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/optional/src/seed/optional/client.py b/seed/python-sdk/optional/src/seed/optional/client.py index d69e29aa8b5..07153246bd5 100644 --- a/seed/python-sdk/optional/src/seed/optional/client.py +++ b/seed/python-sdk/optional/src/seed/optional/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -24,7 +20,7 @@ def send_optional_body( self, *, request: typing.Optional[typing.Dict[str, typing.Any]] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> str: """ Parameters @@ -51,32 +47,7 @@ def send_optional_body( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "send-optional-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "send-optional-body", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -95,7 +66,7 @@ async def send_optional_body( self, *, request: typing.Optional[typing.Dict[str, typing.Any]] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> str: """ Parameters @@ -122,32 +93,7 @@ async def send_optional_body( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "send-optional-body"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "send-optional-body", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/package-yml/src/seed/client.py b/seed/python-sdk/package-yml/src/seed/client.py index c27a2a75a9d..d0f9251c6d6 100644 --- a/seed/python-sdk/package-yml/src/seed/client.py +++ b/seed/python-sdk/package-yml/src/seed/client.py @@ -1,7 +1,6 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError import httpx @@ -10,8 +9,6 @@ from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from .core.jsonable_encoder import jsonable_encoder from .core.pydantic_utilities import pydantic_v1 -from .core.query_encoder import encode_query -from .core.remove_none_from_dict import remove_none_from_dict from .core.request_options import RequestOptions from .service.client import AsyncServiceClient, ServiceClient @@ -94,27 +91,7 @@ def echo(self, id: str, *, request: str, request_options: typing.Optional[Reques ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"{jsonable_encoder(id)}/"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"{jsonable_encoder(id)}/", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore @@ -200,27 +177,7 @@ async def echo(self, id: str, *, request: str, request_options: typing.Optional[ ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"{jsonable_encoder(id)}/"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"{jsonable_encoder(id)}/", method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/package-yml/src/seed/core/client_wrapper.py b/seed/python-sdk/package-yml/src/seed/core/client_wrapper.py index 89b06dd7a9f..9e295db20a9 100644 --- a/seed/python-sdk/package-yml/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/package-yml/src/seed/core/client_wrapper.py @@ -30,10 +30,20 @@ def get_timeout(self) -> typing.Optional[float]: class SyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/package-yml/src/seed/core/http_client.py b/seed/python-sdk/package-yml/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/package-yml/src/seed/core/http_client.py +++ b/seed/python-sdk/package-yml/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/package-yml/src/seed/service/client.py b/seed/python-sdk/package-yml/src/seed/service/client.py index b0e9d0d0a46..e50da897e35 100644 --- a/seed/python-sdk/package-yml/src/seed/service/client.py +++ b/seed/python-sdk/package-yml/src/seed/service/client.py @@ -1,14 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ..core.jsonable_encoder import jsonable_encoder -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions @@ -44,28 +41,7 @@ def nop(self, id: str, nested_id: str, *, request_options: typing.Optional[Reque ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"{jsonable_encoder(id)}//{jsonable_encoder(nested_id)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"{jsonable_encoder(id)}//{jsonable_encoder(nested_id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -108,28 +84,7 @@ async def nop(self, id: str, nested_id: str, *, request_options: typing.Optional ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin( - f"{self._client_wrapper.get_base_url()}/", f"{jsonable_encoder(id)}//{jsonable_encoder(nested_id)}" - ), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"{jsonable_encoder(id)}//{jsonable_encoder(nested_id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return diff --git a/seed/python-sdk/pagination/src/seed/core/client_wrapper.py b/seed/python-sdk/pagination/src/seed/core/client_wrapper.py index ec3043e5aeb..366b39cb21d 100644 --- a/seed/python-sdk/pagination/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/pagination/src/seed/core/client_wrapper.py @@ -53,7 +53,12 @@ def __init__( httpx_client: httpx.Client, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): @@ -66,4 +71,9 @@ def __init__( httpx_client: httpx.AsyncClient, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/pagination/src/seed/core/http_client.py b/seed/python-sdk/pagination/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/pagination/src/seed/core/http_client.py +++ b/seed/python-sdk/pagination/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/pagination/src/seed/users/client.py b/seed/python-sdk/pagination/src/seed/users/client.py index 117ad811d1a..3fabaf068ce 100644 --- a/seed/python-sdk/pagination/src/seed/users/client.py +++ b/seed/python-sdk/pagination/src/seed/users/client.py @@ -1,7 +1,6 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError @@ -10,8 +9,6 @@ from ..core.jsonable_encoder import jsonable_encoder from ..core.pagination import AsyncPager, SyncPager from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..types.username_cursor import UsernameCursor from .types.list_users_extended_response import ListUsersExtendedResponse @@ -32,7 +29,7 @@ def list_with_cursor_pagination( per_page: typing.Optional[int] = None, order: typing.Optional[Order] = None, starting_after: typing.Optional[str] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> SyncPager[User]: """ Parameters @@ -72,38 +69,10 @@ def list_with_cursor_pagination( ) """ _response = self._client_wrapper.httpx_client.request( + "users", method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "users"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "page": page, - "per_page": per_page, - "order": order, - "starting_after": starting_after, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"page": page, "per_page": per_page, "order": order, "starting_after": starting_after}, + request_options=request_options, ) if 200 <= _response.status_code < 300: _parsed_response = pydantic_v1.parse_obj_as(ListUsersPaginationResponse, _response.json()) # type: ignore @@ -134,7 +103,7 @@ def list_with_offset_pagination( per_page: typing.Optional[int] = None, order: typing.Optional[Order] = None, starting_after: typing.Optional[str] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> SyncPager[User]: """ Parameters @@ -174,38 +143,10 @@ def list_with_offset_pagination( ) """ _response = self._client_wrapper.httpx_client.request( + "users", method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "users"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "page": page, - "per_page": per_page, - "order": order, - "starting_after": starting_after, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"page": page, "per_page": per_page, "order": order, "starting_after": starting_after}, + request_options=request_options, ) if 200 <= _response.status_code < 300: _parsed_response = pydantic_v1.parse_obj_as(ListUsersPaginationResponse, _response.json()) # type: ignore @@ -257,35 +198,7 @@ def list_with_extended_results( ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "users"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "cursor": jsonable_encoder(cursor), - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "users", method="GET", params={"cursor": jsonable_encoder(cursor)}, request_options=request_options ) if 200 <= _response.status_code < 300: _parsed_response = pydantic_v1.parse_obj_as(ListUsersExtendedResponse, _response.json()) # type: ignore @@ -332,35 +245,7 @@ def list_usernames( ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "users"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "starting_after": starting_after, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "users", method="GET", params={"starting_after": starting_after}, request_options=request_options ) if 200 <= _response.status_code < 300: _parsed_response = pydantic_v1.parse_obj_as(UsernameCursor, _response.json()) # type: ignore @@ -408,35 +293,7 @@ def list_with_global_config( ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "users"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "offset": offset, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "users", method="GET", params={"offset": offset}, request_options=request_options ) if 200 <= _response.status_code < 300: _parsed_response = pydantic_v1.parse_obj_as(UsernameContainer, _response.json()) # type: ignore @@ -464,7 +321,7 @@ async def list_with_cursor_pagination( per_page: typing.Optional[int] = None, order: typing.Optional[Order] = None, starting_after: typing.Optional[str] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> AsyncPager[User]: """ Parameters @@ -504,38 +361,10 @@ async def list_with_cursor_pagination( ) """ _response = await self._client_wrapper.httpx_client.request( + "users", method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "users"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "page": page, - "per_page": per_page, - "order": order, - "starting_after": starting_after, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"page": page, "per_page": per_page, "order": order, "starting_after": starting_after}, + request_options=request_options, ) if 200 <= _response.status_code < 300: _parsed_response = pydantic_v1.parse_obj_as(ListUsersPaginationResponse, _response.json()) # type: ignore @@ -566,7 +395,7 @@ async def list_with_offset_pagination( per_page: typing.Optional[int] = None, order: typing.Optional[Order] = None, starting_after: typing.Optional[str] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> AsyncPager[User]: """ Parameters @@ -606,38 +435,10 @@ async def list_with_offset_pagination( ) """ _response = await self._client_wrapper.httpx_client.request( + "users", method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "users"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "page": page, - "per_page": per_page, - "order": order, - "starting_after": starting_after, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={"page": page, "per_page": per_page, "order": order, "starting_after": starting_after}, + request_options=request_options, ) if 200 <= _response.status_code < 300: _parsed_response = pydantic_v1.parse_obj_as(ListUsersPaginationResponse, _response.json()) # type: ignore @@ -689,35 +490,7 @@ async def list_with_extended_results( ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "users"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "cursor": jsonable_encoder(cursor), - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "users", method="GET", params={"cursor": jsonable_encoder(cursor)}, request_options=request_options ) if 200 <= _response.status_code < 300: _parsed_response = pydantic_v1.parse_obj_as(ListUsersExtendedResponse, _response.json()) # type: ignore @@ -764,35 +537,7 @@ async def list_usernames( ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "users"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "starting_after": starting_after, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "users", method="GET", params={"starting_after": starting_after}, request_options=request_options ) if 200 <= _response.status_code < 300: _parsed_response = pydantic_v1.parse_obj_as(UsernameCursor, _response.json()) # type: ignore @@ -840,35 +585,7 @@ async def list_with_global_config( ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "users"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "offset": offset, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "users", method="GET", params={"offset": offset}, request_options=request_options ) if 200 <= _response.status_code < 300: _parsed_response = pydantic_v1.parse_obj_as(UsernameContainer, _response.json()) # type: ignore diff --git a/seed/python-sdk/plain-text/src/seed/core/client_wrapper.py b/seed/python-sdk/plain-text/src/seed/core/client_wrapper.py index 289eecccd31..6ca6c4865ca 100644 --- a/seed/python-sdk/plain-text/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/plain-text/src/seed/core/client_wrapper.py @@ -30,10 +30,20 @@ def get_timeout(self) -> typing.Optional[float]: class SyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/plain-text/src/seed/core/http_client.py b/seed/python-sdk/plain-text/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/plain-text/src/seed/core/http_client.py +++ b/seed/python-sdk/plain-text/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/plain-text/src/seed/service/client.py b/seed/python-sdk/plain-text/src/seed/service/client.py index 697a39ef623..a32a2945077 100644 --- a/seed/python-sdk/plain-text/src/seed/service/client.py +++ b/seed/python-sdk/plain-text/src/seed/service/client.py @@ -1,14 +1,10 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions @@ -36,31 +32,7 @@ def get_text(self, *, request_options: typing.Optional[RequestOptions] = None) - ) client.service.get_text() """ - _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "text"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore - ) + _response = self._client_wrapper.httpx_client.request("text", method="POST", request_options=request_options) if 200 <= _response.status_code < 300: return _response.text # type: ignore try: @@ -95,29 +67,7 @@ async def get_text(self, *, request_options: typing.Optional[RequestOptions] = N await client.service.get_text() """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "text"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "text", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return _response.text # type: ignore diff --git a/seed/python-sdk/query-parameters/src/seed/core/client_wrapper.py b/seed/python-sdk/query-parameters/src/seed/core/client_wrapper.py index f137a0cbd7b..ff1ab771aeb 100644 --- a/seed/python-sdk/query-parameters/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/query-parameters/src/seed/core/client_wrapper.py @@ -30,10 +30,20 @@ def get_timeout(self) -> typing.Optional[float]: class SyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/query-parameters/src/seed/core/http_client.py b/seed/python-sdk/query-parameters/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/query-parameters/src/seed/core/http_client.py +++ b/seed/python-sdk/query-parameters/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/query-parameters/src/seed/user/client.py b/seed/python-sdk/query-parameters/src/seed/user/client.py index 602b52f14d9..bc734de209d 100644 --- a/seed/python-sdk/query-parameters/src/seed/user/client.py +++ b/seed/python-sdk/query-parameters/src/seed/user/client.py @@ -2,7 +2,6 @@ import datetime as dt import typing -import urllib.parse import uuid from json.decoder import JSONDecodeError @@ -11,8 +10,6 @@ from ..core.datetime_utils import serialize_datetime from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from .types.nested_user import NestedUser from .types.user import User @@ -37,7 +34,7 @@ def get_username( filter: typing.Union[str, typing.Sequence[str]], optional_string: typing.Optional[str] = None, optional_user: typing.Optional[User] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> User: """ Parameters @@ -121,46 +118,23 @@ def get_username( ) """ _response = self._client_wrapper.httpx_client.request( + "user", method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "user"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "limit": limit, - "id": jsonable_encoder(id), - "date": str(date), - "deadline": serialize_datetime(deadline), - "bytes": jsonable_encoder(bytes), - "user": jsonable_encoder(user), - "keyValue": jsonable_encoder(key_value), - "optionalString": optional_string, - "nestedUser": jsonable_encoder(nested_user), - "optionalUser": jsonable_encoder(optional_user), - "excludeUser": jsonable_encoder(exclude_user), - "filter": filter, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={ + "limit": limit, + "id": jsonable_encoder(id), + "date": str(date), + "deadline": serialize_datetime(deadline), + "bytes": jsonable_encoder(bytes), + "user": jsonable_encoder(user), + "keyValue": jsonable_encoder(key_value), + "optionalString": optional_string, + "nestedUser": jsonable_encoder(nested_user), + "optionalUser": jsonable_encoder(optional_user), + "excludeUser": jsonable_encoder(exclude_user), + "filter": filter, + }, + request_options=request_options, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(User, _response.json()) # type: ignore @@ -190,7 +164,7 @@ async def get_username( filter: typing.Union[str, typing.Sequence[str]], optional_string: typing.Optional[str] = None, optional_user: typing.Optional[User] = None, - request_options: typing.Optional[RequestOptions] = None, + request_options: typing.Optional[RequestOptions] = None ) -> User: """ Parameters @@ -274,46 +248,23 @@ async def get_username( ) """ _response = await self._client_wrapper.httpx_client.request( + "user", method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "user"), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "limit": limit, - "id": jsonable_encoder(id), - "date": str(date), - "deadline": serialize_datetime(deadline), - "bytes": jsonable_encoder(bytes), - "user": jsonable_encoder(user), - "keyValue": jsonable_encoder(key_value), - "optionalString": optional_string, - "nestedUser": jsonable_encoder(nested_user), - "optionalUser": jsonable_encoder(optional_user), - "excludeUser": jsonable_encoder(exclude_user), - "filter": filter, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + params={ + "limit": limit, + "id": jsonable_encoder(id), + "date": str(date), + "deadline": serialize_datetime(deadline), + "bytes": jsonable_encoder(bytes), + "user": jsonable_encoder(user), + "keyValue": jsonable_encoder(key_value), + "optionalString": optional_string, + "nestedUser": jsonable_encoder(nested_user), + "optionalUser": jsonable_encoder(optional_user), + "excludeUser": jsonable_encoder(exclude_user), + "filter": filter, + }, + request_options=request_options, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(User, _response.json()) # type: ignore diff --git a/seed/python-sdk/reserved-keywords/src/seed/core/client_wrapper.py b/seed/python-sdk/reserved-keywords/src/seed/core/client_wrapper.py index 312403be9b7..1a751ae0d5d 100644 --- a/seed/python-sdk/reserved-keywords/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/reserved-keywords/src/seed/core/client_wrapper.py @@ -30,10 +30,20 @@ def get_timeout(self) -> typing.Optional[float]: class SyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/reserved-keywords/src/seed/core/http_client.py b/seed/python-sdk/reserved-keywords/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/reserved-keywords/src/seed/core/http_client.py +++ b/seed/python-sdk/reserved-keywords/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/reserved-keywords/src/seed/package/client.py b/seed/python-sdk/reserved-keywords/src/seed/package/client.py index 2ac3d92616b..bf617f170ff 100644 --- a/seed/python-sdk/reserved-keywords/src/seed/package/client.py +++ b/seed/python-sdk/reserved-keywords/src/seed/package/client.py @@ -5,9 +5,6 @@ from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions @@ -40,38 +37,7 @@ def test(self, *, for_: str, request_options: typing.Optional[RequestOptions] = ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=self._client_wrapper.get_base_url(), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "for": for_, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + method="POST", params={"for": for_}, request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -111,38 +77,7 @@ async def test(self, *, for_: str, request_options: typing.Optional[RequestOptio ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=self._client_wrapper.get_base_url(), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "for": for_, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + method="POST", params={"for": for_}, request_options=request_options ) if 200 <= _response.status_code < 300: return diff --git a/seed/python-sdk/server-sent-events/src/seed/completions/client.py b/seed/python-sdk/server-sent-events/src/seed/completions/client.py index 201b5dab507..5717837cbed 100644 --- a/seed/python-sdk/server-sent-events/src/seed/completions/client.py +++ b/seed/python-sdk/server-sent-events/src/seed/completions/client.py @@ -2,17 +2,13 @@ import json import typing -import urllib.parse from json.decoder import JSONDecodeError import httpx_sse from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from .types.streamed_completion import StreamedCompletion @@ -53,32 +49,7 @@ def stream( yield chunk """ with self._client_wrapper.httpx_client.stream( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "stream"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"query": query}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"query": query}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "stream", method="POST", json={"query": query}, request_options=request_options, omit=OMIT ) as _response: if 200 <= _response.status_code < 300: _event_source = httpx_sse.EventSource(_response) @@ -126,32 +97,7 @@ async def stream( yield chunk """ async with self._client_wrapper.httpx_client.stream( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "stream"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"query": query}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"query": query}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "stream", method="POST", json={"query": query}, request_options=request_options, omit=OMIT ) as _response: if 200 <= _response.status_code < 300: _event_source = httpx_sse.EventSource(_response) diff --git a/seed/python-sdk/server-sent-events/src/seed/core/client_wrapper.py b/seed/python-sdk/server-sent-events/src/seed/core/client_wrapper.py index e4f374fd251..bb41c804457 100644 --- a/seed/python-sdk/server-sent-events/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/server-sent-events/src/seed/core/client_wrapper.py @@ -30,10 +30,20 @@ def get_timeout(self) -> typing.Optional[float]: class SyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/server-sent-events/src/seed/core/http_client.py b/seed/python-sdk/server-sent-events/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/server-sent-events/src/seed/core/http_client.py +++ b/seed/python-sdk/server-sent-events/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/single-url-environment-default/src/seed/core/client_wrapper.py b/seed/python-sdk/single-url-environment-default/src/seed/core/client_wrapper.py index ebb81e789b2..6887b2415a6 100644 --- a/seed/python-sdk/single-url-environment-default/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/single-url-environment-default/src/seed/core/client_wrapper.py @@ -51,7 +51,12 @@ def __init__( httpx_client: httpx.Client, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): @@ -64,4 +69,9 @@ def __init__( httpx_client: httpx.AsyncClient, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/single-url-environment-default/src/seed/core/http_client.py b/seed/python-sdk/single-url-environment-default/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/single-url-environment-default/src/seed/core/http_client.py +++ b/seed/python-sdk/single-url-environment-default/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/single-url-environment-default/src/seed/dummy/client.py b/seed/python-sdk/single-url-environment-default/src/seed/dummy/client.py index 5608d31b05b..e1738ed0834 100644 --- a/seed/python-sdk/single-url-environment-default/src/seed/dummy/client.py +++ b/seed/python-sdk/single-url-environment-default/src/seed/dummy/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions @@ -37,28 +33,7 @@ def get_dummy(self, *, request_options: typing.Optional[RequestOptions] = None) ) client.dummy.get_dummy() """ - _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "dummy"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore - ) + _response = self._client_wrapper.httpx_client.request("dummy", method="GET", request_options=request_options) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore try: @@ -93,26 +68,7 @@ async def get_dummy(self, *, request_options: typing.Optional[RequestOptions] = await client.dummy.get_dummy() """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "dummy"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "dummy", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/single-url-environment-no-default/src/seed/core/client_wrapper.py b/seed/python-sdk/single-url-environment-no-default/src/seed/core/client_wrapper.py index 9f2f52452c0..721db61d27f 100644 --- a/seed/python-sdk/single-url-environment-no-default/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/single-url-environment-no-default/src/seed/core/client_wrapper.py @@ -51,7 +51,12 @@ def __init__( httpx_client: httpx.Client, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): @@ -64,4 +69,9 @@ def __init__( httpx_client: httpx.AsyncClient, ): super().__init__(token=token, base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/single-url-environment-no-default/src/seed/core/http_client.py b/seed/python-sdk/single-url-environment-no-default/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/single-url-environment-no-default/src/seed/core/http_client.py +++ b/seed/python-sdk/single-url-environment-no-default/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/single-url-environment-no-default/src/seed/dummy/client.py b/seed/python-sdk/single-url-environment-no-default/src/seed/dummy/client.py index cd3df461ea4..3b7521bb97e 100644 --- a/seed/python-sdk/single-url-environment-no-default/src/seed/dummy/client.py +++ b/seed/python-sdk/single-url-environment-no-default/src/seed/dummy/client.py @@ -1,15 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions @@ -39,28 +35,7 @@ def get_dummy(self, *, request_options: typing.Optional[RequestOptions] = None) ) client.dummy.get_dummy() """ - _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "dummy"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore - ) + _response = self._client_wrapper.httpx_client.request("dummy", method="GET", request_options=request_options) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore try: @@ -97,26 +72,7 @@ async def get_dummy(self, *, request_options: typing.Optional[RequestOptions] = await client.dummy.get_dummy() """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "dummy"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + "dummy", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(str, _response.json()) # type: ignore diff --git a/seed/python-sdk/streaming/no-custom-config/src/seed/core/client_wrapper.py b/seed/python-sdk/streaming/no-custom-config/src/seed/core/client_wrapper.py index d4befbfe985..f5a3cbe0a1d 100644 --- a/seed/python-sdk/streaming/no-custom-config/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/streaming/no-custom-config/src/seed/core/client_wrapper.py @@ -30,10 +30,20 @@ def get_timeout(self) -> typing.Optional[float]: class SyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/streaming/no-custom-config/src/seed/core/http_client.py b/seed/python-sdk/streaming/no-custom-config/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/streaming/no-custom-config/src/seed/core/http_client.py +++ b/seed/python-sdk/streaming/no-custom-config/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/streaming/no-custom-config/src/seed/dummy/client.py b/seed/python-sdk/streaming/no-custom-config/src/seed/dummy/client.py index 077b9e2b928..5e8a4564fb5 100644 --- a/seed/python-sdk/streaming/no-custom-config/src/seed/dummy/client.py +++ b/seed/python-sdk/streaming/no-custom-config/src/seed/dummy/client.py @@ -2,15 +2,11 @@ import json import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from .types.stream_response import StreamResponse @@ -51,32 +47,11 @@ def generate_stream( yield chunk """ with self._client_wrapper.httpx_client.stream( + "generate-stream", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "generate-stream"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"num_events": num_events}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"num_events": num_events}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"num_events": num_events}, + request_options=request_options, + omit=OMIT, ) as _response: if 200 <= _response.status_code < 300: for _text in _response.iter_lines(): @@ -125,32 +100,11 @@ async def generate_stream( yield chunk """ async with self._client_wrapper.httpx_client.stream( + "generate-stream", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "generate-stream"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"num_events": num_events}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"num_events": num_events}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"num_events": num_events}, + request_options=request_options, + omit=OMIT, ) as _response: if 200 <= _response.status_code < 300: async for _text in _response.aiter_lines(): diff --git a/seed/python-sdk/streaming/skip-pydantic-validation/src/seed/core/client_wrapper.py b/seed/python-sdk/streaming/skip-pydantic-validation/src/seed/core/client_wrapper.py index d4befbfe985..f5a3cbe0a1d 100644 --- a/seed/python-sdk/streaming/skip-pydantic-validation/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/streaming/skip-pydantic-validation/src/seed/core/client_wrapper.py @@ -30,10 +30,20 @@ def get_timeout(self) -> typing.Optional[float]: class SyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/streaming/skip-pydantic-validation/src/seed/core/http_client.py b/seed/python-sdk/streaming/skip-pydantic-validation/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/streaming/skip-pydantic-validation/src/seed/core/http_client.py +++ b/seed/python-sdk/streaming/skip-pydantic-validation/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/streaming/skip-pydantic-validation/src/seed/dummy/client.py b/seed/python-sdk/streaming/skip-pydantic-validation/src/seed/dummy/client.py index 284877c5a0e..cec285401c2 100644 --- a/seed/python-sdk/streaming/skip-pydantic-validation/src/seed/dummy/client.py +++ b/seed/python-sdk/streaming/skip-pydantic-validation/src/seed/dummy/client.py @@ -2,14 +2,10 @@ import json import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from ..core.unchecked_base_model import construct_type from .types.stream_response import StreamResponse @@ -51,32 +47,11 @@ def generate_stream( yield chunk """ with self._client_wrapper.httpx_client.stream( + "generate-stream", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "generate-stream"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"num_events": num_events}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"num_events": num_events}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"num_events": num_events}, + request_options=request_options, + omit=OMIT, ) as _response: if 200 <= _response.status_code < 300: for _text in _response.iter_lines(): @@ -125,32 +100,11 @@ async def generate_stream( yield chunk """ async with self._client_wrapper.httpx_client.stream( + "generate-stream", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "generate-stream"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"num_events": num_events}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"num_events": num_events}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"num_events": num_events}, + request_options=request_options, + omit=OMIT, ) as _response: if 200 <= _response.status_code < 300: async for _text in _response.aiter_lines(): diff --git a/seed/python-sdk/undiscriminated-unions/src/seed/core/client_wrapper.py b/seed/python-sdk/undiscriminated-unions/src/seed/core/client_wrapper.py index dcc58b7c504..f940f2d4ab4 100644 --- a/seed/python-sdk/undiscriminated-unions/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/undiscriminated-unions/src/seed/core/client_wrapper.py @@ -30,10 +30,20 @@ def get_timeout(self) -> typing.Optional[float]: class SyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/undiscriminated-unions/src/seed/core/http_client.py b/seed/python-sdk/undiscriminated-unions/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/undiscriminated-unions/src/seed/core/http_client.py +++ b/seed/python-sdk/undiscriminated-unions/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/undiscriminated-unions/src/seed/union/client.py b/seed/python-sdk/undiscriminated-unions/src/seed/union/client.py index 8f306fe9bab..c5c0d975970 100644 --- a/seed/python-sdk/undiscriminated-unions/src/seed/union/client.py +++ b/seed/python-sdk/undiscriminated-unions/src/seed/union/client.py @@ -5,10 +5,7 @@ from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from .types.my_union import MyUnion @@ -45,32 +42,7 @@ def get(self, *, request: MyUnion, request_options: typing.Optional[RequestOptio ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=self._client_wrapper.get_base_url(), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(MyUnion, _response.json()) # type: ignore @@ -110,32 +82,7 @@ async def get(self, *, request: MyUnion, request_options: typing.Optional[Reques ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=self._client_wrapper.get_base_url(), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(MyUnion, _response.json()) # type: ignore diff --git a/seed/python-sdk/unions/src/seed/core/client_wrapper.py b/seed/python-sdk/unions/src/seed/core/client_wrapper.py index e19704f963f..a12ded4d812 100644 --- a/seed/python-sdk/unions/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/unions/src/seed/core/client_wrapper.py @@ -30,10 +30,20 @@ def get_timeout(self) -> typing.Optional[float]: class SyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/unions/src/seed/core/http_client.py b/seed/python-sdk/unions/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/unions/src/seed/core/http_client.py +++ b/seed/python-sdk/unions/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/unions/src/seed/union/client.py b/seed/python-sdk/unions/src/seed/union/client.py index 625af52fa54..4edd47080c0 100644 --- a/seed/python-sdk/unions/src/seed/union/client.py +++ b/seed/python-sdk/unions/src/seed/union/client.py @@ -1,15 +1,12 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions from .types.shape import Shape @@ -46,26 +43,7 @@ def get(self, id: str, *, request_options: typing.Optional[RequestOptions] = Non ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"{jsonable_encoder(id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Shape, _response.json()) # type: ignore @@ -104,32 +82,7 @@ def update(self, *, request: Shape, request_options: typing.Optional[RequestOpti ) """ _response = self._client_wrapper.httpx_client.request( - method="PATCH", - url=self._client_wrapper.get_base_url(), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + method="PATCH", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore @@ -169,26 +122,7 @@ async def get(self, id: str, *, request_options: typing.Optional[RequestOptions] ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"{jsonable_encoder(id)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"{jsonable_encoder(id)}", method="GET", request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Shape, _response.json()) # type: ignore @@ -227,32 +161,7 @@ async def update(self, *, request: Shape, request_options: typing.Optional[Reque ) """ _response = await self._client_wrapper.httpx_client.request( - method="PATCH", - url=self._client_wrapper.get_base_url(), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + method="PATCH", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(bool, _response.json()) # type: ignore diff --git a/seed/python-sdk/unknown/src/seed/core/client_wrapper.py b/seed/python-sdk/unknown/src/seed/core/client_wrapper.py index db0b4cb8290..12e235ac7e0 100644 --- a/seed/python-sdk/unknown/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/unknown/src/seed/core/client_wrapper.py @@ -30,10 +30,20 @@ def get_timeout(self) -> typing.Optional[float]: class SyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/unknown/src/seed/core/http_client.py b/seed/python-sdk/unknown/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/unknown/src/seed/core/http_client.py +++ b/seed/python-sdk/unknown/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/unknown/src/seed/unknown/client.py b/seed/python-sdk/unknown/src/seed/unknown/client.py index a03ded93fd3..a292cfc5ccf 100644 --- a/seed/python-sdk/unknown/src/seed/unknown/client.py +++ b/seed/python-sdk/unknown/src/seed/unknown/client.py @@ -5,10 +5,7 @@ from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from ..core.jsonable_encoder import jsonable_encoder from ..core.pydantic_utilities import pydantic_v1 -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions # this is used as the default value for optional parameters @@ -46,32 +43,7 @@ def post( ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=self._client_wrapper.get_base_url(), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[typing.Any], _response.json()) # type: ignore @@ -113,32 +85,7 @@ async def post( ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=self._client_wrapper.get_base_url(), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(request) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder(request), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + method="POST", json=request, request_options=request_options, omit=OMIT ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(typing.List[typing.Any], _response.json()) # type: ignore diff --git a/seed/python-sdk/validation/src/seed/client.py b/seed/python-sdk/validation/src/seed/client.py index aa274c1fe99..59a1a65998d 100644 --- a/seed/python-sdk/validation/src/seed/client.py +++ b/seed/python-sdk/validation/src/seed/client.py @@ -1,17 +1,13 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError import httpx from .core.api_error import ApiError from .core.client_wrapper import AsyncClientWrapper, SyncClientWrapper -from .core.jsonable_encoder import jsonable_encoder from .core.pydantic_utilities import pydantic_v1 -from .core.query_encoder import encode_query -from .core.remove_none_from_dict import remove_none_from_dict from .core.request_options import RequestOptions from .types.type import Type @@ -52,7 +48,7 @@ def __init__( base_url: str, timeout: typing.Optional[float] = None, follow_redirects: typing.Optional[bool] = True, - httpx_client: typing.Optional[httpx.Client] = None, + httpx_client: typing.Optional[httpx.Client] = None ): _defaulted_timeout = timeout if timeout is not None else 60 if httpx_client is None else None self._client_wrapper = SyncClientWrapper( @@ -98,32 +94,11 @@ def create( ) """ _response = self._client_wrapper.httpx_client.request( + "create", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "create"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"decimal": decimal, "even": even, "name": name}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"decimal": decimal, "even": even, "name": name}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"decimal": decimal, "even": even, "name": name}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Type, _response.json()) # type: ignore @@ -166,37 +141,7 @@ def get( ) """ _response = self._client_wrapper.httpx_client.request( - method="GET", - url=self._client_wrapper.get_base_url(), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "decimal": decimal, - "even": even, - "name": name, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + method="GET", params={"decimal": decimal, "even": even, "name": name}, request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Type, _response.json()) # type: ignore @@ -240,7 +185,7 @@ def __init__( base_url: str, timeout: typing.Optional[float] = None, follow_redirects: typing.Optional[bool] = True, - httpx_client: typing.Optional[httpx.AsyncClient] = None, + httpx_client: typing.Optional[httpx.AsyncClient] = None ): _defaulted_timeout = timeout if timeout is not None else 60 if httpx_client is None else None self._client_wrapper = AsyncClientWrapper( @@ -286,32 +231,11 @@ async def create( ) """ _response = await self._client_wrapper.httpx_client.request( + "create", method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", "create"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder({"decimal": decimal, "even": even, "name": name}) - if request_options is None or request_options.get("additional_body_parameters") is None - else { - **jsonable_encoder({"decimal": decimal, "even": even, "name": name}), - **(jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {})))), - }, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + json={"decimal": decimal, "even": even, "name": name}, + request_options=request_options, + omit=OMIT, ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Type, _response.json()) # type: ignore @@ -354,37 +278,7 @@ async def get( ) """ _response = await self._client_wrapper.httpx_client.request( - method="GET", - url=self._client_wrapper.get_base_url(), - params=encode_query( - jsonable_encoder( - remove_none_from_dict( - { - "decimal": decimal, - "even": even, - "name": name, - **( - request_options.get("additional_query_parameters", {}) - if request_options is not None - else {} - ), - } - ) - ) - ), - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + method="GET", params={"decimal": decimal, "even": even, "name": name}, request_options=request_options ) if 200 <= _response.status_code < 300: return pydantic_v1.parse_obj_as(Type, _response.json()) # type: ignore diff --git a/seed/python-sdk/validation/src/seed/core/client_wrapper.py b/seed/python-sdk/validation/src/seed/core/client_wrapper.py index d18294892fc..45bff809ee6 100644 --- a/seed/python-sdk/validation/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/validation/src/seed/core/client_wrapper.py @@ -30,10 +30,20 @@ def get_timeout(self) -> typing.Optional[float]: class SyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/validation/src/seed/core/http_client.py b/seed/python-sdk/validation/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/validation/src/seed/core/http_client.py +++ b/seed/python-sdk/validation/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/variables/src/seed/core/client_wrapper.py b/seed/python-sdk/variables/src/seed/core/client_wrapper.py index 27bd3c572e2..70df8e6ae67 100644 --- a/seed/python-sdk/variables/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/variables/src/seed/core/client_wrapper.py @@ -30,10 +30,20 @@ def get_timeout(self) -> typing.Optional[float]: class SyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/variables/src/seed/core/http_client.py b/seed/python-sdk/variables/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/variables/src/seed/core/http_client.py +++ b/seed/python-sdk/variables/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream diff --git a/seed/python-sdk/variables/src/seed/service/client.py b/seed/python-sdk/variables/src/seed/service/client.py index 129b6ae49b9..7bf61da61c8 100644 --- a/seed/python-sdk/variables/src/seed/service/client.py +++ b/seed/python-sdk/variables/src/seed/service/client.py @@ -1,14 +1,11 @@ # This file was auto-generated by Fern from our API Definition. import typing -import urllib.parse from json.decoder import JSONDecodeError from ..core.api_error import ApiError from ..core.client_wrapper import AsyncClientWrapper, SyncClientWrapper from ..core.jsonable_encoder import jsonable_encoder -from ..core.query_encoder import encode_query -from ..core.remove_none_from_dict import remove_none_from_dict from ..core.request_options import RequestOptions @@ -41,29 +38,7 @@ def post(self, endpoint_param: str, *, request_options: typing.Optional[RequestO ) """ _response = self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"{jsonable_encoder(endpoint_param)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"{jsonable_encoder(endpoint_param)}", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return @@ -103,29 +78,7 @@ async def post(self, endpoint_param: str, *, request_options: typing.Optional[Re ) """ _response = await self._client_wrapper.httpx_client.request( - method="POST", - url=urllib.parse.urljoin(f"{self._client_wrapper.get_base_url()}/", f"{jsonable_encoder(endpoint_param)}"), - params=encode_query( - jsonable_encoder( - request_options.get("additional_query_parameters") if request_options is not None else None - ) - ), - json=jsonable_encoder(remove_none_from_dict(request_options.get("additional_body_parameters", {}))) - if request_options is not None - else None, - headers=jsonable_encoder( - remove_none_from_dict( - { - **self._client_wrapper.get_headers(), - **(request_options.get("additional_headers", {}) if request_options is not None else {}), - } - ) - ), - timeout=request_options.get("timeout_in_seconds") - if request_options is not None and request_options.get("timeout_in_seconds") is not None - else self._client_wrapper.get_timeout(), - retries=0, - max_retries=request_options.get("max_retries") if request_options is not None else 0, # type: ignore + f"{jsonable_encoder(endpoint_param)}", method="POST", request_options=request_options ) if 200 <= _response.status_code < 300: return diff --git a/seed/python-sdk/websocket/src/seed/core/client_wrapper.py b/seed/python-sdk/websocket/src/seed/core/client_wrapper.py index 04f243f321f..918281e5157 100644 --- a/seed/python-sdk/websocket/src/seed/core/client_wrapper.py +++ b/seed/python-sdk/websocket/src/seed/core/client_wrapper.py @@ -30,10 +30,20 @@ def get_timeout(self) -> typing.Optional[float]: class SyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = HttpClient(httpx_client=httpx_client) + self.httpx_client = HttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) class AsyncClientWrapper(BaseClientWrapper): def __init__(self, *, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient): super().__init__(base_url=base_url, timeout=timeout) - self.httpx_client = AsyncHttpClient(httpx_client=httpx_client) + self.httpx_client = AsyncHttpClient( + httpx_client=httpx_client, + base_headers=self.get_headers(), + base_timeout=self.get_timeout(), + base_url=self.get_base_url(), + ) diff --git a/seed/python-sdk/websocket/src/seed/core/http_client.py b/seed/python-sdk/websocket/src/seed/core/http_client.py index 4e6877df257..6c3686981a2 100644 --- a/seed/python-sdk/websocket/src/seed/core/http_client.py +++ b/seed/python-sdk/websocket/src/seed/core/http_client.py @@ -5,12 +5,18 @@ import re import time import typing +import urllib.parse from contextlib import asynccontextmanager, contextmanager -from functools import wraps from random import random import httpx +from .file import File, convert_file_dict_to_httpx_tuples +from .jsonable_encoder import jsonable_encoder +from .query_encoder import encode_query +from .remove_none_from_dict import remove_none_from_dict +from .request_options import RequestOptions + INITIAL_RETRY_DELAY_SECONDS = 0.5 MAX_RETRY_DELAY_SECONDS = 10 MAX_RETRY_DELAY_SECONDS_FROM_HEADER = 30 @@ -82,49 +88,348 @@ def _should_retry(response: httpx.Response) -> bool: return response.status_code >= 500 or response.status_code in retriable_400s +def remove_omit_from_dict( + original: typing.Dict[str, typing.Optional[typing.Any]], omit: typing.Optional[typing.Any] +) -> typing.Dict[str, typing.Any]: + if omit is None: + return original + new: typing.Dict[str, typing.Any] = {} + for key, value in original.items(): + if value is not omit: + new[key] = value + return new + + +def maybe_filter_request_body( + data: typing.Optional[typing.Any], + request_options: typing.Optional[RequestOptions], + omit: typing.Optional[typing.Any], +) -> typing.Optional[typing.Any]: + if data is None: + return None + elif not isinstance(data, typing.Mapping): + data_content = jsonable_encoder(data) + else: + data_content = { + **(jsonable_encoder(remove_omit_from_dict(data, omit))), # type: ignore + **( + jsonable_encoder(request_options.get("additional_body_parameters", {})) + if request_options is not None + else {} + ), + } + return data_content + + class HttpClient: - def __init__(self, *, httpx_client: httpx.Client): + def __init__( + self, + *, + httpx_client: httpx.Client, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.Client.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + response = self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: time.sleep(_retry_timeout(response=response, retries=retries)) - return self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) + return response - @wraps(httpx.Client.stream) @contextmanager - def stream(self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any) -> typing.Any: - with self.httpx_client.stream(*args, **kwargs) as stream: + def stream( + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.Iterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream class AsyncHttpClient: - def __init__(self, *, httpx_client: httpx.AsyncClient): + def __init__( + self, + *, + httpx_client: httpx.AsyncClient, + base_timeout: typing.Optional[float], + base_headers: typing.Dict[str, str], + base_url: typing.Optional[str] = None, + ): + self.base_url = base_url + self.base_timeout = base_timeout + self.base_headers = base_headers self.httpx_client = httpx_client - # Ensure that the signature of the `request` method is the same as the `httpx.Client.request` method - @wraps(httpx.AsyncClient.request) + def get_base_url(self, maybe_base_url: typing.Optional[str]) -> str: + base_url = self.base_url if maybe_base_url is None else maybe_base_url + if base_url is None: + raise ValueError("A base_url is required to make this request, please provide one and try again.") + return base_url + async def request( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, ) -> httpx.Response: - response = await self.httpx_client.request(*args, **kwargs) + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + # Add the input to each of these and do None-safety checks + response = await self.httpx_client.request( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) + + max_retries: int = request_options.get("max_retries", 0) if request_options is not None else 0 if _should_retry(response=response): if max_retries > retries: await asyncio.sleep(_retry_timeout(response=response, retries=retries)) - return await self.request(max_retries=max_retries, retries=retries + 1, *args, **kwargs) + return await self.request( + path=path, + method=method, + base_url=base_url, + params=params, + json=json, + content=content, + files=files, + headers=headers, + request_options=request_options, + retries=retries + 1, + omit=omit, + ) return response - @wraps(httpx.AsyncClient.stream) @asynccontextmanager async def stream( - self, *args: typing.Any, max_retries: int = 0, retries: int = 0, **kwargs: typing.Any - ) -> typing.Any: - async with self.httpx_client.stream(*args, **kwargs) as stream: + self, + path: typing.Optional[str] = None, + *, + method: str, + base_url: typing.Optional[str] = None, + params: typing.Optional[typing.Dict[str, typing.Any]] = None, + json: typing.Optional[typing.Any] = None, + data: typing.Optional[typing.Any] = None, + content: typing.Optional[typing.Union[bytes, typing.Iterator[bytes], typing.AsyncIterator[bytes]]] = None, + files: typing.Optional[typing.Dict[str, typing.Union[File, typing.List[File]]]] = None, + headers: typing.Optional[typing.Dict[str, typing.Any]] = None, + request_options: typing.Optional[RequestOptions] = None, + retries: int = 0, + omit: typing.Optional[typing.Any] = None, + ) -> typing.AsyncIterator[httpx.Response]: + base_url = self.get_base_url(base_url) + timeout = ( + request_options.get("timeout_in_seconds") + if request_options is not None and request_options.get("timeout_in_seconds") is not None + else self.base_timeout + ) + + async with self.httpx_client.stream( + method=method, + url=urllib.parse.urljoin(base_url, path), + headers=jsonable_encoder( + remove_none_from_dict( + { + **self.base_headers, + **(headers if headers is not None else {}), + **(request_options.get("additional_headers", {}) if request_options is not None else {}), + } + ) + ), + params=encode_query( + jsonable_encoder( + remove_omit_from_dict( + { + **(params if params is not None else {}), + **( + request_options.get("additional_query_parameters", {}) + if request_options is not None + else {} + ), + }, + omit=omit, + ) + ) + ), + json=maybe_filter_request_body(json, request_options, omit), + data=maybe_filter_request_body(data, request_options, omit), + content=content, + files=convert_file_dict_to_httpx_tuples(remove_none_from_dict(files)) if files is not None else None, + timeout=timeout, + ) as stream: yield stream