Skip to content

Commit 1a9d04e

Browse files
author
Dave Johnston
authored
Merge pull request #30 from davejohnston/FFM-3364-default-config
[FFM-3364]: Add default config options for python
2 parents 19adda5 + cf6bb11 commit 1a9d04e

File tree

3 files changed

+42
-3
lines changed

3 files changed

+42
-3
lines changed

README.md

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ def main():
6363
client = CfClient(apiKey)
6464

6565
# Create a target (different targets can get different results based on rules. This include a custom attribute 'location')
66-
target = Target(identifier='mytarget', name="FriendlyName", attributes={"location": "emea"}
66+
target = Target(identifier='pythonSDK', name="PythonSDK", attributes={"location": "emea"})
6767

6868
# Loop forever reporting the state of the flag
6969
while True:

docs/further_reading.md

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,42 @@
22

33
Covers advanced topics (different config options and scenarios)
44

5+
## Configuration Options
6+
The following configuration options are available to control the behaviour of the SDK.
7+
You can pass the configuration in as options when the SDK client is created.
8+
```python
9+
# Create a Feature Flag Client
10+
client = CfClient(apiKey,
11+
with_base_url("https://config.ff.harness.io/api/1.0"),
12+
with_events_url("https://events.ff.harness.io/api/1.0"),
13+
with_stream_enabled(True),
14+
with_analytics_enabled(True),
15+
Config(pull_interval=60))
16+
```
17+
18+
| Name | Config Option | Description | default |
19+
|-----------------|----------------------------------------------------------|--------------------------------------------------------------------------------------------------------------------------------------------------|--------------------------------------|
20+
| baseUrl | with_base_url("https://config.ff.harness.io/api/1.0") | the URL used to fetch feature flag evaluations. You should change this when using the Feature Flag proxy to http://localhost:7000 | https://config.ff.harness.io/api/1.0 |
21+
| eventsUrl | with_events_url("https://events.ff.harness.io/api/1.0"), | the URL used to post metrics data to the feature flag service. You should change this when using the Feature Flag proxy to http://localhost:7000 | https://events.ff.harness.io/api/1.0 |
22+
| pollInterval | Config(pull_interval=60) | when running in stream mode, the interval in seconds that we poll for changes. | 60 |
23+
| enableStream | with_stream_enabled(True), | Enable streaming mode. | true |
24+
| enableAnalytics | with_analytics_enabled(True) | Enable analytics. Metrics data is posted every 60s | true |
25+
26+
## Logging Configuration
27+
The SDK provides a logger that wraps the standard python logging package. You can import and use it with:
28+
```python
29+
from featureflags.util import log
30+
log.info("Hello, World!")
31+
```
32+
33+
If you want to change the default log level, you can use the standard logging levels
34+
```python
35+
from featureflags.util import log
36+
import logging
37+
38+
log.setLevel(logging.WARN)
39+
```
40+
541
## Recommended reading
642

743
[Feature Flag Concepts](https://ngdocs.harness.io/article/7n9433hkc0-cf-feature-flag-overview)

examples/getting_started/getting_started.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,18 +5,21 @@
55
import os
66
import time
77

8+
89
# API Key
9-
apiKey = os.getenv('FF_API_KEY', "c9b3f14f-6336-4d23-83b4-73f29d1ebeeb")
10+
apiKey = os.getenv('FF_API_KEY', "")
1011

1112
# Flag Name
1213
flagName = os.getenv('FF_FLAG_NAME', "harnessappdemodarkmode")
1314

1415
def main():
16+
log.info("Harness SDK Getting Started")
1517
# Create a Feature Flag Client
1618
client = CfClient(apiKey)
1719

20+
1821
# Create a target (different targets can get different results based on rules)
19-
target = Target(identifier='mytarget', name="FriendlyName", attributes={"location": "emea"})
22+
target = Target(identifier='pythonSDK', name="PythonSDK", attributes={"location": "emea"})
2023

2124
# Loop forever reporting the state of the flag
2225
while True:

0 commit comments

Comments
 (0)