Skip to content

Commit deda3e6

Browse files
feat: support setting headers via env
1 parent b02dee5 commit deda3e6

1 file changed

Lines changed: 23 additions & 1 deletion

File tree

src/studio_sdk/_client.py

Lines changed: 23 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -19,7 +19,11 @@
1919
RequestOptions,
2020
not_given,
2121
)
22-
from ._utils import is_given, get_async_library
22+
from ._utils import (
23+
is_given,
24+
is_mapping_t,
25+
get_async_library,
26+
)
2327
from ._compat import cached_property
2428
from ._version import __version__
2529
from ._streaming import Stream as Stream, AsyncStream as AsyncStream
@@ -122,6 +126,15 @@ def __init__(
122126
except KeyError as exc:
123127
raise ValueError(f"Unknown environment: {environment}") from exc
124128

129+
custom_headers_env = os.environ.get("STUDIO_SDK_CUSTOM_HEADERS")
130+
if custom_headers_env is not None:
131+
parsed: dict[str, str] = {}
132+
for line in custom_headers_env.split("\n"):
133+
colon = line.find(":")
134+
if colon >= 0:
135+
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
136+
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}
137+
125138
super().__init__(
126139
version=__version__,
127140
base_url=base_url,
@@ -334,6 +347,15 @@ def __init__(
334347
except KeyError as exc:
335348
raise ValueError(f"Unknown environment: {environment}") from exc
336349

350+
custom_headers_env = os.environ.get("STUDIO_SDK_CUSTOM_HEADERS")
351+
if custom_headers_env is not None:
352+
parsed: dict[str, str] = {}
353+
for line in custom_headers_env.split("\n"):
354+
colon = line.find(":")
355+
if colon >= 0:
356+
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
357+
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}
358+
337359
super().__init__(
338360
version=__version__,
339361
base_url=base_url,

0 commit comments

Comments
 (0)