Skip to content

Commit b6192da

Browse files
committed
Release 0.0.14
1 parent 28f1e88 commit b6192da

File tree

3 files changed

+85
-22
lines changed

3 files changed

+85
-22
lines changed

pyproject.toml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,6 @@
11
[tool.poetry]
22
name = "fileforge"
3-
version = "0.1.5"
3+
version = "0.0.14"
44
description = ""
55
readme = "README.md"
66
authors = []

src/fileforge/client.py

Lines changed: 36 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,5 @@
11
# This file was auto-generated by Fern from our API Definition.
22

3-
import os
43
import typing
54
import urllib.parse
65
from json.decoder import JSONDecodeError
@@ -47,7 +46,9 @@ class Fileforge:
4746
4847
4948
50-
api_key : typing.Optional[str]
49+
api_key : str
50+
username : typing.Optional[typing.Union[str, typing.Callable[[], str]]]
51+
password : typing.Optional[typing.Union[str, typing.Callable[[], str]]]
5152
timeout : typing.Optional[float]
5253
The timeout to be used, in seconds, for requests by default the timeout is 60 seconds, unless a custom httpx client is used, in which case a default is not set.
5354
@@ -63,6 +64,8 @@ class Fileforge:
6364
6465
client = Fileforge(
6566
api_key="YOUR_API_KEY",
67+
username="YOUR_USERNAME",
68+
password="YOUR_PASSWORD",
6669
)
6770
"""
6871

@@ -71,19 +74,19 @@ def __init__(
7174
*,
7275
base_url: typing.Optional[str] = None,
7376
environment: FileforgeEnvironment = FileforgeEnvironment.DEFAULT,
74-
api_key: typing.Optional[str] = os.getenv("FILEFORGE_API_KEY"),
77+
api_key: str,
78+
username: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
79+
password: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
7580
timeout: typing.Optional[float] = None,
7681
follow_redirects: typing.Optional[bool] = True,
7782
httpx_client: typing.Optional[httpx.Client] = None,
7883
):
7984
_defaulted_timeout = timeout if timeout is not None else 60 if httpx_client is None else None
80-
if api_key is None:
81-
raise ApiError(
82-
body="The client must be instantiated be either passing in api_key or setting FILEFORGE_API_KEY"
83-
)
8485
self._client_wrapper = SyncClientWrapper(
8586
base_url=_get_base_url(base_url=base_url, environment=environment),
8687
api_key=api_key,
88+
username=username,
89+
password=password,
8790
httpx_client=httpx_client
8891
if httpx_client is not None
8992
else httpx.Client(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
@@ -109,6 +112,8 @@ def retrieve_server_status(self, *, request_options: typing.Optional[RequestOpti
109112
110113
client = Fileforge(
111114
api_key="YOUR_API_KEY",
115+
username="YOUR_USERNAME",
116+
password="YOUR_PASSWORD",
112117
)
113118
client.retrieve_server_status()
114119
"""
@@ -212,6 +217,8 @@ def convert_docx(
212217
213218
client = Fileforge(
214219
api_key="YOUR_API_KEY",
220+
username="YOUR_USERNAME",
221+
password="YOUR_PASSWORD",
215222
)
216223
client.convert_docx()
217224
"""
@@ -293,6 +300,8 @@ def generate(
293300
294301
client = Fileforge(
295302
api_key="YOUR_API_KEY",
303+
username="YOUR_USERNAME",
304+
password="YOUR_PASSWORD",
296305
)
297306
client.generate()
298307
"""
@@ -373,6 +382,8 @@ def merge(
373382
374383
client = Fileforge(
375384
api_key="YOUR_API_KEY",
385+
username="YOUR_USERNAME",
386+
password="YOUR_PASSWORD",
376387
)
377388
client.merge()
378389
"""
@@ -441,7 +452,9 @@ class AsyncFileforge:
441452
442453
443454
444-
api_key : typing.Optional[str]
455+
api_key : str
456+
username : typing.Optional[typing.Union[str, typing.Callable[[], str]]]
457+
password : typing.Optional[typing.Union[str, typing.Callable[[], str]]]
445458
timeout : typing.Optional[float]
446459
The timeout to be used, in seconds, for requests by default the timeout is 60 seconds, unless a custom httpx client is used, in which case a default is not set.
447460
@@ -457,6 +470,8 @@ class AsyncFileforge:
457470
458471
client = AsyncFileforge(
459472
api_key="YOUR_API_KEY",
473+
username="YOUR_USERNAME",
474+
password="YOUR_PASSWORD",
460475
)
461476
"""
462477

@@ -465,19 +480,19 @@ def __init__(
465480
*,
466481
base_url: typing.Optional[str] = None,
467482
environment: FileforgeEnvironment = FileforgeEnvironment.DEFAULT,
468-
api_key: typing.Optional[str] = os.getenv("FILEFORGE_API_KEY"),
483+
api_key: str,
484+
username: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
485+
password: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
469486
timeout: typing.Optional[float] = None,
470487
follow_redirects: typing.Optional[bool] = True,
471488
httpx_client: typing.Optional[httpx.AsyncClient] = None,
472489
):
473490
_defaulted_timeout = timeout if timeout is not None else 60 if httpx_client is None else None
474-
if api_key is None:
475-
raise ApiError(
476-
body="The client must be instantiated be either passing in api_key or setting FILEFORGE_API_KEY"
477-
)
478491
self._client_wrapper = AsyncClientWrapper(
479492
base_url=_get_base_url(base_url=base_url, environment=environment),
480493
api_key=api_key,
494+
username=username,
495+
password=password,
481496
httpx_client=httpx_client
482497
if httpx_client is not None
483498
else httpx.AsyncClient(timeout=_defaulted_timeout, follow_redirects=follow_redirects)
@@ -503,6 +518,8 @@ async def retrieve_server_status(self, *, request_options: typing.Optional[Reque
503518
504519
client = AsyncFileforge(
505520
api_key="YOUR_API_KEY",
521+
username="YOUR_USERNAME",
522+
password="YOUR_PASSWORD",
506523
)
507524
await client.retrieve_server_status()
508525
"""
@@ -606,6 +623,8 @@ async def convert_docx(
606623
607624
client = AsyncFileforge(
608625
api_key="YOUR_API_KEY",
626+
username="YOUR_USERNAME",
627+
password="YOUR_PASSWORD",
609628
)
610629
await client.convert_docx()
611630
"""
@@ -687,6 +706,8 @@ async def generate(
687706
688707
client = AsyncFileforge(
689708
api_key="YOUR_API_KEY",
709+
username="YOUR_USERNAME",
710+
password="YOUR_PASSWORD",
690711
)
691712
await client.generate()
692713
"""
@@ -767,6 +788,8 @@ async def merge(
767788
768789
client = AsyncFileforge(
769790
api_key="YOUR_API_KEY",
791+
username="YOUR_USERNAME",
792+
password="YOUR_PASSWORD",
770793
)
771794
await client.merge()
772795
"""

src/fileforge/core/client_wrapper.py

Lines changed: 48 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -8,20 +8,46 @@
88

99

1010
class BaseClientWrapper:
11-
def __init__(self, *, api_key: str, base_url: str, timeout: typing.Optional[float] = None):
12-
self.api_key = api_key
11+
def __init__(
12+
self,
13+
*,
14+
api_key: str,
15+
username: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
16+
password: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
17+
base_url: str,
18+
timeout: typing.Optional[float] = None
19+
):
20+
self._api_key = api_key
21+
self._username = username
22+
self._password = password
1323
self._base_url = base_url
1424
self._timeout = timeout
1525

1626
def get_headers(self) -> typing.Dict[str, str]:
1727
headers: typing.Dict[str, str] = {
1828
"X-Fern-Language": "Python",
1929
"X-Fern-SDK-Name": "fileforge",
20-
"X-Fern-SDK-Version": "0.1.5",
30+
"X-Fern-SDK-Version": "0.0.14",
2131
}
22-
headers["X-API-Key"] = self.api_key
32+
username = self._get_username()
33+
password = self._get_password()
34+
if username is not None and password is not None:
35+
headers["Authorization"] = httpx.BasicAuth(username, password)._auth_header
36+
headers["X-API-Key"] = self._api_key
2337
return headers
2438

39+
def _get_username(self) -> typing.Optional[str]:
40+
if isinstance(self._username, str) or self._username is None:
41+
return self._username
42+
else:
43+
return self._username()
44+
45+
def _get_password(self) -> typing.Optional[str]:
46+
if isinstance(self._password, str) or self._password is None:
47+
return self._password
48+
else:
49+
return self._password()
50+
2551
def get_base_url(self) -> str:
2652
return self._base_url
2753

@@ -31,15 +57,29 @@ def get_timeout(self) -> typing.Optional[float]:
3157

3258
class SyncClientWrapper(BaseClientWrapper):
3359
def __init__(
34-
self, *, api_key: str, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.Client
60+
self,
61+
*,
62+
api_key: str,
63+
username: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
64+
password: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
65+
base_url: str,
66+
timeout: typing.Optional[float] = None,
67+
httpx_client: httpx.Client
3568
):
36-
super().__init__(api_key=api_key, base_url=base_url, timeout=timeout)
69+
super().__init__(api_key=api_key, username=username, password=password, base_url=base_url, timeout=timeout)
3770
self.httpx_client = HttpClient(httpx_client=httpx_client)
3871

3972

4073
class AsyncClientWrapper(BaseClientWrapper):
4174
def __init__(
42-
self, *, api_key: str, base_url: str, timeout: typing.Optional[float] = None, httpx_client: httpx.AsyncClient
75+
self,
76+
*,
77+
api_key: str,
78+
username: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
79+
password: typing.Optional[typing.Union[str, typing.Callable[[], str]]] = None,
80+
base_url: str,
81+
timeout: typing.Optional[float] = None,
82+
httpx_client: httpx.AsyncClient
4383
):
44-
super().__init__(api_key=api_key, base_url=base_url, timeout=timeout)
84+
super().__init__(api_key=api_key, username=username, password=password, base_url=base_url, timeout=timeout)
4585
self.httpx_client = AsyncHttpClient(httpx_client=httpx_client)

0 commit comments

Comments
 (0)