Python client for ACM.
Project description
Introduction
Python SDK for ACM.
Features
Get 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 2.7
Python 3.3
Python 3.4
Python 3.5
Python 3.6
Supported ACM version
ACM 1.0
Change Logs
Installation
pip install acm-sdk-python
Getting Started
import acm
ENDPOINT = "acm.aliyun.com:8080"
NAMESPACE = "**********"
AK = "**********"
SK = "**********"
# get config
client = acm.ACMClient(ENDPOINT, NAMESPACE, AK, SK)
data_id = "com.alibaba.cloud.acm:sample-app.properties"
group = "group"
print(client.get(data_id, group))
# add watch
import time
client.add_watcher(data_id, group, lambda x:print("config change detected: " + x))
time.sleep(5) # wait for config changes
Configuration
client = ACMClient(endpoint, namespace, ak, sk)
Options
endpoint - required - ACM server address.
namespace - Namespace. | default: DEFAULT_TENANT
ak - AccessKey For Alibaba Cloud ACM. | default: None
sk - SecretKey For Alibaba Cloud ACM. | default: None
Extra Options
Extra option can be set by set_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.
API Reference
Get Config
ACMClient.get(data_id, group, timeout)
param data_id Data id.
param group Group, use DEFAULT_GROUP if no group specified.
param timeout Timeout for requesting server in seconds.
return
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 Watchers
ACMClient.add_watchers(data_id, group, cb_list)
param data_id Data id.
param group Group, use DEFAULT_GROUP if no group specified.
param cb_list List of callback functions to add.
return
Add 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 by threading.Thread. * Callback functions are invoked from current process.
Remove Watcher
ACMClient.remove_watcher(data_id, group, cb, remove_all)
param data_id Data id.
param group Group, use “DEFAULT_GROUP” if no group specified.
param cb Callback function to delete.
param remove_all Whether to remove all occurrence of the callback or just once.
return
Remove watcher from specified key.
Debugging Mode
Debugging mode if useful for getting more detailed log on console.
Debugging mode can be set by:
ACMClient.set_debugging() # only effective within the current process
Other Resources
Alibaba Cloud ACM homepage: https://www.aliyun.com/product/acm
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.