Skip to content

Commit 4e3f141

Browse files
Add proxies option to Flagsmith init (#39)
1 parent 4613bc0 commit 4e3f141

File tree

2 files changed

+14
-0
lines changed

2 files changed

+14
-0
lines changed

flagsmith/flagsmith.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ def __init__(
4848
retries: Retry = None,
4949
enable_analytics: bool = False,
5050
default_flag_handler: typing.Callable[[str], DefaultFlag] = None,
51+
proxies: typing.Dict[str, str] = None,
5152
):
5253
"""
5354
:param environment_key: The environment key obtained from Flagsmith interface
@@ -66,11 +67,13 @@ def __init__(
6667
:param default_flag_handler: callable which will be used in the case where
6768
flags cannot be retrieved from the API or a non existent feature is
6869
requested
70+
:param proxies: as per https://requests.readthedocs.io/en/latest/api/#requests.Session.proxies
6971
"""
7072
self.session = requests.Session()
7173
self.session.headers.update(
7274
**{"X-Environment-Key": environment_key}, **(custom_headers or {})
7375
)
76+
self.session.proxies.update(proxies or {})
7477
retries = retries or Retry(total=3, backoff_factor=0.1)
7578

7679
self.api_url = api_url if api_url.endswith("/") else f"{api_url}/"

tests/test_flagsmith.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -367,3 +367,14 @@ def test_get_identity_segments_with_valid_trait(
367367
def test_local_evaluation_requires_server_key():
368368
with pytest.raises(ValueError):
369369
Flagsmith(environment_key="not-a-server-key", enable_local_evaluation=True)
370+
371+
372+
def test_initialise_flagsmith_with_proxies():
373+
# Given
374+
proxies = {"https": "https://my.proxy.com/proxy-me"}
375+
376+
# When
377+
flagsmith = Flagsmith(environment_key="test-key", proxies=proxies)
378+
379+
# Then
380+
assert flagsmith.session.proxies == proxies

0 commit comments

Comments
 (0)