|
1 |
| -# Eppo SDK for Python |
| 1 | +# Eppo Python SDK |
2 | 2 |
|
3 |
| -## Getting Started |
| 3 | +[](https://github.com/Eppo-exp/python-sdk/actions/workflows/test-and-lint-sdk.yml) |
4 | 4 |
|
5 |
| -Refer to our [SDK documentation](https://docs.geteppo.com/feature-flags/sdks/python) for how to install and use the SDK. |
| 5 | +[Eppo](https://www.geteppo.com/) is a modular flagging and experimentation analysis tool. Eppo's Python SDK is built to make assignments in multi-user server side contexts. Before proceeding you'll need an Eppo account. |
6 | 6 |
|
7 |
| -## Supported Python Versions |
| 7 | +## Features |
8 | 8 |
|
9 |
| -This version of the SDK is compatible with Python 3.6 and above. |
| 9 | +- Feature gates |
| 10 | +- Kill switches |
| 11 | +- Progressive rollouts |
| 12 | +- A/B/n experiments |
| 13 | +- Mutually exclusive experiments (Layers) |
| 14 | +- Dynamic configuration |
10 | 15 |
|
11 |
| -## Development |
| 16 | +## Installation |
12 | 17 |
|
13 |
| -### Running tests |
| 18 | +```shell |
| 19 | +pip install eppo-server-sdk |
| 20 | +``` |
14 | 21 |
|
15 |
| -`make test` |
| 22 | +## Quick start |
| 23 | + |
| 24 | +Begin by initializing a singleton instance of Eppo's client. Once initialized, the client can be used to make assignments anywhere in your app. |
| 25 | + |
| 26 | +#### Initialize once |
| 27 | + |
| 28 | +```python |
| 29 | +import eppo_client |
| 30 | +from eppo_client.config import Config, AssignmentLogger |
| 31 | + |
| 32 | +client_config = Config(api_key="<SDK-KEY-FROM-DASHBOARD>") |
| 33 | +eppo_client.init(client_config) |
| 34 | +``` |
| 35 | + |
| 36 | + |
| 37 | +#### Assign anywhere |
| 38 | + |
| 39 | +```python |
| 40 | +import eppo_client |
| 41 | + |
| 42 | +client = eppo_client.get_instance() |
| 43 | +user = get_current_user() |
| 44 | + |
| 45 | +variation = eppoClient.get_boolean_assignment( |
| 46 | + 'show-new-feature', |
| 47 | + user.id, |
| 48 | + { 'country': user.country }, |
| 49 | + False |
| 50 | +) |
| 51 | +``` |
| 52 | + |
| 53 | +## Assignment functions |
| 54 | + |
| 55 | +Every Eppo flag has a return type that is set once on creation in the dashboard. Once a flag is created, assignments in code should be made using the corresponding typed function: |
| 56 | + |
| 57 | +```python |
| 58 | +get_boolean_assignment(...) |
| 59 | +get_numeric_assignment(...) |
| 60 | +get_integer_assignment(...) |
| 61 | +get_string_assignment(...) |
| 62 | +get_json_assignment(...) |
| 63 | +``` |
| 64 | + |
| 65 | +Each function has the same signature, but returns the type in the function name. For booleans use `get_boolean_assignment`, which has the following signature: |
| 66 | + |
| 67 | +```python |
| 68 | +get_boolean_assignment( |
| 69 | + flag_key: str, |
| 70 | + subject_key: str, |
| 71 | + subject_attributes: Dict[str, Any], |
| 72 | + default_value: bool |
| 73 | +) -> bool: |
| 74 | + ``` |
| 75 | + |
| 76 | +## Initialization options |
| 77 | + |
| 78 | +The `init` function accepts the following optional configuration arguments. |
| 79 | + |
| 80 | +| Option | Type | Description | Default | |
| 81 | +| ------ | ----- | ----- | ----- | |
| 82 | +| **`assignment_logger`** | [AssignmentLogger](https://github.com/Eppo-exp/python-sdk/blob/ebc1a0b781769fe9d2e2be6fc81779eb8685a6c7/eppo_client/assignment_logger.py#L6-L10) | A callback that sends each assignment to your data warehouse. Required only for experiment analysis. See [example](#assignment-logger) below. | `None` | |
| 83 | +| **`is_graceful_mode`** | bool | When true, gracefully handles all exceptions within the assignment function and returns the default value. | `True` | |
| 84 | + |
| 85 | + |
| 86 | +## Assignment logger |
| 87 | + |
| 88 | +To use the Eppo SDK for experiments that require analysis, pass in a callback logging function to the `init` function on SDK initialization. The SDK invokes the callback to capture assignment data whenever a variation is assigned. The assignment data is needed in the warehouse to perform analysis. |
| 89 | + |
| 90 | +The code below illustrates an example implementation of a logging callback using [Segment](https://segment.com/), but you can use any system you'd like. The only requirement is that the SDK receives a `log_assignment` callback function. Here we define an implementation of the Eppo `SegmentAssignmentLogger` interface containing a single function named `log_assignment`: |
| 91 | + |
| 92 | +```python |
| 93 | +from eppo_client.assignment_logger import AssignmentLogger |
| 94 | +import analytics |
| 95 | + |
| 96 | +# Connect to Segment. |
| 97 | +analytics.write_key = "<SEGMENT_WRITE_KEY>" |
| 98 | + |
| 99 | +class SegmentAssignmentLogger(AssignmentLogger): |
| 100 | + def log_assignment(self, assignment): |
| 101 | + analytics.track(assignment["subject"], "Eppo Randomization Assignment", assignment) |
| 102 | + |
| 103 | +client_config = Config(api_key="<SDK-KEY-FROM-DASHBOARD>", assignment_logger=SegmentAssignmentLogger()) |
| 104 | +``` |
| 105 | + |
| 106 | +## Philosophy |
| 107 | + |
| 108 | +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. |
0 commit comments