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

Method __init__

src/anthropic/_base_client.py:1726–1780  ·  view source on GitHub ↗
(
        self,
        *,
        version: str,
        base_url: str | URL,
        _strict_response_validation: bool,
        max_retries: int = DEFAULT_MAX_RETRIES,
        timeout: float | Timeout | None | NotGiven = not_given,
        http_client: httpx.AsyncClient | None = None,
        custom_headers: Mapping[str, str] | None = None,
        custom_query: Mapping[str, object] | None = None,
        middleware: Sequence[MiddlewareInput] | None = None,
    )

Source from the content-addressed store, hash-verified

1724 webhook_key: str | None = None
1725
1726 def __init__(
1727 self,
1728 *,
1729 version: str,
1730 base_url: str | URL,
1731 _strict_response_validation: bool,
1732 max_retries: int = DEFAULT_MAX_RETRIES,
1733 timeout: float | Timeout | None | NotGiven = not_given,
1734 http_client: httpx.AsyncClient | None = None,
1735 custom_headers: Mapping[str, str] | None = None,
1736 custom_query: Mapping[str, object] | None = None,
1737 middleware: Sequence[MiddlewareInput] | None = None,
1738 ) -> None:
1739 if not is_given(timeout):
1740 # if the user passed in a custom http client with a non-default
1741 # timeout set then we use that timeout.
1742 #
1743 # note: there is an edge case here where the user passes in a client
1744 # where they've explicitly set the timeout to match the default timeout
1745 # as this check is structural, meaning that we'll think they didn't
1746 # pass in a timeout and will ignore it
1747 if http_client and http_client.timeout != HTTPX_DEFAULT_TIMEOUT:
1748 timeout = http_client.timeout
1749 else:
1750 timeout = DEFAULT_TIMEOUT
1751
1752 if http_client is not None and not isinstance(http_client, httpx.AsyncClient): # pyright: ignore[reportUnnecessaryIsInstance]
1753 raise TypeError(
1754 f"Invalid `http_client` argument; Expected an instance of `httpx.AsyncClient` but got {type(http_client)}"
1755 )
1756
1757 # materialize the middleware before validating it so that passing an
1758 # iterator/generator doesn't result in validation consuming it and the
1759 # middleware silently never running
1760 middleware = tuple(middleware or ())
1761 if middleware:
1762 validate_async_middleware(middleware)
1763
1764 super().__init__(
1765 version=version,
1766 base_url=base_url,
1767 # cast to a valid type because mypy doesn't understand our type narrowing
1768 timeout=cast(Timeout, timeout),
1769 max_retries=max_retries,
1770 custom_query=custom_query,
1771 custom_headers=custom_headers,
1772 middleware=middleware,
1773 _strict_response_validation=_strict_response_validation,
1774 )
1775 self._middleware_chain = self._build_middleware_chain()
1776 self._client = http_client or AsyncHttpxClientWrapper(
1777 base_url=base_url,
1778 # cast to a valid type because mypy doesn't understand our type narrowing
1779 timeout=cast(Timeout, timeout),
1780 )
1781
1782 def is_closed(self) -> bool:
1783 return self._client.is_closed

Callers

nothing calls this directly

Calls 5

is_givenFunction · 0.85
__init__Method · 0.45

Tested by

no test coverage detected