分布式注册中心Nacos-python实现
nacos-sdk-python
A Python implementation of Nacos OpenAPI.
see: https://nacos.io/zh-cn/docs/open-API.html
Supported Python version:
Python 2.7 Python 3.6 Python 3.7
Supported Nacos version
Nacos 0.8.0 ~ 1.3.2
Installation
pip install nacos-sdk-python
Getting Started
import nacos
SERVER_ADDRESSES = "server addresses split by comma"
NAMESPACE = "***"
# no auth mode
client = nacos.NacosClient(SERVER_ADDRESSES, namespace=NAMESPACE)
# auth mode
#client = nacos.NacosClient(SERVER_ADDRESSES, namespace=NAMESPACE, username="nacos", password="nacos")
# get config
data_id = "config.nacos"
group = "group"
print(client.get_config(data_id, group))
Configuration
client = NacosClient(server_addresses, namespace=your_ns)
server_addresses - required - Nacos server address, comma separated if more than 1.
namespace - Namespace. | 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.
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.
no_snapshot - To disable default snapshot behavior, this can be overridden by param no_snapshot in get method.
proxies - Dict proxy mapping, some environments require proxy access, so you can set this parameter, this way http requests go through the proxy.
API Reference
Get Config
NacosClient.get_config(data_id, group, timeout, no_snapshot)
param data_id Data id.
param group Group, use DEFAULT_GROUP if no group specified.
param timeout Timeout for requesting server in seconds.
param no_snapshot Whether to use local snapshot while ser