IBM Cloud App Configuration Python SDK
Project description
IBM Cloud App Configuration Python server SDK
IBM Cloud App Configuration SDK is used to perform feature flag and property evaluation based on the configuration on IBM Cloud App Configuration service.
Table of Contents
Overview
IBM Cloud App Configuration is a centralized feature management and configuration service on IBM Cloud for use with web and mobile applications, microservices, and distributed environments.
Instrument your applications with App Configuration Python SDK, and use the App Configuration dashboard, CLI or API to define feature flags or properties, organized into collections and targeted to segments. Toggle feature flag states in the cloud to activate or deactivate features in your application or environment, when required. You can also manage the properties for distributed applications centrally.
Installation
To install, use pip
or easy_install
:
pip install --upgrade ibm-appconfiguration-python-sdk
or
easy_install --upgrade ibm-appconfiguration-python-sdk
Import the SDK
from ibm_appconfiguration import AppConfiguration, Feature, Property, ConfigurationType
Initialize SDK
app_config = AppConfiguration.get_instance()
app_config.init(region=AppConfiguration.REGION_US_SOUTH,
guid='GUID',
apikey='APIKEY')
## Initialize configurations
app_config.set_context(collection_id='collection_id',
environment_id='environment_id')
- region : Region name where the service instance is created. Use
AppConfiguration.REGION_US_SOUTH
for DallasAppConfiguration.REGION_EU_GB
for LondonAppConfiguration.REGION_AU_SYD
for Sydney
- guid : GUID of the App Configuration service. Get it from the service credentials section of the dashboard
- apikey : ApiKey of the App Configuration service. Get it from the service credentials section of the dashboard
- collection_id : Id of the collection created in App Configuration service instance.
- environment_id : Id of the environment created in App Configuration service instance.
Work offline with local configuration file
You can also work offline with local configuration file and perform feature and property related operations.
app_config.set_context(collection_id='collection_id',
environment_id='environment_id',
configuration_file='custom/userJson.json',
live_config_update_enabled=True)
- configuration_file : Path to the JSON file which contains configuration details.
- live_config_update_enabled : Set this value to false if the new configuration values shouldn't be fetched from the server. Make sure to provide a proper JSON file in the configuration_file path. By default, this value is enabled.
Get single feature
feature = app_config.get_feature('feature_id')
if (feature) {
print('Feature Name : {0}'.format(feature.get_feature_name()));
print('Feature Id : {0}'.format(feature.get_feature_id()));
print('Feature Type : {0}'.format(feature.get_feature_data_type()));
print('Feature is enabled : {0}'.format(feature.is_enabled()));
}
Get all features
features_dictionary = app_config.get_features()
Evaluate a feature
You can use the feature.get_current_value(identity_id, identity_attributes) method to evaluate the value of the feature flag.
You should pass an unique identity_id as the parameter to perform the feature flag evaluation. If the feature flag is configured with segments in the App Configuration service, you can set the attributes values as a dictionary.
identity_attributes = {
'city': 'Bangalore',
'country': 'India'
}
feature_value = feature.get_current_value(identity_id='identity_id', identity_attributes=identity_attributes)
Get single Property
property = app_config.get_property('property_id')
if (property) {
print('Property Name : {0}'.format(property.get_property_name()));
print('Property Id : {0}'.format(property.get_property_id()));
print('Property Type : {0}'.format(property.get_property_data_type()));
}
Get all Properties
properties_dictionary = app_config.get_properties()
Evaluate a property
You can use the property.get_current_value(identity_id, identity_attributes) method to evaluate the value of the property.
You should pass an unique identity_id as the parameter to perform the property evaluation. If the property is configured with segments in the App Configuration service, you can set the attributes values as a dictionary.
identity_attributes = {
'city': 'Bangalore',
'country': 'India'
}
property_value = property.get_current_value(identity_id='identity_id', identity_attributes=identity_attributes)
Set listener for the feature and property data changes
To listen to the data changes add the following code in your application.
def configuration_update(self):
print('Get your Feature/Property value now')
app_config.register_configuration_update_listener(configuration_update)
Fetch latest data
app_config.fetch_configurations()
Enable debugger (Optional)
app_config.enable_debug(True)
License
This project is released under the Apache 2.0 license. The license's full text can be found in LICENSE
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Hashes for ibm-appconfiguration-python-sdk-0.0.1.tar.gz
Algorithm | Hash digest | |
---|---|---|
SHA256 | c23a76bdc35a8ed743681ca99010143cb9812c826076287be47be74990febe8e |
|
MD5 | 6c5d1b8a58dc8ac438cadfd9c0851f94 |
|
BLAKE2b-256 | 72260ef3fa18397a9583d28812c1e34f239171e14b48650708022342f6d68a82 |
Hashes for ibm_appconfiguration_python_sdk-0.0.1-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5e90a88ff15e102847bc162da82fc5a19704309bffc9141ceb58a84ea2a86b65 |
|
MD5 | 5130ee7977548a4197e178ec2c869450 |
|
BLAKE2b-256 | 26ac295ff28a6147cf54dd758212836086cd0f7c1cfed05589b3339a0d243f79 |