Skip to content

Commit 3af111d

Browse files
authored
docs: add auth datafile config manager documentation and refactor README (#277)
* docs: add auth datafile config manager documentation and refactor README * style: make small update * style: make small update in README
1 parent d743410 commit 3af111d

File tree

2 files changed

+53
-30
lines changed

2 files changed

+53
-30
lines changed

README.md

+47-30
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,4 @@
1-
Optimizely Python SDK
2-
=====================
1+
# Optimizely Python SDK
32

43
[![PyPI version](https://badge.fury.io/py/optimizely-sdk.svg)](https://pypi.org/project/optimizely-sdk)
54
[![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
2322
<https://www.optimizely.com/rollouts/>, or see the [Rollouts
2423
documentation](https://docs.developers.optimizely.com/rollouts/docs).
2524

26-
Getting Started
27-
---------------
25+
## Getting Started
2826

2927
### Installing the SDK
3028

@@ -46,7 +44,7 @@ You can initialize the Optimizely instance in three ways: with a datafile, by pr
4644
Each method is described below.
4745

4846
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:
5048

5149
optimizely.Optimizely(
5250
datafile
@@ -59,43 +57,43 @@ Each method is described below.
5957
project datafile at regular intervals and update ProjectConfig when
6058
a new datafile is received. A hard-coded datafile can also be
6159
provided along with the sdk_key that will be used
62-
initially before any update. :
60+
initially before any update:
6361

6462
optimizely.Optimizely(
6563
sdk_key='put_your_sdk_key_here'
6664
)
6765

68-
If providing a datafile, the initialization will look like: :
66+
If providing a datafile, the initialization will look like:
6967

7068
optimizely.Optimizely(
7169
datafile=datafile,
7270
sdk_key='put_your_sdk_key_here'
7371
)
7472

7573
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:
7877

7978
optimizely.Optimizely(
8079
config_manager=custom_config_manager
8180
)
8281

8382
#### PollingConfigManager
8483

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.
8886

8987
polling_config_manager = PollingConfigManager(
9088
sdk_key=None,
91-
datafile=None,
92-
update_interval=None,
93-
url=None,
89+
datafile=None,
90+
update_interval=None,
91+
url=None,
9492
url_template=None,
95-
logger=None,
96-
error_handler=None,
93+
logger=None,
94+
error_handler=None,
9795
notification_center=None,
98-
skip_json_validation=False
96+
skip_json_validation=False
9997
)
10098

10199
**Note**: You must provide either the sdk_key or URL. If
@@ -113,38 +111,57 @@ successful datafile poll.
113111
**update_interval** The update_interval is used to specify a fixed
114112
delay in seconds between consecutive HTTP requests for the datafile.
115113

114+
**url** The target URL from which to request the datafile.
115+
116116
**url_template** A string with placeholder `{sdk_key}` can be provided
117117
so that this template along with the provided sdk key is
118118
used to form the target URL.
119119

120120
You may also provide your own logger, error_handler, or
121121
notification_center.
122122

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+
123140
#### Advanced configuration
124141

125142
The following properties can be set to override the default
126-
configurations for [PollingConfigManager](#pollingconfigmanager).
143+
configurations for [PollingConfigManager](#pollingconfigmanager) and [AuthDatafilePollingConfigManager](#authdatafilepollingconfigmanager).
127144

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 |
135152

136-
A notification signal will be triggered whenever a *new* datafile is
153+
A notification signal will be triggered whenever a _new_ datafile is
137154
fetched and Project Config is updated. To subscribe to these
138155
notifications, use:
139156

140157
```
141158
notification_center.add_notification_listener(NotificationTypes.OPTIMIZELY_CONFIG_UPDATE, update_callback)
142159
```
143160

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.
145163

146-
Development
147-
-----------
164+
## Development
148165

149166
### Building the SDK
150167

docs/source/config_manager.rst

+6
Original file line numberDiff line numberDiff line change
@@ -18,3 +18,9 @@ Config Manager
1818

1919
.. autoclass:: optimizely.config_manager.PollingConfigManager
2020
:members:
21+
22+
``Authenticated Datafile Polling Config Manager``
23+
-------------------------------------------------
24+
25+
.. autoclass:: optimizely.config_manager.AuthDatafilePollingConfigManager
26+
:members:

0 commit comments

Comments
 (0)