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