@@ -30,7 +30,97 @@ dashboard, please contact your Optimizely account executive.
3030Using the SDK
3131~~~~~~~~~~~~~
3232
33- See the Optimizely `Full Stack documentation `_ to learn how to
33+ Optimizely instance can be initialized in three
34+ different ways as per your requirement.
35+
36+ 1. Initialize Optimizely with a datafile. This datafile will be used as
37+ ProjectConfig throughout the life of Optimizely instance.
38+ ::
39+
40+ optimizely.Optimizely(
41+ datafile
42+ )
43+
44+ 2. Initialize Optimizely by providing an 'sdk_key'. This will initialize
45+ a PollingConfigManager that makes an HTTP GET request to the URL (
46+ formed using your provided sdk key and the default datafile CDN url
47+ template) to asynchronously download the project datafile at regular
48+ intervals and update ProjectConfig when a new datafile is recieved. A
49+ hard-coded datafile can also be provided along with the sdk_key that
50+ will be used initially before any update.
51+ ::
52+
53+ optimizely.Optimizely(
54+ datafile=None,
55+ sdk_key='put_your_sdk_key_here'
56+ )
57+
58+ 3. Initialize Optimizely by providing a Config Manager that implements a
59+ 'get_config' method.You may use our Polling Config Manager and
60+ customize it to your need.
61+ ::
62+
63+ optimizely.Optimizely(
64+ config_manager=custom_config_manager
65+ )
66+
67+ PollingConfigManager
68+ ''''''''''''''''''''
69+
70+ The PollingConfigManager asynchronously polls for datafiles from a
71+ specified URL at regular intervals by making HTTP request.
72+
73+ polling_config_manager = PollingConfigManager( sdk_key=None,
74+ datafile=None, update_interval=None, url=None, url_template=None,
75+ logger=None, error_handler=None, notification_center=None,
76+ skip_json_validation=False )
77+
78+ **Note **: One of the sdk_key or url must be provided. When both are
79+ provided, url takes the preference.
80+
81+ **sdk_key ** The sdk_key is used to compose the outbound HTTP request to
82+ the default datafile location on the Optimizely CDN.
83+
84+ **datafile ** You can provide an initial datafile to bootstrap the
85+ ``ProjectConfigManager `` so that it can be used immediately. The initial
86+ datafile also serves as a fallback datafile if HTTP connection cannot be
87+ established. The initial datafile will be discarded after the first
88+ successful datafile poll.
89+
90+ **update_interval ** The update_interval is used to specify a fixed delay
91+ in seconds between consecutive HTTP requests for the datafile.
92+
93+ **url_template ** A string with placeholder ``{sdk_key} `` can be provided
94+ so that this template along with the provided sdk key is used to form
95+ the target URL.
96+
97+ You may also provide your own logger, error_handler or
98+ notification_center.
99+
100+ Advanced configuration
101+ ''''''''''''''''''''''
102+
103+ The following properties can be set to override the default
104+ configurations for PollingConfigManager.
105+
106+ ================ ======================================================== =====================================================================================
107+ **Property Name ** **Default Value ** **Description **
108+ ================ ======================================================== =====================================================================================
109+ update_interval 5 minutes Fixed delay between fetches for the datafile
110+ sdk_key None Optimizely project SDK key
111+ url None URL override location used to specify custom HTTP source for the Optimizely datafile.
112+ url_template https://cdn.optimizely.com/datafiles/{sdk_key}.json Parameterized datafile URL by SDK key.
113+ datafile None Initial datafile, typically sourced from a local cached source.
114+ ================ ======================================================== =====================================================================================
115+
116+ A notification signal will be triggered whenever a *new * datafile is
117+ fetched and Project Config is updated. To subscribe to these
118+ notifications you can use the
119+
120+ ``notification_center.add_notification_listener(NotificationTypes.OPTIMIZELY_CONFIG_UPDATE, update_callback) ``
121+
122+
123+ For Further details see the Optimizely `Full Stack documentation `_ to learn how to
34124set up your first Python project and use the SDK.
35125
36126Development
0 commit comments