Skip to content

Commit c745a2b

Browse files
refactor(client): remove deprecated http client options (#704)
instead of passing these options directly to Lithic, you should instantiate a custom http client https://github.com/lithic-com/lithic-python#configuring-the-http-client
1 parent a00fdff commit c745a2b

File tree

3 files changed

+3
-367
lines changed

3 files changed

+3
-367
lines changed

src/lithic/_base_client.py

Lines changed: 1 addition & 96 deletions
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,6 @@
99
import inspect
1010
import logging
1111
import platform
12-
import warnings
1312
import email.utils
1413
from types import TracebackType
1514
from random import random
@@ -36,7 +35,7 @@
3635
import httpx
3736
import distro
3837
import pydantic
39-
from httpx import URL, Limits
38+
from httpx import URL
4039
from pydantic import PrivateAttr
4140

4241
from . import _exceptions
@@ -51,13 +50,10 @@
5150
Timeout,
5251
NotGiven,
5352
ResponseT,
54-
Transport,
5553
AnyMapping,
5654
PostParser,
57-
ProxiesTypes,
5855
RequestFiles,
5956
HttpxSendArgs,
60-
AsyncTransport,
6157
RequestOptions,
6258
HttpxRequestFiles,
6359
ModelBuilderProtocol,
@@ -338,9 +334,6 @@ class BaseClient(Generic[_HttpxClientT, _DefaultStreamT]):
338334
_base_url: URL
339335
max_retries: int
340336
timeout: Union[float, Timeout, None]
341-
_limits: httpx.Limits
342-
_proxies: ProxiesTypes | None
343-
_transport: Transport | AsyncTransport | None
344337
_strict_response_validation: bool
345338
_idempotency_header: str | None
346339
_default_stream_cls: type[_DefaultStreamT] | None = None
@@ -353,19 +346,13 @@ def __init__(
353346
_strict_response_validation: bool,
354347
max_retries: int = DEFAULT_MAX_RETRIES,
355348
timeout: float | Timeout | None = DEFAULT_TIMEOUT,
356-
limits: httpx.Limits,
357-
transport: Transport | AsyncTransport | None,
358-
proxies: ProxiesTypes | None,
359349
custom_headers: Mapping[str, str] | None = None,
360350
custom_query: Mapping[str, object] | None = None,
361351
) -> None:
362352
self._version = version
363353
self._base_url = self._enforce_trailing_slash(URL(base_url))
364354
self.max_retries = max_retries
365355
self.timeout = timeout
366-
self._limits = limits
367-
self._proxies = proxies
368-
self._transport = transport
369356
self._custom_headers = custom_headers or {}
370357
self._custom_query = custom_query or {}
371358
self._strict_response_validation = _strict_response_validation
@@ -801,46 +788,11 @@ def __init__(
801788
base_url: str | URL,
802789
max_retries: int = DEFAULT_MAX_RETRIES,
803790
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
804-
transport: Transport | None = None,
805-
proxies: ProxiesTypes | None = None,
806-
limits: Limits | None = None,
807791
http_client: httpx.Client | None = None,
808792
custom_headers: Mapping[str, str] | None = None,
809793
custom_query: Mapping[str, object] | None = None,
810794
_strict_response_validation: bool,
811795
) -> None:
812-
kwargs: dict[str, Any] = {}
813-
if limits is not None:
814-
warnings.warn(
815-
"The `connection_pool_limits` argument is deprecated. The `http_client` argument should be passed instead",
816-
category=DeprecationWarning,
817-
stacklevel=3,
818-
)
819-
if http_client is not None:
820-
raise ValueError("The `http_client` argument is mutually exclusive with `connection_pool_limits`")
821-
else:
822-
limits = DEFAULT_CONNECTION_LIMITS
823-
824-
if transport is not None:
825-
kwargs["transport"] = transport
826-
warnings.warn(
827-
"The `transport` argument is deprecated. The `http_client` argument should be passed instead",
828-
category=DeprecationWarning,
829-
stacklevel=3,
830-
)
831-
if http_client is not None:
832-
raise ValueError("The `http_client` argument is mutually exclusive with `transport`")
833-
834-
if proxies is not None:
835-
kwargs["proxies"] = proxies
836-
warnings.warn(
837-
"The `proxies` argument is deprecated. The `http_client` argument should be passed instead",
838-
category=DeprecationWarning,
839-
stacklevel=3,
840-
)
841-
if http_client is not None:
842-
raise ValueError("The `http_client` argument is mutually exclusive with `proxies`")
843-
844796
if not is_given(timeout):
845797
# if the user passed in a custom http client with a non-default
846798
# timeout set then we use that timeout.
@@ -861,12 +813,9 @@ def __init__(
861813

862814
super().__init__(
863815
version=version,
864-
limits=limits,
865816
# cast to a valid type because mypy doesn't understand our type narrowing
866817
timeout=cast(Timeout, timeout),
867-
proxies=proxies,
868818
base_url=base_url,
869-
transport=transport,
870819
max_retries=max_retries,
871820
custom_query=custom_query,
872821
custom_headers=custom_headers,
@@ -876,9 +825,6 @@ def __init__(
876825
base_url=base_url,
877826
# cast to a valid type because mypy doesn't understand our type narrowing
878827
timeout=cast(Timeout, timeout),
879-
limits=limits,
880-
follow_redirects=True,
881-
**kwargs, # type: ignore
882828
)
883829

884830
def is_closed(self) -> bool:
@@ -1387,45 +1333,10 @@ def __init__(
13871333
_strict_response_validation: bool,
13881334
max_retries: int = DEFAULT_MAX_RETRIES,
13891335
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
1390-
transport: AsyncTransport | None = None,
1391-
proxies: ProxiesTypes | None = None,
1392-
limits: Limits | None = None,
13931336
http_client: httpx.AsyncClient | None = None,
13941337
custom_headers: Mapping[str, str] | None = None,
13951338
custom_query: Mapping[str, object] | None = None,
13961339
) -> None:
1397-
kwargs: dict[str, Any] = {}
1398-
if limits is not None:
1399-
warnings.warn(
1400-
"The `connection_pool_limits` argument is deprecated. The `http_client` argument should be passed instead",
1401-
category=DeprecationWarning,
1402-
stacklevel=3,
1403-
)
1404-
if http_client is not None:
1405-
raise ValueError("The `http_client` argument is mutually exclusive with `connection_pool_limits`")
1406-
else:
1407-
limits = DEFAULT_CONNECTION_LIMITS
1408-
1409-
if transport is not None:
1410-
kwargs["transport"] = transport
1411-
warnings.warn(
1412-
"The `transport` argument is deprecated. The `http_client` argument should be passed instead",
1413-
category=DeprecationWarning,
1414-
stacklevel=3,
1415-
)
1416-
if http_client is not None:
1417-
raise ValueError("The `http_client` argument is mutually exclusive with `transport`")
1418-
1419-
if proxies is not None:
1420-
kwargs["proxies"] = proxies
1421-
warnings.warn(
1422-
"The `proxies` argument is deprecated. The `http_client` argument should be passed instead",
1423-
category=DeprecationWarning,
1424-
stacklevel=3,
1425-
)
1426-
if http_client is not None:
1427-
raise ValueError("The `http_client` argument is mutually exclusive with `proxies`")
1428-
14291340
if not is_given(timeout):
14301341
# if the user passed in a custom http client with a non-default
14311342
# timeout set then we use that timeout.
@@ -1447,11 +1358,8 @@ def __init__(
14471358
super().__init__(
14481359
version=version,
14491360
base_url=base_url,
1450-
limits=limits,
14511361
# cast to a valid type because mypy doesn't understand our type narrowing
14521362
timeout=cast(Timeout, timeout),
1453-
proxies=proxies,
1454-
transport=transport,
14551363
max_retries=max_retries,
14561364
custom_query=custom_query,
14571365
custom_headers=custom_headers,
@@ -1461,9 +1369,6 @@ def __init__(
14611369
base_url=base_url,
14621370
# cast to a valid type because mypy doesn't understand our type narrowing
14631371
timeout=cast(Timeout, timeout),
1464-
limits=limits,
1465-
follow_redirects=True,
1466-
**kwargs, # type: ignore
14671372
)
14681373

14691374
def is_closed(self) -> bool:

src/lithic/_client.py

Lines changed: 2 additions & 62 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
NotGiven,
2121
Transport,
2222
ProxiesTypes,
23-
AsyncTransport,
2423
RequestOptions,
2524
)
2625
from ._utils import (
@@ -51,11 +50,8 @@
5150
from ._exceptions import LithicError, APIStatusError
5251
from ._base_client import (
5352
DEFAULT_MAX_RETRIES,
54-
DEFAULT_CONNECTION_LIMITS,
5553
SyncAPIClient,
5654
AsyncAPIClient,
57-
SyncHttpxClientWrapper,
58-
AsyncHttpxClientWrapper,
5955
make_request_options,
6056
)
6157
from .resources.cards import cards
@@ -137,12 +133,6 @@ def __init__(
137133
# We provide a `DefaultHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
138134
# See the [httpx documentation](https://www.python-httpx.org/api/#client) for more details.
139135
http_client: httpx.Client | None = None,
140-
# See httpx documentation for [custom transports](https://www.python-httpx.org/advanced/#custom-transports)
141-
transport: Transport | None = None,
142-
# See httpx documentation for [proxies](https://www.python-httpx.org/advanced/#http-proxying)
143-
proxies: ProxiesTypes | None = None,
144-
# See httpx documentation for [limits](https://www.python-httpx.org/advanced/#pool-limit-configuration)
145-
connection_pool_limits: httpx.Limits | None = None,
146136
# Enable or disable schema validation for data returned by the API.
147137
# When enabled an error APIResponseValidationError is raised
148138
# if the API responds with invalid data for the expected schema.
@@ -203,9 +193,6 @@ def __init__(
203193
max_retries=max_retries,
204194
timeout=timeout,
205195
http_client=http_client,
206-
transport=transport,
207-
proxies=proxies,
208-
limits=connection_pool_limits,
209196
custom_headers=default_headers,
210197
custom_query=default_query,
211198
_strict_response_validation=_strict_response_validation,
@@ -269,7 +256,6 @@ def copy(
269256
base_url: str | httpx.URL | None = None,
270257
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
271258
http_client: httpx.Client | None = None,
272-
connection_pool_limits: httpx.Limits | None = None,
273259
max_retries: int | NotGiven = NOT_GIVEN,
274260
default_headers: Mapping[str, str] | None = None,
275261
set_default_headers: Mapping[str, str] | None = None,
@@ -298,32 +284,14 @@ def copy(
298284
elif set_default_query is not None:
299285
params = set_default_query
300286

301-
if connection_pool_limits is not None:
302-
if http_client is not None:
303-
raise ValueError("The 'http_client' argument is mutually exclusive with 'connection_pool_limits'")
304-
305-
if not isinstance(self._client, SyncHttpxClientWrapper):
306-
raise ValueError(
307-
"A custom HTTP client has been set and is mutually exclusive with the 'connection_pool_limits' argument"
308-
)
309-
310-
http_client = None
311-
else:
312-
if self._limits is not DEFAULT_CONNECTION_LIMITS:
313-
connection_pool_limits = self._limits
314-
else:
315-
connection_pool_limits = None
316-
317-
http_client = http_client or self._client
318-
287+
http_client = http_client or self._client
319288
return self.__class__(
320289
api_key=api_key or self.api_key,
321290
webhook_secret=webhook_secret or self.webhook_secret,
322291
base_url=base_url or self.base_url,
323292
environment=environment or self._environment,
324293
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
325294
http_client=http_client,
326-
connection_pool_limits=connection_pool_limits,
327295
max_retries=max_retries if is_given(max_retries) else self.max_retries,
328296
default_headers=headers,
329297
default_query=params,
@@ -437,12 +405,6 @@ def __init__(
437405
# We provide a `DefaultAsyncHttpxClient` class that you can pass to retain the default values we use for `limits`, `timeout` & `follow_redirects`.
438406
# See the [httpx documentation](https://www.python-httpx.org/api/#asyncclient) for more details.
439407
http_client: httpx.AsyncClient | None = None,
440-
# See httpx documentation for [custom transports](https://www.python-httpx.org/advanced/#custom-transports)
441-
transport: AsyncTransport | None = None,
442-
# See httpx documentation for [proxies](https://www.python-httpx.org/advanced/#http-proxying)
443-
proxies: ProxiesTypes | None = None,
444-
# See httpx documentation for [limits](https://www.python-httpx.org/advanced/#pool-limit-configuration)
445-
connection_pool_limits: httpx.Limits | None = None,
446408
# Enable or disable schema validation for data returned by the API.
447409
# When enabled an error APIResponseValidationError is raised
448410
# if the API responds with invalid data for the expected schema.
@@ -503,9 +465,6 @@ def __init__(
503465
max_retries=max_retries,
504466
timeout=timeout,
505467
http_client=http_client,
506-
transport=transport,
507-
proxies=proxies,
508-
limits=connection_pool_limits,
509468
custom_headers=default_headers,
510469
custom_query=default_query,
511470
_strict_response_validation=_strict_response_validation,
@@ -569,7 +528,6 @@ def copy(
569528
base_url: str | httpx.URL | None = None,
570529
timeout: float | Timeout | None | NotGiven = NOT_GIVEN,
571530
http_client: httpx.AsyncClient | None = None,
572-
connection_pool_limits: httpx.Limits | None = None,
573531
max_retries: int | NotGiven = NOT_GIVEN,
574532
default_headers: Mapping[str, str] | None = None,
575533
set_default_headers: Mapping[str, str] | None = None,
@@ -598,32 +556,14 @@ def copy(
598556
elif set_default_query is not None:
599557
params = set_default_query
600558

601-
if connection_pool_limits is not None:
602-
if http_client is not None:
603-
raise ValueError("The 'http_client' argument is mutually exclusive with 'connection_pool_limits'")
604-
605-
if not isinstance(self._client, AsyncHttpxClientWrapper):
606-
raise ValueError(
607-
"A custom HTTP client has been set and is mutually exclusive with the 'connection_pool_limits' argument"
608-
)
609-
610-
http_client = None
611-
else:
612-
if self._limits is not DEFAULT_CONNECTION_LIMITS:
613-
connection_pool_limits = self._limits
614-
else:
615-
connection_pool_limits = None
616-
617-
http_client = http_client or self._client
618-
559+
http_client = http_client or self._client
619560
return self.__class__(
620561
api_key=api_key or self.api_key,
621562
webhook_secret=webhook_secret or self.webhook_secret,
622563
base_url=base_url or self.base_url,
623564
environment=environment or self._environment,
624565
timeout=self.timeout if isinstance(timeout, NotGiven) else timeout,
625566
http_client=http_client,
626-
connection_pool_limits=connection_pool_limits,
627567
max_retries=max_retries if is_given(max_retries) else self.max_retries,
628568
default_headers=headers,
629569
default_query=params,

0 commit comments

Comments
 (0)