nacos-sdk-python 2.0.2__tar.gz → 2.0.4__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/PKG-INFO +388 -386
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/README.md +387 -385
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/nacos_sdk_python.egg-info/PKG-INFO +388 -386
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/setup.py +1 -1
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/config/remote/config_grpc_client_proxy.py +45 -45
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/transport/grpc_client.py +6 -2
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/transport/model/internal_request.py +0 -6
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/nacos/__init__.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/nacos/auth.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/nacos/client.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/nacos/commons.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/nacos/exception.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/nacos/files.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/nacos/listener.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/nacos/params.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/nacos/task.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/nacos/timer.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/nacos_sdk_python.egg-info/SOURCES.txt +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/nacos_sdk_python.egg-info/dependency_links.txt +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/nacos_sdk_python.egg-info/requires.txt +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/nacos_sdk_python.egg-info/top_level.txt +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/setup.cfg +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/__init__.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/__init__.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/common/__init__.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/common/auth.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/common/client_config.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/common/client_config_builder.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/common/constants.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/common/nacos_exception.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/common/payload_registry.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/common/preserved_metadata_key.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/config/__init__.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/config/cache/__init__.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/config/cache/config_info_cache.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/config/cache/config_subscribe_manager.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/config/encryption/__init__.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/config/encryption/kms_client.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/config/encryption/kms_handler.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/config/encryption/plugin/__init__.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/config/encryption/plugin/encryption_plugin.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/config/encryption/plugin/kms_aes_128_encrytion_plugin.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/config/encryption/plugin/kms_aes_256_encrytion_plugin.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/config/encryption/plugin/kms_base_encryption_plugin.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/config/encryption/plugin/kms_encrytion_plugin.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/config/filter/__init__.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/config/filter/config_encryption_filter.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/config/filter/config_filter.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/config/model/__init__.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/config/model/config.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/config/model/config_param.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/config/model/config_request.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/config/model/config_response.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/config/nacos_config_service.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/config/remote/__init__.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/config/remote/config_change_notify_request_handler.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/config/remote/config_grpc_connection_event_listener.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/config/util/__init__.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/config/util/config_client_util.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/nacos_client.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/naming/__init__.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/naming/cache/__init__.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/naming/cache/service_info_cache.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/naming/cache/subscribe_manager.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/naming/event/__init__.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/naming/event/instance_change_notifier.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/naming/model/__init__.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/naming/model/instance.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/naming/model/naming_param.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/naming/model/naming_request.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/naming/model/naming_response.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/naming/model/service.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/naming/nacos_naming_service.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/naming/remote/__init__.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/naming/remote/naming_grpc_client_proxy.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/naming/remote/naming_grpc_connection_event_listener.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/naming/remote/naming_push_request_handler.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/naming/util/__init__.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/naming/util/naming_client_util.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/naming/util/naming_remote_constants.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/proto/__init__.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/transport/__init__.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/transport/auth_client.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/transport/connection.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/transport/connection_event_listener.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/transport/grpc_connection.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/transport/grpc_util.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/transport/grpcauto/__init__.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/transport/grpcauto/nacos_grpc_service_pb2.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/transport/grpcauto/nacos_grpc_service_pb2_grpc.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/transport/http_agent.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/transport/model/__init__.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/transport/model/internal_response.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/transport/model/rpc_request.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/transport/model/rpc_response.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/transport/model/server_info.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/transport/nacos_server_connector.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/transport/rpc_client.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/transport/rpc_client_factory.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/transport/server_request_handler.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/utils/__init__.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/utils/aes_util.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/utils/common_util.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/utils/content_util.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/utils/encode_util.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/utils/file_util.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/utils/hmac_util.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/utils/md5_util.py +0 -0
- {nacos-sdk-python-2.0.2 → nacos-sdk-python-2.0.4}/v2/nacos/utils/net_util.py +0 -0
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.1
|
|
2
2
|
Name: nacos-sdk-python
|
|
3
|
-
Version: 2.0.
|
|
3
|
+
Version: 2.0.4
|
|
4
4
|
Summary: Python client for Nacos.
|
|
5
5
|
Home-page: https://github.com/nacos-group/nacos-sdk-python
|
|
6
6
|
Author: nacos
|
|
@@ -10,152 +10,165 @@ Project-URL: Documentation, https://github.com/nacos-group/nacos-sdk-python
|
|
|
10
10
|
Project-URL: Source, https://github.com/nacos-group/nacos-sdk-python
|
|
11
11
|
Project-URL: Nacos Open API Guide, https://nacos.io/en-us/docs/open-api.html
|
|
12
12
|
Description:
|
|
13
|
-
# nacos-sdk-python
|
|
13
|
+
# nacos-sdk-python v2
|
|
14
14
|
|
|
15
15
|
A Python implementation of Nacos OpenAPI.
|
|
16
16
|
|
|
17
|
-
see: https://nacos.io/docs/
|
|
17
|
+
see: https://nacos.io/zh-cn/docs/open-API.html
|
|
18
18
|
|
|
19
19
|
[](https://badge.fury.io/py/nacos-sdk-python)
|
|
20
20
|
[](https://github.com/nacos-group/nacos-sdk-python/blob/master/LICENSE)
|
|
21
21
|
|
|
22
22
|
### Supported Python version:
|
|
23
23
|
|
|
24
|
-
Python
|
|
25
|
-
Python 3.6
|
|
26
|
-
Python 3.7
|
|
24
|
+
Python 3.7+
|
|
27
25
|
|
|
28
26
|
### Supported Nacos version
|
|
29
27
|
|
|
30
|
-
Nacos
|
|
31
|
-
Nacos 1.x
|
|
32
|
-
Nacos 2.x with http protocol
|
|
28
|
+
Supported Nacos version over 2.x
|
|
33
29
|
|
|
34
30
|
## Installation
|
|
35
31
|
|
|
36
32
|
```shell
|
|
37
|
-
|
|
38
|
-
```
|
|
39
|
-
|
|
40
|
-
## Getting Started
|
|
41
|
-
|
|
42
|
-
```python
|
|
43
|
-
import nacos
|
|
44
|
-
|
|
45
|
-
# Both HTTP/HTTPS protocols are supported, if not set protocol prefix default is HTTP, and HTTPS with no ssl check(verify=False)
|
|
46
|
-
# "192.168.3.4:8848" or "https://192.168.3.4:443" or "http://192.168.3.4:8848,192.168.3.5:8848" or "https://192.168.3.4:443,https://192.168.3.5:443"
|
|
47
|
-
SERVER_ADDRESSES = "server addresses split by comma"
|
|
48
|
-
NAMESPACE = "namespace id"
|
|
49
|
-
|
|
50
|
-
# no auth mode
|
|
51
|
-
client = nacos.NacosClient(SERVER_ADDRESSES, namespace=NAMESPACE)
|
|
52
|
-
# auth mode
|
|
53
|
-
# client = nacos.NacosClient(SERVER_ADDRESSES, namespace=NAMESPACE, ak="{ak}", sk="{sk}")
|
|
54
|
-
|
|
55
|
-
# get config
|
|
56
|
-
data_id = "config.nacos"
|
|
57
|
-
group = "group"
|
|
58
|
-
print(client.get_config(data_id, group))
|
|
33
|
+
pip install nacos-sdk-python==2.0.3
|
|
59
34
|
```
|
|
60
35
|
|
|
61
|
-
## Configuration
|
|
36
|
+
## Client Configuration
|
|
62
37
|
|
|
63
38
|
```
|
|
64
|
-
|
|
39
|
+
from v2.nacos import NacosNamingService, ClientConfigBuilder, GRPCConfig, Instance, SubscribeServiceParam, \
|
|
40
|
+
RegisterInstanceParam, DeregisterInstanceParam, BatchRegisterInstanceParam, GetServiceParam, ListServiceParam, \
|
|
41
|
+
ListInstanceParam, NacosConfigService, ConfigParam
|
|
42
|
+
|
|
43
|
+
client_config = (ClientConfigBuilder()
|
|
44
|
+
.access_key(os.getenv('NACOS_ACCESS_KEY'))
|
|
45
|
+
.secret_key(os.getenv('NACOS_SECRET_KEY'))
|
|
46
|
+
.server_address(os.getenv('NACOS_SERVER_ADDR', 'localhost:8848'))
|
|
47
|
+
.log_level('INFO')
|
|
48
|
+
.grpc_config(GRPCConfig(grpc_timeout=5000))
|
|
49
|
+
.build())
|
|
65
50
|
```
|
|
66
51
|
|
|
67
|
-
* *
|
|
68
|
-
* *
|
|
69
|
-
* *
|
|
70
|
-
* *
|
|
71
|
-
* *
|
|
72
|
-
* *
|
|
73
|
-
* *
|
|
74
|
-
|
|
75
|
-
|
|
52
|
+
* *server_address* - **required** - Nacos server address
|
|
53
|
+
* *access_key* - The aliyun accessKey to authenticate.
|
|
54
|
+
* *secret_key* - The aliyun secretKey to authenticate.
|
|
55
|
+
* *credentials_provider* - The custom access key manager.
|
|
56
|
+
* *username* - The username to authenticate.
|
|
57
|
+
* *password* - The password to authenticate.
|
|
58
|
+
* *log_level* - Log level | default: `logging.INFO`
|
|
59
|
+
* *cache_dir* - cache dir path. | default: `~/nacos/cache`
|
|
60
|
+
* *log_dir* - log dir path. | default: `~/logs/nacos`
|
|
61
|
+
* *namespace_id* - namespace id. | default: ``
|
|
62
|
+
* *grpc_config* - grpc config.
|
|
63
|
+
* *max_receive_message_length* - max receive message length in grpc. | default: 100 * 1024 * 1024
|
|
64
|
+
* *max_keep_alive_ms* - max keep alive ms in grpc. | default: 60 * 1000
|
|
65
|
+
* *initial_window_size* - initial window size in grpc. | default: 10 * 1024 * 1024
|
|
66
|
+
* *initial_conn_window_size* - initial connection window size in grpc. | default: 10 * 1024 * 1024
|
|
67
|
+
* *grpc_timeout* - grpc timeout in milliseconds. default: 3000
|
|
68
|
+
* *tls_config* - tls config
|
|
69
|
+
* *enabled* - whether enable tls.
|
|
70
|
+
* *ca_file* - ca file path.
|
|
71
|
+
* *cert_file* - cert file path.
|
|
72
|
+
* *key_file* - key file path.
|
|
73
|
+
* *kms_config* - aliyun kms config
|
|
74
|
+
* *enabled* - whether enable aliyun kms.
|
|
75
|
+
* *endpoint* - aliyun kms endpoint.
|
|
76
|
+
* *access_key* - aliyun accessKey.
|
|
77
|
+
* *secret_key* - aliyun secretKey.
|
|
78
|
+
* *password* - aliyun kms password.
|
|
76
79
|
|
|
77
|
-
|
|
80
|
+
## Config Client
|
|
78
81
|
|
|
79
82
|
```
|
|
80
|
-
|
|
81
|
-
|
|
83
|
+
|
|
84
|
+
config_client = await NacosConfigService.create_config_service(client_config)
|
|
85
|
+
|
|
82
86
|
```
|
|
83
87
|
|
|
84
|
-
|
|
88
|
+
### config client common parameters
|
|
85
89
|
|
|
86
|
-
|
|
87
|
-
* *pulling_timeout* - Long polling timeout in seconds.
|
|
88
|
-
* *pulling_config_size* - Max config items number listened by one polling process.
|
|
89
|
-
* *callback_thread_num* - Concurrency for invoking callback.
|
|
90
|
-
* *failover_base* - Dir to store failover config files.
|
|
91
|
-
* *snapshot_base* - Dir to store snapshot config files.
|
|
92
|
-
* *no_snapshot* - To disable default snapshot behavior, this can be overridden by param *no_snapshot* in *get* method.
|
|
93
|
-
* *proxies* - Dict proxy mapping, some environments require proxy access, so you can set this parameter, this way http
|
|
94
|
-
requests go through the proxy.
|
|
90
|
+
> `param: ConfigParam`
|
|
95
91
|
|
|
96
|
-
|
|
92
|
+
* `param` *data_id* Data id.
|
|
93
|
+
* `param` *group* Group, use `DEFAULT_GROUP` if no group specified.
|
|
94
|
+
* `param` *content* Config content.
|
|
95
|
+
* `param` *tag* Config tag.
|
|
96
|
+
* `param` *app_name* Application name.
|
|
97
|
+
* `param` *beta_ips* Beta test ip address.
|
|
98
|
+
* `param` *cas_md5* MD5 check code.
|
|
99
|
+
* `param` *type* Config type.
|
|
100
|
+
* `param` *src_user* Source user.
|
|
101
|
+
* `param` *encrypted_data_key* Encrypted data key.
|
|
102
|
+
* `param` *kms_key_id* Kms encrypted data key id.
|
|
103
|
+
* `param` *usage_type* Usage type.
|
|
97
104
|
|
|
98
105
|
### Get Config
|
|
99
106
|
|
|
100
|
-
|
|
107
|
+
```
|
|
108
|
+
content = await config_client.get_config(ConfigParam(
|
|
109
|
+
data_id=data_id,
|
|
110
|
+
group=group
|
|
111
|
+
))
|
|
112
|
+
```
|
|
101
113
|
|
|
102
|
-
* `param` *
|
|
103
|
-
|
|
104
|
-
* `
|
|
105
|
-
* `param` *no_snapshot* Whether to use local snapshot while server is unavailable.
|
|
106
|
-
* `return`
|
|
107
|
-
W
|
|
108
|
-
Get value of one config item following priority:
|
|
114
|
+
* `param` *ConfigParam* config client common parameters. When getting configuration, it is necessary to specify the
|
|
115
|
+
required data_id and group in param.
|
|
116
|
+
* `return` Config content if success or an exception will be raised.
|
|
109
117
|
|
|
118
|
+
Get value of one config item following priority:
|
|
110
119
|
|
|
111
|
-
* Step 1 - Get from local failover dir
|
|
112
|
-
* Failover dir can be manually copied from snapshot dir(default: `${cwd}/nacos-data/snapshot`) in advance.
|
|
113
|
-
* This helps to suppress the effect of known server failure.
|
|
120
|
+
* Step 1 - Get from local failover dir.
|
|
114
121
|
|
|
115
122
|
* Step 2 - Get from one server until value is got or all servers tried.
|
|
116
|
-
* Content will be
|
|
123
|
+
* Content will be saved to snapshot dir after got from server.
|
|
117
124
|
|
|
118
125
|
* Step 3 - Get from snapshot dir.
|
|
119
126
|
|
|
120
|
-
### Add
|
|
127
|
+
### Add Listener
|
|
121
128
|
|
|
122
|
-
|
|
129
|
+
```
|
|
130
|
+
async def config_listener(tenant, data_id, group, content):
|
|
131
|
+
print("listen, tenant:{} data_id:{} group:{} content:{}".format(tenant, data_id, group, content))
|
|
123
132
|
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
133
|
+
await config_client.add_listener(dataID, groupName, config_listener)
|
|
134
|
+
```
|
|
135
|
+
|
|
136
|
+
* `param` *ConfigParam* config client common parameters.
|
|
137
|
+
* `listener` *listener* Configure listener, defined by the namespace_id、group、data_id、content.
|
|
127
138
|
* `return`
|
|
128
139
|
|
|
129
|
-
Add
|
|
140
|
+
Add Listener to a specified config item.
|
|
130
141
|
|
|
131
142
|
* Once changes or deletion of the item happened, callback functions will be invoked.
|
|
132
143
|
* If the item is already exists in server, callback functions will be invoked for once.
|
|
133
|
-
* Multiple callbacks on one item is allowed and all callback functions are invoked concurrently by `threading.Thread`.
|
|
134
144
|
* Callback functions are invoked from current process.
|
|
135
145
|
|
|
136
|
-
### Remove
|
|
146
|
+
### Remove Listener
|
|
137
147
|
|
|
138
|
-
|
|
148
|
+
```
|
|
149
|
+
await client.remove_listener(dataID, groupName, config_listener)
|
|
150
|
+
```
|
|
139
151
|
|
|
140
|
-
* `param` *
|
|
141
|
-
* `
|
|
142
|
-
* `param` *cb* Callback function to delete.
|
|
143
|
-
* `param` *remove_all* Whether to remove all occurrence of the callback or just once.
|
|
144
|
-
* `return`
|
|
152
|
+
* `param` *ConfigParam* config client common parameters.
|
|
153
|
+
* `return` True if success or an exception will be raised.
|
|
145
154
|
|
|
146
155
|
Remove watcher from specified key.
|
|
147
156
|
|
|
148
157
|
### Publish Config
|
|
149
158
|
|
|
150
|
-
|
|
159
|
+
```
|
|
160
|
+
res = await client.publish_config(ConfigParam(
|
|
161
|
+
data_id=dataID,
|
|
162
|
+
group=groupName,
|
|
163
|
+
content="Hello world")
|
|
164
|
+
)
|
|
165
|
+
```
|
|
151
166
|
|
|
152
|
-
* `param` *
|
|
153
|
-
|
|
154
|
-
* `param` *content* Config value.
|
|
155
|
-
* `param` *timeout* Timeout for requesting server in seconds.
|
|
167
|
+
* `param` *ConfigParam* config client common parameters. When publishing configuration, it is necessary to specify the
|
|
168
|
+
required data_id, group and content in param.
|
|
156
169
|
* `return` True if success or an exception will be raised.
|
|
157
170
|
|
|
158
|
-
Publish one data item to Nacos.
|
|
171
|
+
Publish one congfig data item to Nacos.
|
|
159
172
|
|
|
160
173
|
* If the data key is not exist, create one first.
|
|
161
174
|
* If the data key is exist, update to the content specified.
|
|
@@ -163,287 +176,292 @@ Description:
|
|
|
163
176
|
|
|
164
177
|
### Remove Config
|
|
165
178
|
|
|
166
|
-
|
|
167
|
-
|
|
168
|
-
|
|
169
|
-
|
|
170
|
-
|
|
179
|
+
```
|
|
180
|
+
res = await client.remove_config(ConfigParam(
|
|
181
|
+
data_id=dataID,
|
|
182
|
+
group=groupName
|
|
183
|
+
))
|
|
184
|
+
```
|
|
185
|
+
* `param` *ConfigParam* config client common parameters.When removing configuration, it is necessary to specify the
|
|
186
|
+
required data_id and group in param.
|
|
171
187
|
* `return` True if success or an exception will be raised.
|
|
172
188
|
|
|
173
|
-
Remove one data item from Nacos.
|
|
174
|
-
|
|
175
|
-
### Register Instance
|
|
176
|
-
|
|
177
|
-
>
|
|
178
|
-
`NacosClient.add_naming_instance(service_name, ip, port, cluster_name, weight, metadata, enable, healthy,ephemeral,group_name,heartbeat_interval)`
|
|
179
|
-
|
|
180
|
-
* `param` *service_name* **required** Service name to register to.
|
|
181
|
-
* `param` *ip* **required** IP of the instance.
|
|
182
|
-
* `param` *port* **required** Port of the instance.
|
|
183
|
-
* `param` *cluster_name* Cluster to register to.
|
|
184
|
-
* `param` *weight* A float number for load balancing weight.
|
|
185
|
-
* `param` *metadata* Extra info in JSON string format or dict format
|
|
186
|
-
* `param` *enable* A bool value to determine whether instance is enabled or not.
|
|
187
|
-
* `param` *healthy* A bool value to determine whether instance is healthy or not.
|
|
188
|
-
* `param` *ephemeral* A bool value to determine whether instance is ephemeral or not.
|
|
189
|
-
* `param` *heartbeat_interval* Auto daemon heartbeat interval in seconds.
|
|
190
|
-
* `return` True if success or an exception will be raised.
|
|
189
|
+
Remove one config data item from Nacos.
|
|
191
190
|
|
|
192
|
-
###
|
|
191
|
+
### Stop Config Client
|
|
193
192
|
|
|
194
|
-
|
|
193
|
+
```
|
|
194
|
+
await client.shutdown()
|
|
195
|
+
```
|
|
195
196
|
|
|
196
|
-
|
|
197
|
-
* `param` *ip* **required** IP of the instance.
|
|
198
|
-
* `param` *port* **required** Port of the instance.
|
|
199
|
-
* `param` *cluster_name* Cluster to deregister from.
|
|
200
|
-
* `param` *ephemeral* A bool value to determine whether instance is ephemeral or not.
|
|
201
|
-
* `return` True if success or an exception will be raised.
|
|
197
|
+
## Naming Client
|
|
202
198
|
|
|
203
|
-
|
|
199
|
+
```
|
|
204
200
|
|
|
205
|
-
|
|
201
|
+
naming_client = await NacosNamingService.create_naming_service(client_config)
|
|
206
202
|
|
|
207
|
-
|
|
208
|
-
* `param` *ip* **required** IP of the instance.
|
|
209
|
-
* `param` *port* **required** Port of the instance.
|
|
210
|
-
* `param` *cluster_name* Cluster name.
|
|
211
|
-
* `param` *weight* A float number for load balancing weight.
|
|
212
|
-
* `param` *metadata* Extra info in JSON string format or dict format.
|
|
213
|
-
* `param` *enable* A bool value to determine whether instance is enabled or not.
|
|
214
|
-
* `param` *ephemeral* A bool value to determine whether instance is ephemeral or not.
|
|
215
|
-
* `return` True if success or an exception will be raised.
|
|
203
|
+
```
|
|
216
204
|
|
|
217
|
-
###
|
|
205
|
+
### Register Instance
|
|
218
206
|
|
|
219
|
-
|
|
207
|
+
```angular2html
|
|
208
|
+
response = await client.register_instance(
|
|
209
|
+
request=RegisterInstanceParam(service_name='nacos.test.1', group_name='DEFAULT_GROUP', ip='1.1.1.1',
|
|
210
|
+
port=7001, weight=1.0, cluster_name='c1', metadata={'a': 'b'},
|
|
211
|
+
enabled=True,
|
|
212
|
+
healthy=True, ephemeral=True))
|
|
213
|
+
```
|
|
220
214
|
|
|
221
|
-
|
|
222
|
-
|
|
223
|
-
|
|
224
|
-
|
|
225
|
-
|
|
226
|
-
|
|
227
|
-
|
|
228
|
-
|
|
215
|
+
### Batch Register Instance
|
|
216
|
+
```angular2html
|
|
217
|
+
param1 = RegisterInstanceParam(service_name='nacos.test.1',
|
|
218
|
+
group_name='DEFAULT_GROUP',
|
|
219
|
+
ip='1.1.1.1',
|
|
220
|
+
port=7001,
|
|
221
|
+
weight=1.0,
|
|
222
|
+
cluster_name='c1',
|
|
223
|
+
metadata={'a': 'b'},
|
|
224
|
+
enabled=True,
|
|
225
|
+
healthy=True,
|
|
226
|
+
ephemeral=True
|
|
227
|
+
)
|
|
228
|
+
param2 = RegisterInstanceParam(service_name='nacos.test.1',
|
|
229
|
+
group_name='DEFAULT_GROUP',
|
|
230
|
+
ip='1.1.1.1',
|
|
231
|
+
port=7002,
|
|
232
|
+
weight=1.0,
|
|
233
|
+
cluster_name='c1',
|
|
234
|
+
metadata={'a': 'b'},
|
|
235
|
+
enabled=True,
|
|
236
|
+
healthy=True,
|
|
237
|
+
ephemeral=True
|
|
238
|
+
)
|
|
239
|
+
param3 = RegisterInstanceParam(service_name='nacos.test.1',
|
|
240
|
+
group_name='DEFAULT_GROUP',
|
|
241
|
+
ip='1.1.1.1',
|
|
242
|
+
port=7003,
|
|
243
|
+
weight=1.0,
|
|
244
|
+
cluster_name='c1',
|
|
245
|
+
metadata={'a': 'b'},
|
|
246
|
+
enabled=True,
|
|
247
|
+
healthy=False,
|
|
248
|
+
ephemeral=True
|
|
249
|
+
)
|
|
250
|
+
response = await client.batch_register_instances(
|
|
251
|
+
request=BatchRegisterInstanceParam(service_name='nacos.test.1', group_name='DEFAULT_GROUP',
|
|
252
|
+
instances=[param1, param2, param3]))
|
|
253
|
+
```
|
|
229
254
|
|
|
230
|
-
|
|
255
|
+
### Deregister Instance
|
|
231
256
|
|
|
232
|
-
|
|
233
|
-
|
|
234
|
-
|
|
235
|
-
|
|
236
|
-
|
|
257
|
+
```angular2html
|
|
258
|
+
response = await client.deregister_instance(
|
|
259
|
+
request=DeregisterInstanceParam(service_name='nacos.test.1', group_name='DEFAULT_GROUP', ip='1.1.1.1',
|
|
260
|
+
port=7001, cluster_name='c1', ephemeral=True)
|
|
261
|
+
)
|
|
262
|
+
```
|
|
237
263
|
|
|
238
|
-
###
|
|
264
|
+
### Update Instance
|
|
265
|
+
```angular2html
|
|
266
|
+
response = await client.update_instance(
|
|
267
|
+
request=RegisterInstanceParam(service_name='nacos.test.1', group_name='DEFAULT_GROUP', ip='1.1.1.1',
|
|
268
|
+
port=7001, weight=2.0, cluster_name='c1', metadata={'a': 'b'},
|
|
269
|
+
enabled=True,
|
|
270
|
+
healthy=True, ephemeral=True))
|
|
271
|
+
```
|
|
239
272
|
|
|
240
|
-
|
|
273
|
+
### Get Service
|
|
274
|
+
```angular2html
|
|
275
|
+
service = await client.get_service(
|
|
276
|
+
GetServiceParam(service_name='nacos.test.1', group_name='DEFAULT_GROUP', cluster_name='c1'))
|
|
277
|
+
```
|
|
241
278
|
|
|
242
|
-
|
|
243
|
-
|
|
244
|
-
* `param` *port* **required** Port of the instance.
|
|
245
|
-
* `param` *cluster_name* Cluster to register to.
|
|
246
|
-
* `param` *weight* A float number for load balancing weight.
|
|
247
|
-
* `param` *ephemeral* A bool value to determine whether instance is ephemeral or not.
|
|
248
|
-
* `param` *metadata* Extra info in JSON string format or dict format.
|
|
249
|
-
* `return` A JSON object include server recommended beat interval if success or an exception will be raised.
|
|
279
|
+
### List Service
|
|
280
|
+
```angular2html
|
|
250
281
|
|
|
251
|
-
|
|
282
|
+
service_list = await client.list_services(ListServiceParam())
|
|
252
283
|
|
|
253
|
-
|
|
284
|
+
```
|
|
254
285
|
|
|
255
|
-
|
|
256
|
-
* `param` *listener_interval* Listen interval , default 7 second.
|
|
257
|
-
* `param` *service_name* **required** Service name which subscribes.
|
|
258
|
-
* `param` *clusters* Cluster names separated by comma.
|
|
259
|
-
* `param` *namespace_id* Customized group name, default `blank`.
|
|
260
|
-
* `param` *group_name* Customized group name , default `DEFAULT_GROUP`.
|
|
261
|
-
* `param` *healthy_only* A bool value for querying healthy instances or not.
|
|
262
|
-
* `return`
|
|
286
|
+
### List Instance
|
|
263
287
|
|
|
264
|
-
|
|
288
|
+
```angular2html
|
|
265
289
|
|
|
266
|
-
|
|
290
|
+
instance_list = await client.list_instances(ListInstanceParam(service_name='nacos.test.1', healthy_only=True))
|
|
291
|
+
instance_list = await client.list_instances(ListInstanceParam(service_name='nacos.test.1', healthy_only=False))
|
|
292
|
+
instance_list = await client.list_instances(ListInstanceParam(service_name='nacos.test.1', healthy_only=None))
|
|
267
293
|
|
|
268
|
-
|
|
269
|
-
* `param` *listener_name* listener_name which is customized.
|
|
270
|
-
* `return`
|
|
294
|
+
```
|
|
271
295
|
|
|
272
|
-
###
|
|
296
|
+
### Subscribe
|
|
273
297
|
|
|
274
|
-
|
|
298
|
+
```angular2html
|
|
299
|
+
async def cb(instance_list: list[Instance]):
|
|
300
|
+
print('received subscribe callback', str(instance_list))
|
|
275
301
|
|
|
276
|
-
|
|
302
|
+
await client.subscribe(
|
|
303
|
+
SubscribeServiceParam(service_name='nacos.test.1', group_name='DEFAULT_GROUP', subscribe_callback=cb))
|
|
304
|
+
```
|
|
277
305
|
|
|
278
|
-
## Debugging Mode
|
|
279
306
|
|
|
280
|
-
|
|
307
|
+
### Unsubscribe
|
|
281
308
|
|
|
282
|
-
|
|
309
|
+
```angular2html
|
|
310
|
+
async def cb(instance_list: list[Instance]):
|
|
311
|
+
print('received subscribe callback', str(instance_list))
|
|
283
312
|
|
|
284
|
-
|
|
285
|
-
|
|
313
|
+
await client.unsubscribe(
|
|
314
|
+
SubscribeServiceParam(service_name='nacos.test.1', group_name='DEFAULT_GROUP', subscribe_callback=cb))
|
|
286
315
|
```
|
|
287
316
|
|
|
288
|
-
|
|
317
|
+
|
|
318
|
+
# nacos-sdk-python 1.0
|
|
289
319
|
|
|
290
320
|
A Python implementation of Nacos OpenAPI.
|
|
291
321
|
|
|
292
|
-
see: https://nacos.io/
|
|
322
|
+
see: https://nacos.io/docs/latest/guide/user/open-api/
|
|
293
323
|
|
|
294
324
|
[](https://badge.fury.io/py/nacos-sdk-python)
|
|
295
325
|
[](https://github.com/nacos-group/nacos-sdk-python/blob/master/LICENSE)
|
|
296
326
|
|
|
297
327
|
### Supported Python version:
|
|
298
328
|
|
|
299
|
-
Python
|
|
329
|
+
Python 2.7
|
|
330
|
+
Python 3.6
|
|
331
|
+
Python 3.7
|
|
300
332
|
|
|
301
333
|
### Supported Nacos version
|
|
302
334
|
|
|
303
|
-
|
|
335
|
+
Nacos 0.8.0+
|
|
336
|
+
Nacos 1.x
|
|
337
|
+
Nacos 2.x with http protocol
|
|
304
338
|
|
|
305
339
|
## Installation
|
|
306
340
|
|
|
307
341
|
```shell
|
|
308
|
-
|
|
342
|
+
pip install nacos-sdk-python
|
|
309
343
|
```
|
|
310
344
|
|
|
311
|
-
## Client Configuration
|
|
312
345
|
|
|
313
|
-
|
|
314
|
-
from v2.nacos import NacosNamingService, ClientConfigBuilder, GRPCConfig, Instance, SubscribeServiceParam, \
|
|
315
|
-
RegisterInstanceParam, DeregisterInstanceParam, BatchRegisterInstanceParam, GetServiceParam, ListServiceParam, \
|
|
316
|
-
ListInstanceParam, NacosConfigService, ConfigParam
|
|
317
|
-
|
|
318
|
-
client_config = (ClientConfigBuilder()
|
|
319
|
-
.access_key(os.getenv('NACOS_ACCESS_KEY'))
|
|
320
|
-
.secret_key(os.getenv('NACOS_SECRET_KEY'))
|
|
321
|
-
.server_address(os.getenv('NACOS_SERVER_ADDR', 'localhost:8848'))
|
|
322
|
-
.log_level('INFO')
|
|
323
|
-
.grpc_config(GRPCConfig(grpc_timeout=5000))
|
|
324
|
-
.build())
|
|
325
|
-
```
|
|
346
|
+
## Getting Started
|
|
326
347
|
|
|
327
|
-
|
|
328
|
-
|
|
329
|
-
* *secret_key* - The aliyun secretKey to authenticate.
|
|
330
|
-
* *credentials_provider* - The custom access key manager.
|
|
331
|
-
* *username* - The username to authenticate.
|
|
332
|
-
* *password* - The password to authenticate.
|
|
333
|
-
* *log_level* - Log level | default: `logging.INFO`
|
|
334
|
-
* *cache_dir* - cache dir path. | default: `~/nacos/cache`
|
|
335
|
-
* *log_dir* - log dir path. | default: `~/logs/nacos`
|
|
336
|
-
* *namespace_id* - namespace id. | default: ``
|
|
337
|
-
* *grpc_config* - grpc config.
|
|
338
|
-
* *max_receive_message_length* - max receive message length in grpc. | default: 100 * 1024 * 1024
|
|
339
|
-
* *max_keep_alive_ms* - max keep alive ms in grpc. | default: 60 * 1000
|
|
340
|
-
* *initial_window_size* - initial window size in grpc. | default: 10 * 1024 * 1024
|
|
341
|
-
* *initial_conn_window_size* - initial connection window size in grpc. | default: 10 * 1024 * 1024
|
|
342
|
-
* *grpc_timeout* - grpc timeout in milliseconds. default: 3000
|
|
343
|
-
* *tls_config* - tls config
|
|
344
|
-
* *enabled* - whether enable tls.
|
|
345
|
-
* *ca_file* - ca file path.
|
|
346
|
-
* *cert_file* - cert file path.
|
|
347
|
-
* *key_file* - key file path.
|
|
348
|
-
* *kms_config* - aliyun kms config
|
|
349
|
-
* *enabled* - whether enable aliyun kms.
|
|
350
|
-
* *endpoint* - aliyun kms endpoint.
|
|
351
|
-
* *access_key* - aliyun accessKey.
|
|
352
|
-
* *secret_key* - aliyun secretKey.
|
|
353
|
-
* *password* - aliyun kms password.
|
|
348
|
+
```python
|
|
349
|
+
import nacos
|
|
354
350
|
|
|
355
|
-
|
|
351
|
+
# Both HTTP/HTTPS protocols are supported, if not set protocol prefix default is HTTP, and HTTPS with no ssl check(verify=False)
|
|
352
|
+
# "192.168.3.4:8848" or "https://192.168.3.4:443" or "http://192.168.3.4:8848,192.168.3.5:8848" or "https://192.168.3.4:443,https://192.168.3.5:443"
|
|
353
|
+
SERVER_ADDRESSES = "server addresses split by comma"
|
|
354
|
+
NAMESPACE = "namespace id"
|
|
355
|
+
|
|
356
|
+
# no auth mode
|
|
357
|
+
client = nacos.NacosClient(SERVER_ADDRESSES, namespace=NAMESPACE)
|
|
358
|
+
# auth mode
|
|
359
|
+
# client = nacos.NacosClient(SERVER_ADDRESSES, namespace=NAMESPACE, ak="{ak}", sk="{sk}")
|
|
356
360
|
|
|
361
|
+
# get config
|
|
362
|
+
data_id = "config.nacos"
|
|
363
|
+
group = "group"
|
|
364
|
+
print(client.get_config(data_id, group))
|
|
357
365
|
```
|
|
358
366
|
|
|
359
|
-
|
|
367
|
+
## Configuration
|
|
360
368
|
|
|
369
|
+
```
|
|
370
|
+
client = NacosClient(server_addresses, namespace=your_ns, ak=your_ak, sk=your_sk)
|
|
361
371
|
```
|
|
362
372
|
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
373
|
+
* *server_addresses* - **required** - Nacos server address, comma separated if more than 1.
|
|
374
|
+
* *namespace* - Namespace. | default: `None`
|
|
375
|
+
* *ak* - The accessKey to authenticate. | default: null
|
|
376
|
+
* *sk* - The secretKey to authentication. | default: null
|
|
377
|
+
* *credentials_provider* - The custom access key manager | default: null
|
|
378
|
+
* *log_level* - Log level. | default: null
|
|
379
|
+
* *log_rotation_backup_count* - The number of log files to keep. | default: `7`
|
|
366
380
|
|
|
367
|
-
|
|
368
|
-
* `param` *group* Group, use `DEFAULT_GROUP` if no group specified.
|
|
369
|
-
* `param` *content* Config content.
|
|
370
|
-
* `param` *tag* Config tag.
|
|
371
|
-
* `param` *app_name* Application name.
|
|
372
|
-
* `param` *beta_ips* Beta test ip address.
|
|
373
|
-
* `param` *cas_md5* MD5 check code.
|
|
374
|
-
* `param` *type* Config type.
|
|
375
|
-
* `param` *src_user* Source user.
|
|
376
|
-
* `param` *encrypted_data_key* Encrypted data key.
|
|
377
|
-
* `param` *kms_key_id* Kms encrypted data key id.
|
|
378
|
-
* `param` *usage_type* Usage type.
|
|
381
|
+
#### Extra Options
|
|
379
382
|
|
|
380
|
-
|
|
383
|
+
Extra option can be set by `set_options`, as following:
|
|
381
384
|
|
|
382
385
|
```
|
|
383
|
-
|
|
384
|
-
|
|
385
|
-
group=group
|
|
386
|
-
))
|
|
386
|
+
client.set_options({key}={value})
|
|
387
|
+
# client.set_options(proxies={"http":"192.168.3.50:809"})
|
|
387
388
|
```
|
|
388
389
|
|
|
389
|
-
|
|
390
|
-
required data_id and group in param.
|
|
391
|
-
* `return` Config content if success or an exception will be raised.
|
|
390
|
+
Configurable options are:
|
|
392
391
|
|
|
393
|
-
|
|
392
|
+
* *default_timeout* - Default timeout for get config from server in seconds.
|
|
393
|
+
* *pulling_timeout* - Long polling timeout in seconds.
|
|
394
|
+
* *pulling_config_size* - Max config items number listened by one polling process.
|
|
395
|
+
* *callback_thread_num* - Concurrency for invoking callback.
|
|
396
|
+
* *failover_base* - Dir to store failover config files.
|
|
397
|
+
* *snapshot_base* - Dir to store snapshot config files.
|
|
398
|
+
* *no_snapshot* - To disable default snapshot behavior, this can be overridden by param *no_snapshot* in *get* method.
|
|
399
|
+
* *proxies* - Dict proxy mapping, some environments require proxy access, so you can set this parameter, this way http
|
|
400
|
+
requests go through the proxy.
|
|
394
401
|
|
|
395
|
-
|
|
402
|
+
## API Reference
|
|
403
|
+
|
|
404
|
+
### Get Config
|
|
405
|
+
|
|
406
|
+
> `NacosClient.get_config(data_id, group, timeout, no_snapshot)`
|
|
407
|
+
|
|
408
|
+
* `param` *data_id* Data id.
|
|
409
|
+
* `param` *group* Group, use `DEFAULT_GROUP` if no group specified.
|
|
410
|
+
* `param` *timeout* Timeout for requesting server in seconds.
|
|
411
|
+
* `param` *no_snapshot* Whether to use local snapshot while server is unavailable.
|
|
412
|
+
* `return`
|
|
413
|
+
W
|
|
414
|
+
Get value of one config item following priority:
|
|
415
|
+
|
|
416
|
+
|
|
417
|
+
* Step 1 - Get from local failover dir(default: `${cwd}/nacos-data/data`).
|
|
418
|
+
* Failover dir can be manually copied from snapshot dir(default: `${cwd}/nacos-data/snapshot`) in advance.
|
|
419
|
+
* This helps to suppress the effect of known server failure.
|
|
396
420
|
|
|
397
421
|
* Step 2 - Get from one server until value is got or all servers tried.
|
|
398
|
-
* Content will be
|
|
422
|
+
* Content will be save to snapshot dir after got from server.
|
|
399
423
|
|
|
400
424
|
* Step 3 - Get from snapshot dir.
|
|
401
425
|
|
|
402
|
-
### Add
|
|
403
|
-
|
|
404
|
-
```
|
|
405
|
-
async def config_listener(tenant, data_id, group, content):
|
|
406
|
-
print("listen, tenant:{} data_id:{} group:{} content:{}".format(tenant, data_id, group, content))
|
|
426
|
+
### Add Watchers
|
|
407
427
|
|
|
408
|
-
|
|
409
|
-
```
|
|
428
|
+
> `NacosClient.add_config_watchers(data_id, group, cb_list)`
|
|
410
429
|
|
|
411
|
-
* `param` *
|
|
412
|
-
* `
|
|
430
|
+
* `param` *data_id* Data id.
|
|
431
|
+
* `param` *group* Group, use `DEFAULT_GROUP` if no group specified.
|
|
432
|
+
* `param` *cb_list* List of callback functions to add.
|
|
413
433
|
* `return`
|
|
414
434
|
|
|
415
|
-
Add
|
|
435
|
+
Add watchers to a specified config item.
|
|
416
436
|
|
|
417
437
|
* Once changes or deletion of the item happened, callback functions will be invoked.
|
|
418
438
|
* If the item is already exists in server, callback functions will be invoked for once.
|
|
439
|
+
* Multiple callbacks on one item is allowed and all callback functions are invoked concurrently by `threading.Thread`.
|
|
419
440
|
* Callback functions are invoked from current process.
|
|
420
441
|
|
|
421
|
-
### Remove
|
|
442
|
+
### Remove Watcher
|
|
422
443
|
|
|
423
|
-
|
|
424
|
-
await client.remove_listener(dataID, groupName, config_listener)
|
|
425
|
-
```
|
|
444
|
+
> `NacosClient.remove_config_watcher(data_id, group, cb, remove_all)`
|
|
426
445
|
|
|
427
|
-
* `param` *
|
|
428
|
-
* `
|
|
446
|
+
* `param` *data_id* Data id.
|
|
447
|
+
* `param` *group* Group, use "DEFAULT_GROUP" if no group specified.
|
|
448
|
+
* `param` *cb* Callback function to delete.
|
|
449
|
+
* `param` *remove_all* Whether to remove all occurrence of the callback or just once.
|
|
450
|
+
* `return`
|
|
429
451
|
|
|
430
452
|
Remove watcher from specified key.
|
|
431
453
|
|
|
432
454
|
### Publish Config
|
|
433
455
|
|
|
434
|
-
|
|
435
|
-
res = await client.publish_config(ConfigParam(
|
|
436
|
-
data_id=dataID,
|
|
437
|
-
group=groupName,
|
|
438
|
-
content="Hello world")
|
|
439
|
-
)
|
|
440
|
-
```
|
|
456
|
+
> `NacosClient.publish_config(data_id, group, content, timeout)`
|
|
441
457
|
|
|
442
|
-
* `param` *
|
|
443
|
-
|
|
458
|
+
* `param` *data_id* Data id.
|
|
459
|
+
* `param` *group* Group, use "DEFAULT_GROUP" if no group specified.
|
|
460
|
+
* `param` *content* Config value.
|
|
461
|
+
* `param` *timeout* Timeout for requesting server in seconds.
|
|
444
462
|
* `return` True if success or an exception will be raised.
|
|
445
463
|
|
|
446
|
-
Publish one
|
|
464
|
+
Publish one data item to Nacos.
|
|
447
465
|
|
|
448
466
|
* If the data key is not exist, create one first.
|
|
449
467
|
* If the data key is exist, update to the content specified.
|
|
@@ -451,142 +469,126 @@ Description:
|
|
|
451
469
|
|
|
452
470
|
### Remove Config
|
|
453
471
|
|
|
454
|
-
|
|
455
|
-
|
|
456
|
-
|
|
457
|
-
|
|
458
|
-
|
|
459
|
-
```
|
|
460
|
-
* `param` *ConfigParam* config client common parameters.When removing configuration, it is necessary to specify the
|
|
461
|
-
required data_id and group in param.
|
|
472
|
+
> `NacosClient.remove_config(data_id, group, timeout)`
|
|
473
|
+
|
|
474
|
+
* `param` *data_id* Data id.
|
|
475
|
+
* `param` *group* Group, use "DEFAULT_GROUP" if no group specified.
|
|
476
|
+
* `param` *timeout* Timeout for requesting server in seconds.
|
|
462
477
|
* `return` True if success or an exception will be raised.
|
|
463
478
|
|
|
464
|
-
Remove one
|
|
479
|
+
Remove one data item from Nacos.
|
|
465
480
|
|
|
466
|
-
###
|
|
481
|
+
### Register Instance
|
|
467
482
|
|
|
468
|
-
|
|
469
|
-
|
|
470
|
-
```
|
|
483
|
+
>
|
|
484
|
+
`NacosClient.add_naming_instance(service_name, ip, port, cluster_name, weight, metadata, enable, healthy,ephemeral,group_name,heartbeat_interval)`
|
|
471
485
|
|
|
472
|
-
|
|
486
|
+
* `param` *service_name* **required** Service name to register to.
|
|
487
|
+
* `param` *ip* **required** IP of the instance.
|
|
488
|
+
* `param` *port* **required** Port of the instance.
|
|
489
|
+
* `param` *cluster_name* Cluster to register to.
|
|
490
|
+
* `param` *weight* A float number for load balancing weight.
|
|
491
|
+
* `param` *metadata* Extra info in JSON string format or dict format
|
|
492
|
+
* `param` *enable* A bool value to determine whether instance is enabled or not.
|
|
493
|
+
* `param` *healthy* A bool value to determine whether instance is healthy or not.
|
|
494
|
+
* `param` *ephemeral* A bool value to determine whether instance is ephemeral or not.
|
|
495
|
+
* `param` *heartbeat_interval* Auto daemon heartbeat interval in seconds.
|
|
496
|
+
* `return` True if success or an exception will be raised.
|
|
473
497
|
|
|
474
|
-
|
|
498
|
+
### Deregister Instance
|
|
475
499
|
|
|
476
|
-
|
|
500
|
+
> `NacosClient.remove_naming_instance(service_name, ip, port, cluster_name)`
|
|
477
501
|
|
|
478
|
-
|
|
502
|
+
* `param` *service_name* **required** Service name to deregister from.
|
|
503
|
+
* `param` *ip* **required** IP of the instance.
|
|
504
|
+
* `param` *port* **required** Port of the instance.
|
|
505
|
+
* `param` *cluster_name* Cluster to deregister from.
|
|
506
|
+
* `param` *ephemeral* A bool value to determine whether instance is ephemeral or not.
|
|
507
|
+
* `return` True if success or an exception will be raised.
|
|
479
508
|
|
|
480
|
-
###
|
|
509
|
+
### Modify Instance
|
|
481
510
|
|
|
482
|
-
|
|
483
|
-
response = await client.register_instance(
|
|
484
|
-
request=RegisterInstanceParam(service_name='nacos.test.1', group_name='DEFAULT_GROUP', ip='1.1.1.1',
|
|
485
|
-
port=7001, weight=1.0, cluster_name='c1', metadata={'a': 'b'},
|
|
486
|
-
enabled=True,
|
|
487
|
-
healthy=True, ephemeral=True))
|
|
488
|
-
```
|
|
511
|
+
> `NacosClient.modify_naming_instance(service_name, ip, port, cluster_name, weight, metadata, enable)`
|
|
489
512
|
|
|
490
|
-
|
|
491
|
-
|
|
492
|
-
|
|
493
|
-
|
|
494
|
-
|
|
495
|
-
|
|
496
|
-
|
|
497
|
-
|
|
498
|
-
|
|
499
|
-
enabled=True,
|
|
500
|
-
healthy=True,
|
|
501
|
-
ephemeral=True
|
|
502
|
-
)
|
|
503
|
-
param2 = RegisterInstanceParam(service_name='nacos.test.1',
|
|
504
|
-
group_name='DEFAULT_GROUP',
|
|
505
|
-
ip='1.1.1.1',
|
|
506
|
-
port=7002,
|
|
507
|
-
weight=1.0,
|
|
508
|
-
cluster_name='c1',
|
|
509
|
-
metadata={'a': 'b'},
|
|
510
|
-
enabled=True,
|
|
511
|
-
healthy=True,
|
|
512
|
-
ephemeral=True
|
|
513
|
-
)
|
|
514
|
-
param3 = RegisterInstanceParam(service_name='nacos.test.1',
|
|
515
|
-
group_name='DEFAULT_GROUP',
|
|
516
|
-
ip='1.1.1.1',
|
|
517
|
-
port=7003,
|
|
518
|
-
weight=1.0,
|
|
519
|
-
cluster_name='c1',
|
|
520
|
-
metadata={'a': 'b'},
|
|
521
|
-
enabled=True,
|
|
522
|
-
healthy=False,
|
|
523
|
-
ephemeral=True
|
|
524
|
-
)
|
|
525
|
-
response = await client.batch_register_instances(
|
|
526
|
-
request=BatchRegisterInstanceParam(service_name='nacos.test.1', group_name='DEFAULT_GROUP',
|
|
527
|
-
instances=[param1, param2, param3]))
|
|
528
|
-
```
|
|
513
|
+
* `param` *service_name* **required** Service name.
|
|
514
|
+
* `param` *ip* **required** IP of the instance.
|
|
515
|
+
* `param` *port* **required** Port of the instance.
|
|
516
|
+
* `param` *cluster_name* Cluster name.
|
|
517
|
+
* `param` *weight* A float number for load balancing weight.
|
|
518
|
+
* `param` *metadata* Extra info in JSON string format or dict format.
|
|
519
|
+
* `param` *enable* A bool value to determine whether instance is enabled or not.
|
|
520
|
+
* `param` *ephemeral* A bool value to determine whether instance is ephemeral or not.
|
|
521
|
+
* `return` True if success or an exception will be raised.
|
|
529
522
|
|
|
530
|
-
###
|
|
523
|
+
### Query Instances
|
|
531
524
|
|
|
532
|
-
|
|
533
|
-
response = await client.deregister_instance(
|
|
534
|
-
request=DeregisterInstanceParam(service_name='nacos.test.1', group_name='DEFAULT_GROUP', ip='1.1.1.1',
|
|
535
|
-
port=7001, cluster_name='c1', ephemeral=True)
|
|
536
|
-
)
|
|
537
|
-
```
|
|
525
|
+
> `NacosClient.list_naming_instance(service_name, clusters, namespace_id, group_name, healthy_only)`
|
|
538
526
|
|
|
539
|
-
|
|
540
|
-
|
|
541
|
-
|
|
542
|
-
|
|
543
|
-
|
|
544
|
-
|
|
545
|
-
healthy=True, ephemeral=True))
|
|
546
|
-
```
|
|
527
|
+
* `param` *service_name* **required** Service name to query.
|
|
528
|
+
* `param` *clusters* Cluster names separated by comma.
|
|
529
|
+
* `param` *namespace_id* Customized group name, default `blank`.
|
|
530
|
+
* `param` *group_name* Customized group name , default `DEFAULT_GROUP`.
|
|
531
|
+
* `param` *healthy_only* A bool value for querying healthy instances or not.
|
|
532
|
+
* `return` Instance info list if success or an exception will be raised.
|
|
547
533
|
|
|
548
|
-
###
|
|
549
|
-
```angular2html
|
|
550
|
-
service = await client.get_service(
|
|
551
|
-
GetServiceParam(service_name='nacos.test.1', group_name='DEFAULT_GROUP', cluster_name='c1'))
|
|
552
|
-
```
|
|
534
|
+
### Query Instance Detail
|
|
553
535
|
|
|
554
|
-
|
|
555
|
-
```angular2html
|
|
536
|
+
> `NacosClient.get_naming_instance(service_name, ip, port, cluster_name)`
|
|
556
537
|
|
|
557
|
-
|
|
538
|
+
* `param` *service_name* **required** Service name.
|
|
539
|
+
* `param` *ip* **required** IP of the instance.
|
|
540
|
+
* `param` *port* **required** Port of the instance.
|
|
541
|
+
* `param` *cluster_name* Cluster name.
|
|
542
|
+
* `return` Instance info if success or an exception will be raised.
|
|
558
543
|
|
|
559
|
-
|
|
544
|
+
### Send Instance Beat
|
|
560
545
|
|
|
561
|
-
|
|
546
|
+
> `NacosClient.send_heartbeat(service_name, ip, port, cluster_name, weight, metadata)`
|
|
562
547
|
|
|
563
|
-
|
|
548
|
+
* `param` *service_name* **required** Service name.
|
|
549
|
+
* `param` *ip* **required** IP of the instance.
|
|
550
|
+
* `param` *port* **required** Port of the instance.
|
|
551
|
+
* `param` *cluster_name* Cluster to register to.
|
|
552
|
+
* `param` *weight* A float number for load balancing weight.
|
|
553
|
+
* `param` *ephemeral* A bool value to determine whether instance is ephemeral or not.
|
|
554
|
+
* `param` *metadata* Extra info in JSON string format or dict format.
|
|
555
|
+
* `return` A JSON object include server recommended beat interval if success or an exception will be raised.
|
|
564
556
|
|
|
565
|
-
|
|
566
|
-
instance_list = await client.list_instances(ListInstanceParam(service_name='nacos.test.1', healthy_only=False))
|
|
567
|
-
instance_list = await client.list_instances(ListInstanceParam(service_name='nacos.test.1', healthy_only=None))
|
|
557
|
+
### Subscribe Service Instances Changed
|
|
568
558
|
|
|
569
|
-
|
|
559
|
+
>`NacosClient.subscribe(listener_fn, listener_interval=7, *args, **kwargs)`
|
|
570
560
|
|
|
571
|
-
|
|
561
|
+
* `param` *listener_fn* **required** Customized listener function. with signature `fn_listener1(event, instance)->None`
|
|
562
|
+
* `param` *listener_interval* Listen interval , default 7 second.
|
|
563
|
+
* `param` *service_name* **required** Service name which subscribes.
|
|
564
|
+
* `param` *clusters* Cluster names separated by comma.
|
|
565
|
+
* `param` *namespace_id* Customized group name, default `blank`.
|
|
566
|
+
* `param` *group_name* Customized group name , default `DEFAULT_GROUP`.
|
|
567
|
+
* `param` *healthy_only* A bool value for querying healthy instances or not.
|
|
568
|
+
* `return`
|
|
572
569
|
|
|
573
|
-
|
|
574
|
-
async def cb(instance_list: list[Instance]):
|
|
575
|
-
print('received subscribe callback', str(instance_list))
|
|
570
|
+
### Unsubscribe Service Instances Changed
|
|
576
571
|
|
|
577
|
-
|
|
578
|
-
SubscribeServiceParam(service_name='nacos.test.1', group_name='DEFAULT_GROUP', subscribe_callback=cb))
|
|
579
|
-
```
|
|
572
|
+
> `NacosClient.unsubscribe(service_name, listener_name)`
|
|
580
573
|
|
|
574
|
+
* `param` *service_name* **required** Service name to subscribed.
|
|
575
|
+
* `param` *listener_name* listener_name which is customized.
|
|
576
|
+
* `return`
|
|
581
577
|
|
|
582
|
-
###
|
|
578
|
+
### Stop All Service Subscribe
|
|
583
579
|
|
|
584
|
-
|
|
585
|
-
async def cb(instance_list: list[Instance]):
|
|
586
|
-
print('received subscribe callback', str(instance_list))
|
|
580
|
+
> `NacosClient.stop_subscribe()`
|
|
587
581
|
|
|
588
|
-
|
|
589
|
-
|
|
582
|
+
* `return`
|
|
583
|
+
|
|
584
|
+
## Debugging Mode
|
|
585
|
+
|
|
586
|
+
Debugging mode if useful for getting more detailed log on console.
|
|
587
|
+
|
|
588
|
+
Debugging mode can be set by:
|
|
589
|
+
|
|
590
|
+
```
|
|
591
|
+
client = nacos.NacosClient(SERVER_ADDRESSES, namespace=NAMESPACE, username=USERNAME, password=PASSWORD,log_level="DEBUG")
|
|
590
592
|
```
|
|
591
593
|
Keywords: nacos,nacos-sdk-python
|
|
592
594
|
Platform: UNKNOWN
|