Package: aioacm-sdk-python
User GuideIntroductionPython SDK for ACM with asyncio support.FeaturesGet/Publish/Remove config from ACM server use REST API.Watch config changes from server.Auto failover on server failure.TLS supported.Address server supported.Both Alibaba Cloud ACM and Stand-alone deployment supported.Supported Python：Python 3.5Python 3.6Supported ACM versionACM 1.0Change LogsInstallationFor Python 3.5 and above:pipinstallaioacm-sdk-pythonGetting StartedimportaioacmENDPOINT="acm.aliyun.com:8080"NAMESPACE="**********"AK="**********"SK="**********"# get configclient=aioacm.ACMClient(ENDPOINT,NAMESPACE,AK,SK)data_id="com.alibaba.cloud.acm:sample-app.properties"group="group"print(asyncio.get_event_loop().run_until_complete(client.get(data_id,group)))# add watchimporttimeclient.add_watcher(data_id,group,lambdax:print("config change detected: "+x))asyncio.get_event_loop().run_until_complete(asyncio.sleep(5))# wait for config changesConfigurationclient = ACMClient(endpoint, namespace, ak, sk)endpoint-required- ACM server address.namespace- Namespace. | default:DEFAULT_TENANTak- AccessKey For Alibaba Cloud ACM. | default:Nonesk- SecretKey For Alibaba Cloud ACM. | default:NoneExtra OptionsExtra option can be set byset_options, as following:client.set_options({key}={value})Configurable options are:default_timeout- Default timeout for get config from server in seconds.tls_enabled- Whether to use https.auth_enabled- Whether to use auth features.cai_enabled- Whether to use address server.pulling_timeout- Long polling timeout in seconds.pulling_config_size- Max config items number listened by one polling process.callback_thread_num- Concurrency for invoking callback.failover_base- Dir to store failover config files.snapshot_base- Dir to store snapshot config files.app_name- Client app identifier.no_snapshot- To disable default snapshot behavior, this can be overridden by paramno_snapshotingetmethod.API ReferenceGet ConfigACMClient.get(data_id, group, timeout, no_snapshot)paramdata_idData id.paramgroupGroup, useDEFAULT_GROUPif no group specified.paramtimeoutTimeout for requesting server in seconds.paramno_snapshotWhether to use local snapshot while server is unavailable.returnW
Get value of one config item following priority:Step 1 - Get from local failover dir(default:${cwd}/acm/data).Failover dir can be manually copied from snapshot dir(default:${cwd}/acm/snapshot) in advance.This helps to suppress the effect of known server failure.Step 2 - Get from one server until value is got or all servers tried.Content will be save to snapshot dir after got from server.Step 3 - Get from snapshot dir.Add WatchersACMClient.add_watchers(data_id, group, cb_list)paramdata_idData id.paramgroupGroup, useDEFAULT_GROUPif no group specified.paramcb_listList of callback functions to add.returnAdd watchers to a specified config item.Once changes or deletion of the item happened, callback functions will be invoked.If the item is already exists in server, callback functions will be invoked for once.Multiple callbacks on one item is allowed and all callback functions are invoked concurrently bythreading.Thread.Callback functions are invoked from current process.Remove WatcherACMClient.remove_watcher(data_id, group, cb, remove_all)paramdata_idData id.paramgroupGroup, use "DEFAULT_GROUP" if no group specified.paramcbCallback function to delete.paramremove_allWhether to remove all occurrence of the callback or just once.returnRemove watcher from specified key.List All ConfigACMClient.list_all(group, prefix)paramgroupOnly dataIds with group match shall be returned, default is None.paramgrouponly dataIds startswith prefix shall be returned, default is NoneCase sensitive.returnList of data items.Get all config items of current namespace, with dataId and group information only.Warning: If there are lots of config in namespace, this function may cost some time.Publish ConfigACMClient.publish(data_id, group, content, timeout)paramdata_idData id.paramgroupGroup, use "DEFAULT_GROUP" if no group specified.paramcontentConfig value.paramtimeoutTimeout for requesting server in seconds.returnTrue if success or an exception will be raised.Publish one data item to ACM.If the data key is not exist, create one first.If the data key is exist, update to the content specified.Content can not be set to None, if there is need to delete config item, use functionremoveinstead.Remove ConfigACMClient.remove_watcher(data_id, group, cb, remove_all)paramdata_idData id.paramgroupGroup, use "DEFAULT_GROUP" if no group specified.paramtimeoutTimeout for requesting server in seconds.returnTrue if success or an exception will be raised.Remove one data item from ACM.Debugging ModeDebugging mode if useful for getting more detailed log on console.Debugging mode can be set by:ACMClient.set_debugging()
# only effective within the current processCLI ToolA CLI Tool is along with python SDK to make convenient access and management of config items in ACM server.You can useacm {subcommand}directly after installation, sub commands available are as following:addaddanamespaceuseswitchtoanamespacecurrentshowcurrentendpointandnamespaceshowshowallendpointsandnamespaceslistgetlistofdataIdspullgetoneconfigcontentpushpushoneconfigexportexportdataIdstolocalfilesimportimportfilestoACMserverUseacm -hto see the detailed manual.Data Security OptionsACM allows you to encrypt data along withKey Management Service, service provided by Alibaba Cloud (also known asKMS).To use this feature, you can follow these steps:Install KMS SDK bypip install aliyun-python-sdk-kms.Name your data_id with acipher-prefix.Get and filling all the needed configuration toACMClient, info needed are:region_id,kms_ak,kms_secret,key_id.Just make API calls and SDK will process data encrypt & decrypt automatically.Example:c = acm.ACMClient(ENDPOINT, NAMESPACE, AK, SK)
c.set_options(kms_enabled=True, kms_ak=KMS_AK, kms_secret=KMS_SECRET, region_id=REGION_ID, key_id=KEY_ID)

# publish an encrypted config item.
await c.publish("cipher-dataId", None, "plainText")

# get the content of an encrypted config item.
await c.get("cipher-dataId", None)Other ResourcesAlibaba Cloud ACM homepage:https://www.aliyun.com/product/acm