1
- Optimizely Python SDK
2
- =====================
1
+ # Optimizely Python SDK
3
2
4
3
[ ![ PyPI version] ( https://badge.fury.io/py/optimizely-sdk.svg )] ( https://pypi.org/project/optimizely-sdk )
5
4
[ ![ Build Status] ( https://travis-ci.org/optimizely/python-sdk.svg?branch=master )] ( https://travis-ci.org/optimizely/python-sdk )
@@ -23,8 +22,7 @@ Mitigate risk for every feature on your roadmap. Learn more at
23
22
< https://www.optimizely.com/rollouts/ > , or see the [ Rollouts
24
23
documentation] ( https://docs.developers.optimizely.com/rollouts/docs ) .
25
24
26
- Getting Started
27
- ---------------
25
+ ## Getting Started
28
26
29
27
### Installing the SDK
30
28
@@ -46,7 +44,7 @@ You can initialize the Optimizely instance in three ways: with a datafile, by pr
46
44
Each method is described below.
47
45
48
46
1 . Initialize Optimizely with a datafile. This datafile will be used as
49
- the source of ProjectConfig throughout the life of Optimizely instance. :
47
+ the source of ProjectConfig throughout the life of Optimizely instance:
50
48
51
49
optimizely.Optimizely(
52
50
datafile
@@ -59,43 +57,43 @@ Each method is described below.
59
57
project datafile at regular intervals and update ProjectConfig when
60
58
a new datafile is received. A hard-coded datafile can also be
61
59
provided along with the sdk_key that will be used
62
- initially before any update. :
60
+ initially before any update:
63
61
64
62
optimizely.Optimizely(
65
63
sdk_key='put_your_sdk_key_here'
66
64
)
67
65
68
- If providing a datafile, the initialization will look like: :
66
+ If providing a datafile, the initialization will look like:
69
67
70
68
optimizely.Optimizely(
71
69
datafile=datafile,
72
70
sdk_key='put_your_sdk_key_here'
73
71
)
74
72
75
73
3 . Initialize Optimizely by providing a ConfigManager that implements
76
- [ BaseConfigManager] ( https://github.com/optimizely/python-sdk/tree/master/optimizely/config_manager.py#L32 ) .
77
- You may use our [ PollingConfigManager] ( https://github.com/optimizely/python-sdk/blob/master/optimizely/config_manager.py#L151 ) as needed. :
74
+ [ BaseConfigManager] ( https://github.com/optimizely/python-sdk/tree/master/optimizely/config_manager.py#L34 ) .
75
+ You may use our [ PollingConfigManager] ( https://github.com/optimizely/python-sdk/blob/master/optimizely/config_manager.py#L150 ) or
76
+ [ AuthDatafilePollingConfigManager] ( https://github.com/optimizely/python-sdk/blob/master/optimizely/config_manager.py#L375 ) as needed:
78
77
79
78
optimizely.Optimizely(
80
79
config_manager=custom_config_manager
81
80
)
82
81
83
82
#### PollingConfigManager
84
83
85
- The [ PollingConfigManager] ( https://github.com/optimizely/python-sdk/blob/master/optimizely/config_manager.py#L151 ) asynchronously polls for
86
- datafiles from a specified URL at regular intervals by making HTTP
87
- requests.
84
+ The [ PollingConfigManager] ( https://github.com/optimizely/python-sdk/blob/master/optimizely/config_manager.py#L150 ) asynchronously polls for
85
+ datafiles from a specified URL at regular intervals by making HTTP requests.
88
86
89
87
polling_config_manager = PollingConfigManager(
90
88
sdk_key=None,
91
- datafile=None,
92
- update_interval=None,
93
- url=None,
89
+ datafile=None,
90
+ update_interval=None,
91
+ url=None,
94
92
url_template=None,
95
- logger=None,
96
- error_handler=None,
93
+ logger=None,
94
+ error_handler=None,
97
95
notification_center=None,
98
- skip_json_validation=False
96
+ skip_json_validation=False
99
97
)
100
98
101
99
** Note** : You must provide either the sdk_key or URL. If
@@ -113,38 +111,57 @@ successful datafile poll.
113
111
** update_interval** The update_interval is used to specify a fixed
114
112
delay in seconds between consecutive HTTP requests for the datafile.
115
113
114
+ ** url** The target URL from which to request the datafile.
115
+
116
116
** url_template** A string with placeholder ` {sdk_key} ` can be provided
117
117
so that this template along with the provided sdk key is
118
118
used to form the target URL.
119
119
120
120
You may also provide your own logger, error_handler, or
121
121
notification_center.
122
122
123
+ #### AuthDatafilePollingConfigManager
124
+
125
+ The [ AuthDatafilePollingConfigManager] ( https://github.com/optimizely/python-sdk/blob/master/optimizely/config_manager.py#L375 )
126
+ implements ` PollingConfigManager ` and asynchronously polls for authenticated datafiles from a specified URL at regular intervals
127
+ by making HTTP requests.
128
+
129
+ auth_datafile_polling_config_manager = AuthDatafilePollingConfigManager(
130
+ access_token,
131
+ *args,
132
+ **kwargs
133
+ )
134
+
135
+ ** Note** : To use [ AuthDatafilePollingConfigManager] ( #authdatafilepollingconfigmanager ) , you must create a secure environment for
136
+ your project and generate an access token for your datafile.
137
+
138
+ ** access_token** : The access_token is attached to the outbound HTTP request header to authorize the request and fetch the datafile.
139
+
123
140
#### Advanced configuration
124
141
125
142
The following properties can be set to override the default
126
- configurations for [ PollingConfigManager] ( #pollingconfigmanager ) .
143
+ configurations for [ PollingConfigManager] ( #pollingconfigmanager ) and [ AuthDatafilePollingConfigManager ] ( #authdatafilepollingconfigmanager ) .
127
144
128
- | ** Property Name** | ** Default Value** | ** Description ** |
129
- | :-----------------------: | : ---------------: | :--------------------------------------------------------------: |
130
- | update_interval | 5 minutes | Fixed delay between fetches for the datafile |
131
- | sdk_key | None | Optimizely project SDK key |
132
- | url | None | URL override location used to specify custom |
133
- | HTTP source for Optimizely datafile< br >url_template | https://cdn.optimizely.com/datafiles/{sdk_key}.json | Parameterized datafile URL by SDK key |
134
- | datafile | None | Initial datafile, typically sourced from a local cached source |
145
+ | ** Property Name** | ** Default Value** | ** Description ** |
146
+ | :---------------: | : -------------------------------------------------------------------------------------------------------------------------------------------------------------------------------------: | :------------------------------------------------------------: |
147
+ | sdk_key | None | Optimizely project SDK key |
148
+ | datafile | None | Initial datafile, typically sourced from a local cached source |
149
+ | update_interval | 5 minutes | Fixed delay between fetches for the datafile |
150
+ | url | None | Custom URL location from which to fetch the datafile |
151
+ | url_template | ` PollingConfigManager ` :< br /> https://cdn.optimizely.com/datafiles/{sdk_key}.json < br /> ` AuthDatafilePollingConfigManager ` :< br /> https://config.optimizely.com/datafiles/auth/{sdk_key}.json | Parameterized datafile URL by SDK key |
135
152
136
- A notification signal will be triggered whenever a * new * datafile is
153
+ A notification signal will be triggered whenever a _ new _ datafile is
137
154
fetched and Project Config is updated. To subscribe to these
138
155
notifications, use:
139
156
140
157
```
141
158
notification_center.add_notification_listener(NotificationTypes.OPTIMIZELY_CONFIG_UPDATE, update_callback)
142
159
```
143
160
144
- For Further details see the Optimizely [ Full Stack documentation] ( https://docs.developers.optimizely.com/full-stack/docs ) to learn how to set up your first Python project and use the SDK.
161
+ For Further details see the Optimizely [ Full Stack documentation] ( https://docs.developers.optimizely.com/full-stack/docs )
162
+ to learn how to set up your first Python project and use the SDK.
145
163
146
- Development
147
- -----------
164
+ ## Development
148
165
149
166
### Building the SDK
150
167
0 commit comments