-
Notifications
You must be signed in to change notification settings - Fork 2
Expand file tree
/
Copy pathclient_wrapper.py
More file actions
55 lines (44 loc) · 1.79 KB
/
client_wrapper.py
File metadata and controls
55 lines (44 loc) · 1.79 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
# This file was auto-generated by Fern from our API Definition.
import typing
import httpx
from .http_client import AsyncHttpClient, HttpClient
class BaseClientWrapper:
def __init__(self, *, api_key: str, base_url: str, timeout: typing.Optional[float] = None):
self.api_key = api_key
self._base_url = base_url
self._timeout = timeout
def get_headers(self) -> typing.Dict[str, str]:
headers: typing.Dict[str, str] = {
"User-Agent": "humanloop/0.8.40b6",
"X-Fern-Language": "Python",
"X-Fern-SDK-Name": "humanloop",
"X-Fern-SDK-Version": "0.8.40b6",
}
headers["X-API-KEY"] = self.api_key
return headers
def get_base_url(self) -> str:
return self._base_url
def get_timeout(self) -> typing.Optional[float]:
return self._timeout
class SyncClientWrapper(BaseClientWrapper):
def __init__(
self, *, api_key: str, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client
):
super().__init__(api_key=api_key, base_url=base_url, timeout=timeout)
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, *, api_key: str, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient
):
super().__init__(api_key=api_key, base_url=base_url, timeout=timeout)
self.httpx_client = AsyncHttpClient(
httpx_client=httpx_client,
base_headers=self.get_headers,
base_timeout=self.get_timeout,
base_url=self.get_base_url,
)