Skip to content

Commit 6dd2b05

Browse files
feat: support setting headers via env
1 parent 1e34228 commit 6dd2b05

1 file changed

Lines changed: 19 additions & 0 deletions

File tree

src/parallel/_client.py

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -27,6 +27,7 @@
2727
)
2828
from ._utils import (
2929
is_given,
30+
is_mapping_t,
3031
maybe_transform,
3132
get_async_library,
3233
async_maybe_transform,
@@ -113,6 +114,15 @@ def __init__(
113114
if base_url is None:
114115
base_url = f"https://api.parallel.ai"
115116

117+
custom_headers_env = os.environ.get("PARALLEL_CUSTOM_HEADERS")
118+
if custom_headers_env is not None:
119+
parsed: dict[str, str] = {}
120+
for line in custom_headers_env.split("\n"):
121+
colon = line.find(":")
122+
if colon >= 0:
123+
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
124+
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}
125+
116126
super().__init__(
117127
version=__version__,
118128
base_url=base_url,
@@ -464,6 +474,15 @@ def __init__(
464474
if base_url is None:
465475
base_url = f"https://api.parallel.ai"
466476

477+
custom_headers_env = os.environ.get("PARALLEL_CUSTOM_HEADERS")
478+
if custom_headers_env is not None:
479+
parsed: dict[str, str] = {}
480+
for line in custom_headers_env.split("\n"):
481+
colon = line.find(":")
482+
if colon >= 0:
483+
parsed[line[:colon].strip()] = line[colon + 1 :].strip()
484+
default_headers = {**parsed, **(default_headers if is_mapping_t(default_headers) else {})}
485+
467486
super().__init__(
468487
version=__version__,
469488
base_url=base_url,

0 commit comments

Comments
 (0)