Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 3 additions & 0 deletions flagsmith/flagsmith.py
Original file line number Diff line number Diff line change
Expand Up @@ -48,6 +48,7 @@ def __init__(
retries: Retry = None,
enable_analytics: bool = False,
default_flag_handler: typing.Callable[[str], DefaultFlag] = None,
proxies: typing.Dict[str, str] = None,
):
"""
:param environment_key: The environment key obtained from Flagsmith interface
Expand All @@ -66,11 +67,13 @@ def __init__(
:param default_flag_handler: callable which will be used in the case where
flags cannot be retrieved from the API or a non existent feature is
requested
:param proxies: as per https://requests.readthedocs.io/en/latest/api/#requests.Session.proxies
"""
self.session = requests.Session()
self.session.headers.update(
**{"X-Environment-Key": environment_key}, **(custom_headers or {})
)
self.session.proxies.update(proxies or {})
retries = retries or Retry(total=3, backoff_factor=0.1)

self.api_url = api_url if api_url.endswith("/") else f"{api_url}/"
Expand Down
11 changes: 11 additions & 0 deletions tests/test_flagsmith.py
Original file line number Diff line number Diff line change
Expand Up @@ -367,3 +367,14 @@ def test_get_identity_segments_with_valid_trait(
def test_local_evaluation_requires_server_key():
with pytest.raises(ValueError):
Flagsmith(environment_key="not-a-server-key", enable_local_evaluation=True)


def test_initialise_flagsmith_with_proxies():
# Given
proxies = {"https": "https://my.proxy.com/proxy-me"}

# When
flagsmith = Flagsmith(environment_key="test-key", proxies=proxies)

# Then
assert flagsmith.session.proxies == proxies