Config Manager
Base Config Manager
- class optimizely.config_manager.BaseConfigManager(logger: Optional[Union[logging.Logger, optimizely.logger.BaseLogger]] = None, error_handler: Optional[optimizely.error_handler.BaseErrorHandler] = None, notification_center: Optional[optimizely.notification_center.NotificationCenter] = None)
Base class for Optimizely’s config manager.
- abstract get_config() Optional[optimizely.project_config.ProjectConfig]
Get config for use by optimizely.Optimizely. The config should be an instance of project_config.ProjectConfig.
- abstract get_sdk_key() Optional[str]
Get sdk_key for use by optimizely.Optimizely. The sdk_key should uniquely identify the datafile for a project and environment combination.
Static Config Manager
- class optimizely.config_manager.StaticConfigManager(datafile: Optional[str] = None, logger: Optional[Union[logging.Logger, optimizely.logger.BaseLogger]] = None, error_handler: Optional[optimizely.error_handler.BaseErrorHandler] = None, notification_center: Optional[optimizely.notification_center.NotificationCenter] = None, skip_json_validation: Optional[bool] = False)
Config manager that returns ProjectConfig based on provided datafile.
- get_config() Optional[optimizely.project_config.ProjectConfig]
Returns instance of ProjectConfig.
- Returns
ProjectConfig. None if not set.
- get_sdk_key() Optional[str]
Get sdk_key for use by optimizely.Optimizely. The sdk_key should uniquely identify the datafile for a project and environment combination.
Polling Config Manager
- class optimizely.config_manager.PollingConfigManager(sdk_key: Optional[str] = None, datafile: Optional[str] = None, update_interval: Optional[float] = None, blocking_timeout: Optional[int] = None, url: Optional[str] = None, url_template: Optional[str] = None, logger: Optional[Union[logging.Logger, optimizely.logger.BaseLogger]] = None, error_handler: Optional[optimizely.error_handler.BaseErrorHandler] = None, notification_center: Optional[optimizely.notification_center.NotificationCenter] = None, skip_json_validation: Optional[bool] = False)
Config manager that polls for the datafile and updated ProjectConfig based on an update interval.
- fetch_datafile() None
Fetch datafile and set ProjectConfig.
- get_config() Optional[optimizely.project_config.ProjectConfig]
Returns instance of ProjectConfig. Returns immediately if project config is ready otherwise blocks maximum for value of blocking_timeout in seconds.
- Returns
ProjectConfig. None if not set.
- static get_datafile_url(sdk_key: Optional[str], url: Optional[str], url_template: Optional[str]) str
Helper method to determine URL from where to fetch the datafile.
- Parameters
sdk_key – Key uniquely identifying the datafile.
url – String representing URL from which to fetch the datafile.
url_template – String representing template which is filled in with SDK key to determine URL from which to fetch the datafile.
- Returns
String representing URL to fetch datafile from.
- Raises
optimizely.exceptions.InvalidInputException if –
- One of sdk_key or url is not provided. –
- url_template is invalid. –
- property is_running: bool
Check if polling thread is alive or not.
- set_blocking_timeout(blocking_timeout: Optional[int | float]) None
Helper method to set time in seconds to block the config call until config has been initialized.
- Parameters
blocking_timeout – Time in seconds to block the config call.
- set_last_modified(response_headers: CaseInsensitiveDict[str]) None
Looks up and sets last modified time based on Last-Modified header in the response.
- Parameters
response_headers – requests.Response.headers
- set_update_interval(update_interval: Optional[int | float]) None
Helper method to set frequency at which datafile has to be polled and ProjectConfig updated.
- Parameters
update_interval – Time in seconds after which to update datafile.
- start() None
Start the config manager and the thread to periodically fetch datafile.
- stop() None
Stop the polling thread and briefly wait for it to exit.