MCPcopy Create free account
hub / github.com/OpenPipe/OpenPipe / AuthenticatedClient

Class AuthenticatedClient

trainer/src/api_client/client.py:136–268  ·  view source on GitHub ↗

A Client which has been authenticated for use on secured endpoints The following are accepted as keyword arguments and will be used to construct httpx Clients internally: ``base_url``: The base URL for the API, all requests are made to a relative path to this URL ``cookies``:

Source from the content-addressed store, hash-verified

134
135@define
136class AuthenticatedClient:
137 """A Client which has been authenticated for use on secured endpoints
138
139 The following are accepted as keyword arguments and will be used to construct httpx Clients internally:
140
141 ``base_url``: The base URL for the API, all requests are made to a relative path to this URL
142
143 ``cookies``: A dictionary of cookies to be sent with every request
144
145 ``headers``: A dictionary of headers to be sent with every request
146
147 ``timeout``: The maximum amount of a time a request can take. API functions will raise
148 httpx.TimeoutException if this is exceeded.
149
150 ``verify_ssl``: Whether or not to verify the SSL certificate of the API server. This should be True in production,
151 but can be set to False for testing purposes.
152
153 ``follow_redirects``: Whether or not to follow redirects. Default value is False.
154
155 ``httpx_args``: A dictionary of additional arguments to be passed to the ``httpx.Client`` and ``httpx.AsyncClient`` constructor.
156
157
158 Attributes:
159 raise_on_unexpected_status: Whether or not to raise an errors.UnexpectedStatus if the API returns a
160 status code that was not documented in the source OpenAPI document. Can also be provided as a keyword
161 argument to the constructor.
162 token: The token to use for authentication
163 prefix: The prefix to use for the Authorization header
164 auth_header_name: The name of the Authorization header
165 """
166
167 raise_on_unexpected_status: bool = field(default=False, kw_only=True)
168 _base_url: str
169 _cookies: Dict[str, str] = field(factory=dict, kw_only=True)
170 _headers: Dict[str, str] = field(factory=dict, kw_only=True)
171 _timeout: Optional[httpx.Timeout] = field(default=None, kw_only=True)
172 _verify_ssl: Union[str, bool, ssl.SSLContext] = field(default=True, kw_only=True)
173 _follow_redirects: bool = field(default=False, kw_only=True)
174 _httpx_args: Dict[str, Any] = field(factory=dict, kw_only=True)
175 _client: Optional[httpx.Client] = field(default=None, init=False)
176 _async_client: Optional[httpx.AsyncClient] = field(default=None, init=False)
177
178 token: str
179 prefix: str = "Bearer"
180 auth_header_name: str = "Authorization"
181
182 def with_headers(self, headers: Dict[str, str]) -> "AuthenticatedClient":
183 """Get a new client matching this one with additional headers"""
184 if self._client is not None:
185 self._client.headers.update(headers)
186 if self._async_client is not None:
187 self._async_client.headers.update(headers)
188 return evolve(self, headers={**self._headers, **headers})
189
190 def with_cookies(self, cookies: Dict[str, str]) -> "AuthenticatedClient":
191 """Get a new client matching this one with additional cookies"""
192 if self._client is not None:
193 self._client.cookies.update(cookies)

Callers 3

test_client.pyFile · 0.90
clientFunction · 0.85
do_trainFunction · 0.85

Calls

no outgoing calls

Tested by

no test coverage detected