MCPcopy
hub / github.com/anthropics/anthropic-sdk-python / __init__

Method __init__

src/anthropic/_base_client.py:907–952  ·  view source on GitHub ↗
(self, **kwargs: Any)

Source from the content-addressed store, hash-verified

905
906class _DefaultHttpxClient(httpx.Client):
907 def __init__(self, **kwargs: Any) -> None:
908 kwargs.setdefault("timeout", DEFAULT_TIMEOUT)
909 kwargs.setdefault("limits", DEFAULT_CONNECTION_LIMITS)
910 kwargs.setdefault("follow_redirects", True)
911
912 if "transport" not in kwargs:
913 socket_options: List[Tuple[int, int, Union[int, bool]]] = [(socket.SOL_SOCKET, socket.SO_KEEPALIVE, True)]
914
915 TCP_KEEPINTVL = getattr(socket, "TCP_KEEPINTVL", None)
916
917 if TCP_KEEPINTVL is not None:
918 socket_options.append((socket.IPPROTO_TCP, TCP_KEEPINTVL, 60))
919 elif sys.platform == "darwin":
920 TCP_KEEPALIVE = getattr(socket, "TCP_KEEPALIVE", 0x10)
921 socket_options.append((socket.IPPROTO_TCP, TCP_KEEPALIVE, 60))
922
923 TCP_KEEPCNT = getattr(socket, "TCP_KEEPCNT", None)
924 if TCP_KEEPCNT is not None:
925 socket_options.append((socket.IPPROTO_TCP, TCP_KEEPCNT, 5))
926
927 TCP_KEEPIDLE = getattr(socket, "TCP_KEEPIDLE", None)
928 if TCP_KEEPIDLE is not None:
929 socket_options.append((socket.IPPROTO_TCP, TCP_KEEPIDLE, 60))
930
931 proxy_map = {key: None if url is None else Proxy(url=url) for key, url in get_environment_proxies().items()}
932
933 transport_kwargs = {
934 arg: kwargs[arg] for arg in ("verify", "cert", "trust_env", "http1", "http2", "limits") if arg in kwargs
935 }
936
937 transport_kwargs["socket_options"] = socket_options
938
939 proxy_mounts = {
940 key: None if proxy is None else HTTPTransport(proxy=proxy, **transport_kwargs)
941 for key, proxy in proxy_map.items()
942 }
943 default_transport = HTTPTransport(**transport_kwargs)
944
945 # Prioritize the mounts set by the user over the environment variables.
946 proxy_mounts.update(kwargs.get("mounts", {}))
947 kwargs["mounts"] = proxy_mounts
948
949 # Sets the default transport so that HTTPX won't automatically configure proxies.
950 kwargs["transport"] = default_transport
951
952 super().__init__(**kwargs)
953
954
955if TYPE_CHECKING:

Callers

nothing calls this directly

Calls 4

get_environment_proxiesFunction · 0.85
updateMethod · 0.45
getMethod · 0.45
__init__Method · 0.45

Tested by

no test coverage detected