Skip to content
This repository was archived by the owner on Nov 8, 2024. It is now read-only.
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
22 changes: 22 additions & 0 deletions README.md
Original file line number Diff line number Diff line change
Expand Up @@ -103,6 +103,28 @@ class SegmentAssignmentLogger(AssignmentLogger):
client_config = Config(api_key="<SDK-KEY-FROM-DASHBOARD>", assignment_logger=SegmentAssignmentLogger())
```

## Export configuration

To support the use-case of needing to bootstrap a front-end client, the Eppo SDK provides a function to export flag configurations to a JSON string.

Use the `get_flag_configurations` function to export flag configurations to a JSON string and then send it to the front-end client.

```python
from fastapi import JSONResponse

import eppo_client
import json

client = eppo_client.get_instance()
flag_configurations = client.get_flag_configurations()

# Convert flag configurations to a JSON string
flag_config_json = json.dumps(flag_configurations)
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

This, flag_configurations being a dict, makes sense to me


# Create a JSONResponse object with the stringified JSON
response = JSONResponse(content={"flagConfigurations": flag_config_json})
```

## Philosophy

Eppo's SDKs are built for simplicity, speed and reliability. Flag configurations are compressed and distributed over a global CDN (Fastly), typically reaching your servers in under 15ms. Server SDKs continue polling Eppo’s API at 30-second intervals. Configurations are then cached locally, ensuring that each assignment is made instantly. Evaluation logic within each SDK consists of a few lines of simple numeric and string comparisons. The typed functions listed above are all developers need to understand, abstracting away the complexity of the Eppo's underlying (and expanding) feature set.
8 changes: 8 additions & 0 deletions eppo_client/client.py
Original file line number Diff line number Diff line change
Expand Up @@ -10,6 +10,7 @@
ContextAttributes,
ActionContexts,
)
from eppo_client.models import Flag
from eppo_client.configuration_requestor import (
ExperimentConfigurationRequestor,
)
Expand Down Expand Up @@ -386,6 +387,13 @@ def get_flag_keys(self):
"""
return self.__config_requestor.get_flag_keys()

def get_flag_configurations(self) -> Dict[str, Flag]:
"""
Returns a dictionary of all flag configurations that have been initialized.
This can be useful to debug the initialization process or to bootstrap a front-end client.
"""
return self.__config_requestor.get_flag_configurations()

def get_bandit_keys(self):
"""
Returns a list of all bandit keys that have been initialized.
Expand Down
3 changes: 3 additions & 0 deletions eppo_client/configuration_requestor.py
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,9 @@ def get_bandit_model(self, bandit_key: str) -> Optional[BanditData]:
def get_flag_keys(self):
return self.__flag_config_store.get_keys()

def get_flag_configurations(self):
return self.__flag_config_store.get_configurations()

def get_bandit_keys(self):
return self.__bandit_config_store.get_keys()

Expand Down
4 changes: 4 additions & 0 deletions eppo_client/configuration_store.py
Original file line number Diff line number Diff line change
Expand Up @@ -21,3 +21,7 @@ def set_configurations(self, configs: Dict[str, T]):
def get_keys(self):
with self.__lock.reader():
return set(self.__cache.keys())

def get_configurations(self):
with self.__lock.reader():
return self.__cache
2 changes: 1 addition & 1 deletion eppo_client/version.py
Original file line number Diff line number Diff line change
@@ -1 +1 @@
__version__ = "3.2.1"
__version__ = "3.3.0"
7 changes: 7 additions & 0 deletions test/client_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -218,6 +218,13 @@ def test_client_has_flags():
assert len(client.get_flag_keys()) > 0, "No flags have been loaded by the client"


def test_client_flag_configurations():
client = get_instance()
assert (
len(client.get_flag_configurations()) > 0
), "No flags have been loaded by the client"


@pytest.mark.parametrize("test_case", test_data)
def test_assign_subject_in_sample(test_case):
client = get_instance()
Expand Down
7 changes: 7 additions & 0 deletions test/configuration_store_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -34,6 +34,13 @@ def test_get_keys():
assert len(keys) == 2


def test_get_configurations():
config = {"flag1": mock_flag, "flag2": mock_flag}
store.set_configurations(config)
configurations = store.get_configurations()
Copy link
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

👍

assert configurations == config


def test_evicts_old_entries_when_max_size_exceeded():
store.set_configurations({"item_to_be_evicted": mock_flag})
assert store.get_configuration("item_to_be_evicted") == mock_flag
Expand Down