nacos-sdk-python 0.1.17b1__tar.gz → 2.0.0__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.
Files changed (112) hide show
  1. nacos-sdk-python-2.0.0/PKG-INFO +597 -0
  2. nacos-sdk-python-2.0.0/README.md +576 -0
  3. {nacos-sdk-python-0.1.17b1 → nacos-sdk-python-2.0.0}/nacos/client.py +32 -30
  4. nacos-sdk-python-2.0.0/nacos_sdk_python.egg-info/PKG-INFO +597 -0
  5. nacos-sdk-python-2.0.0/nacos_sdk_python.egg-info/SOURCES.txt +105 -0
  6. nacos-sdk-python-2.0.0/nacos_sdk_python.egg-info/requires.txt +9 -0
  7. {nacos-sdk-python-0.1.17b1 → nacos-sdk-python-2.0.0}/nacos_sdk_python.egg-info/top_level.txt +1 -0
  8. {nacos-sdk-python-0.1.17b1 → nacos-sdk-python-2.0.0}/setup.py +7 -4
  9. nacos-sdk-python-2.0.0/v2/__init__.py +0 -0
  10. nacos-sdk-python-2.0.0/v2/nacos/__init__.py +41 -0
  11. nacos-sdk-python-2.0.0/v2/nacos/common/__init__.py +0 -0
  12. nacos-sdk-python-2.0.0/v2/nacos/common/client_config.py +127 -0
  13. nacos-sdk-python-2.0.0/v2/nacos/common/client_config_builder.py +94 -0
  14. nacos-sdk-python-2.0.0/v2/nacos/common/constants.py +227 -0
  15. nacos-sdk-python-2.0.0/v2/nacos/common/nacos_exception.py +40 -0
  16. nacos-sdk-python-2.0.0/v2/nacos/common/payload_registry.py +24 -0
  17. nacos-sdk-python-2.0.0/v2/nacos/common/preserved_metadata_key.py +10 -0
  18. nacos-sdk-python-2.0.0/v2/nacos/config/__init__.py +0 -0
  19. nacos-sdk-python-2.0.0/v2/nacos/config/cache/__init__.py +0 -0
  20. nacos-sdk-python-2.0.0/v2/nacos/config/cache/config_info_cache.py +48 -0
  21. nacos-sdk-python-2.0.0/v2/nacos/config/cache/config_subscribe_manager.py +99 -0
  22. nacos-sdk-python-2.0.0/v2/nacos/config/encryption/__init__.py +0 -0
  23. nacos-sdk-python-2.0.0/v2/nacos/config/encryption/kms_client.py +41 -0
  24. nacos-sdk-python-2.0.0/v2/nacos/config/encryption/kms_handler.py +46 -0
  25. nacos-sdk-python-2.0.0/v2/nacos/config/encryption/plugin/__init__.py +0 -0
  26. nacos-sdk-python-2.0.0/v2/nacos/config/encryption/plugin/encryption_plugin.py +30 -0
  27. nacos-sdk-python-2.0.0/v2/nacos/config/encryption/plugin/kms_aes_128_encrytion_plugin.py +21 -0
  28. nacos-sdk-python-2.0.0/v2/nacos/config/encryption/plugin/kms_aes_256_encrytion_plugin.py +21 -0
  29. nacos-sdk-python-2.0.0/v2/nacos/config/encryption/plugin/kms_base_encryption_plugin.py +39 -0
  30. nacos-sdk-python-2.0.0/v2/nacos/config/encryption/plugin/kms_encrytion_plugin.py +51 -0
  31. nacos-sdk-python-2.0.0/v2/nacos/config/filter/__init__.py +0 -0
  32. nacos-sdk-python-2.0.0/v2/nacos/config/filter/config_encryption_filter.py +37 -0
  33. nacos-sdk-python-2.0.0/v2/nacos/config/filter/config_filter.py +47 -0
  34. nacos-sdk-python-2.0.0/v2/nacos/config/model/__init__.py +0 -0
  35. nacos-sdk-python-2.0.0/v2/nacos/config/model/config.py +103 -0
  36. nacos-sdk-python-2.0.0/v2/nacos/config/model/config_param.py +49 -0
  37. nacos-sdk-python-2.0.0/v2/nacos/config/model/config_request.py +58 -0
  38. nacos-sdk-python-2.0.0/v2/nacos/config/model/config_response.py +43 -0
  39. nacos-sdk-python-2.0.0/v2/nacos/config/nacos_config_service.py +122 -0
  40. nacos-sdk-python-2.0.0/v2/nacos/config/remote/__init__.py +0 -0
  41. nacos-sdk-python-2.0.0/v2/nacos/config/remote/config_change_notify_request_handler.py +29 -0
  42. nacos-sdk-python-2.0.0/v2/nacos/config/remote/config_grpc_client_proxy.py +252 -0
  43. nacos-sdk-python-2.0.0/v2/nacos/config/remote/config_grpc_connection_event_listener.py +23 -0
  44. nacos-sdk-python-2.0.0/v2/nacos/config/util/__init__.py +0 -0
  45. nacos-sdk-python-2.0.0/v2/nacos/config/util/config_client_util.py +5 -0
  46. nacos-sdk-python-2.0.0/v2/nacos/nacos_client.py +57 -0
  47. nacos-sdk-python-2.0.0/v2/nacos/naming/__init__.py +0 -0
  48. nacos-sdk-python-2.0.0/v2/nacos/naming/cache/__init__.py +0 -0
  49. nacos-sdk-python-2.0.0/v2/nacos/naming/cache/service_info_cache.py +141 -0
  50. nacos-sdk-python-2.0.0/v2/nacos/naming/cache/subscribe_manager.py +35 -0
  51. nacos-sdk-python-2.0.0/v2/nacos/naming/event/__init__.py +0 -0
  52. nacos-sdk-python-2.0.0/v2/nacos/naming/event/instance_change_notifier.py +5 -0
  53. nacos-sdk-python-2.0.0/v2/nacos/naming/model/__init__.py +0 -0
  54. nacos-sdk-python-2.0.0/v2/nacos/naming/model/instance.py +83 -0
  55. nacos-sdk-python-2.0.0/v2/nacos/naming/model/naming_param.py +60 -0
  56. nacos-sdk-python-2.0.0/v2/nacos/naming/model/naming_request.py +63 -0
  57. nacos-sdk-python-2.0.0/v2/nacos/naming/model/naming_response.py +37 -0
  58. nacos-sdk-python-2.0.0/v2/nacos/naming/model/service.py +117 -0
  59. nacos-sdk-python-2.0.0/v2/nacos/naming/nacos_naming_service.py +199 -0
  60. nacos-sdk-python-2.0.0/v2/nacos/naming/remote/__init__.py +0 -0
  61. nacos-sdk-python-2.0.0/v2/nacos/naming/remote/naming_grpc_client_proxy.py +190 -0
  62. nacos-sdk-python-2.0.0/v2/nacos/naming/remote/naming_grpc_connection_event_listener.py +70 -0
  63. nacos-sdk-python-2.0.0/v2/nacos/naming/remote/naming_push_request_handler.py +27 -0
  64. nacos-sdk-python-2.0.0/v2/nacos/naming/util/__init__.py +0 -0
  65. nacos-sdk-python-2.0.0/v2/nacos/naming/util/naming_client_util.py +11 -0
  66. nacos-sdk-python-2.0.0/v2/nacos/naming/util/naming_remote_constants.py +18 -0
  67. nacos-sdk-python-2.0.0/v2/nacos/proto/__init__.py +0 -0
  68. nacos-sdk-python-2.0.0/v2/nacos/transport/__init__.py +0 -0
  69. nacos-sdk-python-2.0.0/v2/nacos/transport/auth_client.py +47 -0
  70. nacos-sdk-python-2.0.0/v2/nacos/transport/connection.py +34 -0
  71. nacos-sdk-python-2.0.0/v2/nacos/transport/connection_event_listener.py +12 -0
  72. nacos-sdk-python-2.0.0/v2/nacos/transport/grpc_client.py +158 -0
  73. nacos-sdk-python-2.0.0/v2/nacos/transport/grpc_connection.py +46 -0
  74. nacos-sdk-python-2.0.0/v2/nacos/transport/grpc_util.py +84 -0
  75. nacos-sdk-python-2.0.0/v2/nacos/transport/grpcauto/__init__.py +0 -0
  76. nacos-sdk-python-2.0.0/v2/nacos/transport/grpcauto/nacos_grpc_service_pb2.py +51 -0
  77. nacos-sdk-python-2.0.0/v2/nacos/transport/grpcauto/nacos_grpc_service_pb2_grpc.py +244 -0
  78. nacos-sdk-python-2.0.0/v2/nacos/transport/http_agent.py +58 -0
  79. nacos-sdk-python-2.0.0/v2/nacos/transport/model/__init__.py +1 -0
  80. nacos-sdk-python-2.0.0/v2/nacos/transport/model/internal_request.py +57 -0
  81. nacos-sdk-python-2.0.0/v2/nacos/transport/model/internal_response.py +42 -0
  82. nacos-sdk-python-2.0.0/v2/nacos/transport/model/rpc_request.py +41 -0
  83. nacos-sdk-python-2.0.0/v2/nacos/transport/model/rpc_response.py +40 -0
  84. nacos-sdk-python-2.0.0/v2/nacos/transport/model/server_info.py +25 -0
  85. nacos-sdk-python-2.0.0/v2/nacos/transport/nacos_server_connector.py +97 -0
  86. nacos-sdk-python-2.0.0/v2/nacos/transport/rpc_client.py +470 -0
  87. nacos-sdk-python-2.0.0/v2/nacos/transport/rpc_client_factory.py +117 -0
  88. nacos-sdk-python-2.0.0/v2/nacos/transport/server_request_handler.py +30 -0
  89. nacos-sdk-python-2.0.0/v2/nacos/utils/__init__.py +0 -0
  90. nacos-sdk-python-2.0.0/v2/nacos/utils/aes_util.py +36 -0
  91. nacos-sdk-python-2.0.0/v2/nacos/utils/common_util.py +44 -0
  92. nacos-sdk-python-2.0.0/v2/nacos/utils/content_util.py +9 -0
  93. nacos-sdk-python-2.0.0/v2/nacos/utils/encode_util.py +32 -0
  94. nacos-sdk-python-2.0.0/v2/nacos/utils/file_util.py +94 -0
  95. nacos-sdk-python-2.0.0/v2/nacos/utils/hmac_util.py +13 -0
  96. nacos-sdk-python-2.0.0/v2/nacos/utils/md5_util.py +9 -0
  97. nacos-sdk-python-2.0.0/v2/nacos/utils/net_util.py +20 -0
  98. nacos-sdk-python-0.1.17b1/PKG-INFO +0 -261
  99. nacos-sdk-python-0.1.17b1/README.md +0 -239
  100. nacos-sdk-python-0.1.17b1/nacos/cocurrency_adapter.py +0 -44
  101. nacos-sdk-python-0.1.17b1/nacos_sdk_python.egg-info/PKG-INFO +0 -261
  102. nacos-sdk-python-0.1.17b1/nacos_sdk_python.egg-info/SOURCES.txt +0 -16
  103. {nacos-sdk-python-0.1.17b1 → nacos-sdk-python-2.0.0}/nacos/__init__.py +0 -0
  104. {nacos-sdk-python-0.1.17b1 → nacos-sdk-python-2.0.0}/nacos/commons.py +0 -0
  105. {nacos-sdk-python-0.1.17b1 → nacos-sdk-python-2.0.0}/nacos/exception.py +0 -0
  106. {nacos-sdk-python-0.1.17b1 → nacos-sdk-python-2.0.0}/nacos/files.py +0 -0
  107. {nacos-sdk-python-0.1.17b1 → nacos-sdk-python-2.0.0}/nacos/listener.py +0 -0
  108. {nacos-sdk-python-0.1.17b1 → nacos-sdk-python-2.0.0}/nacos/params.py +0 -0
  109. {nacos-sdk-python-0.1.17b1 → nacos-sdk-python-2.0.0}/nacos/task.py +0 -0
  110. {nacos-sdk-python-0.1.17b1 → nacos-sdk-python-2.0.0}/nacos/timer.py +0 -0
  111. {nacos-sdk-python-0.1.17b1 → nacos-sdk-python-2.0.0}/nacos_sdk_python.egg-info/dependency_links.txt +0 -0
  112. {nacos-sdk-python-0.1.17b1 → nacos-sdk-python-2.0.0}/setup.cfg +0 -0
@@ -0,0 +1,597 @@
1
+ Metadata-Version: 2.1
2
+ Name: nacos-sdk-python
3
+ Version: 2.0.0
4
+ Summary: Python client for Nacos.
5
+ Home-page: https://github.com/nacos-group/nacos-sdk-python
6
+ Author: nacos
7
+ Author-email: 755063194@qq.com
8
+ License: Apache License 2.0
9
+ Project-URL: Documentation, https://github.com/nacos-group/nacos-sdk-python
10
+ Project-URL: Source, https://github.com/nacos-group/nacos-sdk-python
11
+ Project-URL: Nacos Open API Guide, https://nacos.io/en-us/docs/open-api.html
12
+ Description:
13
+ # nacos-sdk-python
14
+
15
+ A Python implementation of Nacos OpenAPI.
16
+
17
+ see: https://nacos.io/docs/latest/guide/user/open-api/
18
+
19
+ [![Pypi Version](https://badge.fury.io/py/nacos-sdk-python.svg)](https://badge.fury.io/py/nacos-sdk-python)
20
+ [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/nacos-group/nacos-sdk-python/blob/master/LICENSE)
21
+
22
+ ### Supported Python version:
23
+
24
+ Python 2.7
25
+ Python 3.6
26
+ Python 3.7
27
+
28
+ ### Supported Nacos version
29
+
30
+ Nacos 0.8.0+
31
+ Nacos 1.x
32
+ Nacos 2.x with http protocol
33
+
34
+ ## Installation
35
+
36
+ ```shell
37
+ pip install nacos-sdk-python
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))
59
+ ```
60
+
61
+ ## Configuration
62
+
63
+ ```
64
+ client = NacosClient(server_addresses, namespace=your_ns, ak=your_ak, sk=your_sk)
65
+ ```
66
+
67
+ * *server_addresses* - **required** - Nacos server address, comma separated if more than 1.
68
+ * *namespace* - Namespace. | default: `None`
69
+ * *ak* - The accessKey to authenticate. | default: null
70
+ * *sk* - The secretKey to authentication. | default: null
71
+ * *log_level* - Log level. | default: null
72
+ * *log_rotation_backup_count* - The number of log files to keep. | default: `7`
73
+
74
+ #### Extra Options
75
+
76
+ Extra option can be set by `set_options`, as following:
77
+
78
+ ```
79
+ client.set_options({key}={value})
80
+ # client.set_options(proxies={"http":"192.168.3.50:809"})
81
+ ```
82
+
83
+ Configurable options are:
84
+
85
+ * *default_timeout* - Default timeout for get config from server in seconds.
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.
94
+
95
+ ## API Reference
96
+
97
+ ### Get Config
98
+
99
+ > `NacosClient.get_config(data_id, group, timeout, no_snapshot)`
100
+
101
+ * `param` *data_id* Data id.
102
+ * `param` *group* Group, use `DEFAULT_GROUP` if no group specified.
103
+ * `param` *timeout* Timeout for requesting server in seconds.
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:
108
+
109
+
110
+ * Step 1 - Get from local failover dir(default: `${cwd}/nacos-data/data`).
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.
113
+
114
+ * Step 2 - Get from one server until value is got or all servers tried.
115
+ * Content will be save to snapshot dir after got from server.
116
+
117
+ * Step 3 - Get from snapshot dir.
118
+
119
+ ### Add Watchers
120
+
121
+ > `NacosClient.add_config_watchers(data_id, group, cb_list)`
122
+
123
+ * `param` *data_id* Data id.
124
+ * `param` *group* Group, use `DEFAULT_GROUP` if no group specified.
125
+ * `param` *cb_list* List of callback functions to add.
126
+ * `return`
127
+
128
+ Add watchers to a specified config item.
129
+
130
+ * Once changes or deletion of the item happened, callback functions will be invoked.
131
+ * 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
+ * Callback functions are invoked from current process.
134
+
135
+ ### Remove Watcher
136
+
137
+ > `NacosClient.remove_config_watcher(data_id, group, cb, remove_all)`
138
+
139
+ * `param` *data_id* Data id.
140
+ * `param` *group* Group, use "DEFAULT_GROUP" if no group specified.
141
+ * `param` *cb* Callback function to delete.
142
+ * `param` *remove_all* Whether to remove all occurrence of the callback or just once.
143
+ * `return`
144
+
145
+ Remove watcher from specified key.
146
+
147
+ ### Publish Config
148
+
149
+ > `NacosClient.publish_config(data_id, group, content, timeout)`
150
+
151
+ * `param` *data_id* Data id.
152
+ * `param` *group* Group, use "DEFAULT_GROUP" if no group specified.
153
+ * `param` *content* Config value.
154
+ * `param` *timeout* Timeout for requesting server in seconds.
155
+ * `return` True if success or an exception will be raised.
156
+
157
+ Publish one data item to Nacos.
158
+
159
+ * If the data key is not exist, create one first.
160
+ * If the data key is exist, update to the content specified.
161
+ * Content can not be set to None, if there is need to delete config item, use function **remove** instead.
162
+
163
+ ### Remove Config
164
+
165
+ > `NacosClient.remove_config(data_id, group, timeout)`
166
+
167
+ * `param` *data_id* Data id.
168
+ * `param` *group* Group, use "DEFAULT_GROUP" if no group specified.
169
+ * `param` *timeout* Timeout for requesting server in seconds.
170
+ * `return` True if success or an exception will be raised.
171
+
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.
190
+
191
+ ### Deregister Instance
192
+
193
+ > `NacosClient.remove_naming_instance(service_name, ip, port, cluster_name)`
194
+
195
+ * `param` *service_name* **required** Service name to deregister from.
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.
201
+
202
+ ### Modify Instance
203
+
204
+ > `NacosClient.modify_naming_instance(service_name, ip, port, cluster_name, weight, metadata, enable)`
205
+
206
+ * `param` *service_name* **required** Service name.
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.
215
+
216
+ ### Query Instances
217
+
218
+ > `NacosClient.list_naming_instance(service_name, clusters, namespace_id, group_name, healthy_only)`
219
+
220
+ * `param` *service_name* **required** Service name to query.
221
+ * `param` *clusters* Cluster names separated by comma.
222
+ * `param` *namespace_id* Customized group name, default `blank`.
223
+ * `param` *group_name* Customized group name , default `DEFAULT_GROUP`.
224
+ * `param` *healthy_only* A bool value for querying healthy instances or not.
225
+ * `return` Instance info list if success or an exception will be raised.
226
+
227
+ ### Query Instance Detail
228
+
229
+ > `NacosClient.get_naming_instance(service_name, ip, port, cluster_name)`
230
+
231
+ * `param` *service_name* **required** Service name.
232
+ * `param` *ip* **required** IP of the instance.
233
+ * `param` *port* **required** Port of the instance.
234
+ * `param` *cluster_name* Cluster name.
235
+ * `return` Instance info if success or an exception will be raised.
236
+
237
+ ### Send Instance Beat
238
+
239
+ > `NacosClient.send_heartbeat(service_name, ip, port, cluster_name, weight, metadata)`
240
+
241
+ * `param` *service_name* **required** Service name.
242
+ * `param` *ip* **required** IP of the instance.
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.
249
+
250
+ ### Subscribe Service Instances Changed
251
+
252
+ > `NacosClient.subscribe(listener_fn, listener_interval=7, *args, **kwargs)`
253
+
254
+ * `param` *listener_fn* **required** Customized listener function.
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`
262
+
263
+ ### Unsubscribe Service Instances Changed
264
+
265
+ > `NacosClient.unsubscribe(service_name, listener_name)`
266
+
267
+ * `param` *service_name* **required** Service name to subscribed.
268
+ * `param` *listener_name* listener_name which is customized.
269
+ * `return`
270
+
271
+ ### Stop All Service Subscribe
272
+
273
+ > `NacosClient.stop_subscribe()`
274
+
275
+ * `return`
276
+
277
+ ## Debugging Mode
278
+
279
+ Debugging mode if useful for getting more detailed log on console.
280
+
281
+ Debugging mode can be set by:
282
+
283
+ ```
284
+ client = nacos.NacosClient(SERVER_ADDRESSES, namespace=NAMESPACE, username=USERNAME, password=PASSWORD,log_level="DEBUG")
285
+ ```
286
+
287
+ # nacos-sdk-python v2
288
+
289
+ A Python implementation of Nacos OpenAPI.
290
+
291
+ see: https://nacos.io/zh-cn/docs/open-API.html
292
+
293
+ [![Pypi Version](https://badge.fury.io/py/nacos-sdk-python.svg)](https://badge.fury.io/py/nacos-sdk-python)
294
+ [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/nacos-group/nacos-sdk-python/blob/master/LICENSE)
295
+
296
+ ### Supported Python version:
297
+
298
+ Python 3.7+
299
+
300
+ ### Supported Nacos version
301
+
302
+ Supported Nacos version over 2.x
303
+
304
+ ## Installation
305
+
306
+ ```shell
307
+ pip install nacos-sdk-python==2.0.0b5
308
+ ```
309
+
310
+ ## Client Configuration
311
+
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
+ ```
325
+
326
+ * *server_address* - **required** - Nacos server address
327
+ * *access_key* - The aliyun accessKey to authenticate.
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.
352
+
353
+ ## Config Client
354
+
355
+ ```
356
+
357
+ config_client = await NacosConfigService.create_config_service(client_config)
358
+
359
+ ```
360
+
361
+ ### config client common parameters
362
+
363
+ > `param: ConfigParam`
364
+
365
+ * `param` *data_id* Data id.
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.
377
+
378
+ ### Get Config
379
+
380
+ ```
381
+ content = await config_client.get_config(ConfigParam(
382
+ data_id=data_id,
383
+ group=group
384
+ ))
385
+ ```
386
+
387
+ * `param` *ConfigParam* config client common parameters. When getting configuration, it is necessary to specify the
388
+ required data_id and group in param.
389
+ * `return` Config content if success or an exception will be raised.
390
+
391
+ Get value of one config item following priority:
392
+
393
+ * Step 1 - Get from local failover dir.
394
+
395
+ * Step 2 - Get from one server until value is got or all servers tried.
396
+ * Content will be saved to snapshot dir after got from server.
397
+
398
+ * Step 3 - Get from snapshot dir.
399
+
400
+ ### Add Listener
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))
405
+
406
+ await config_client.add_listener(dataID, groupName, config_listener)
407
+ ```
408
+
409
+ * `param` *ConfigParam* config client common parameters.
410
+ * `listener` *listener* Configure listener, defined by the namespace_id、group、data_id、content.
411
+ * `return`
412
+
413
+ Add Listener to a specified config item.
414
+
415
+ * Once changes or deletion of the item happened, callback functions will be invoked.
416
+ * If the item is already exists in server, callback functions will be invoked for once.
417
+ * Callback functions are invoked from current process.
418
+
419
+ ### Remove Listener
420
+
421
+ ```
422
+ await client.remove_listener(dataID, groupName, config_listener)
423
+ ```
424
+
425
+ * `param` *ConfigParam* config client common parameters.
426
+ * `return` True if success or an exception will be raised.
427
+
428
+ Remove watcher from specified key.
429
+
430
+ ### Publish Config
431
+
432
+ ```
433
+ res = await client.publish_config(ConfigParam(
434
+ data_id=dataID,
435
+ group=groupName,
436
+ content="Hello world")
437
+ )
438
+ ```
439
+
440
+ * `param` *ConfigParam* config client common parameters. When publishing configuration, it is necessary to specify the
441
+ required data_id, group and content in param.
442
+ * `return` True if success or an exception will be raised.
443
+
444
+ Publish one congfig data item to Nacos.
445
+
446
+ * If the data key is not exist, create one first.
447
+ * If the data key is exist, update to the content specified.
448
+ * Content can not be set to None, if there is need to delete config item, use function **remove** instead.
449
+
450
+ ### Remove Config
451
+
452
+ ```
453
+ res = await client.remove_config(ConfigParam(
454
+ data_id=dataID,
455
+ group=groupName
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.
460
+ * `return` True if success or an exception will be raised.
461
+
462
+ Remove one config data item from Nacos.
463
+
464
+ ### Stop Config Client
465
+
466
+ ```
467
+ await client.shutdown()
468
+ ```
469
+
470
+ ## Naming Client
471
+
472
+ ```
473
+
474
+ naming_client = await NacosNamingService.create_naming_service(client_config)
475
+
476
+ ```
477
+
478
+ ### Register Instance
479
+
480
+ ```angular2html
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
+ ```
487
+
488
+ ### Batch Register Instance
489
+ ```angular2html
490
+ param1 = RegisterInstanceParam(service_name='nacos.test.1',
491
+ group_name='DEFAULT_GROUP',
492
+ ip='1.1.1.1',
493
+ port=7001,
494
+ weight=1.0,
495
+ cluster_name='c1',
496
+ metadata={'a': 'b'},
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
+ ```
527
+
528
+ ### Deregister Instance
529
+
530
+ ```angular2html
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
+ ```
536
+
537
+ ### Update Instance
538
+ ```angular2html
539
+ response = await client.update_instance(
540
+ request=RegisterInstanceParam(service_name='nacos.test.1', group_name='DEFAULT_GROUP', ip='1.1.1.1',
541
+ port=7001, weight=2.0, cluster_name='c1', metadata={'a': 'b'},
542
+ enabled=True,
543
+ healthy=True, ephemeral=True))
544
+ ```
545
+
546
+ ### Get Service
547
+ ```angular2html
548
+ service = await client.get_service(
549
+ GetServiceParam(service_name='nacos.test.1', group_name='DEFAULT_GROUP', cluster_name='c1'))
550
+ ```
551
+
552
+ ### List Service
553
+ ```angular2html
554
+
555
+ service_list = await client.list_services(ListServiceParam())
556
+
557
+ ```
558
+
559
+ ### List Instance
560
+
561
+ ```angular2html
562
+
563
+ instance_list = await client.list_instances(ListInstanceParam(service_name='nacos.test.1', healthy_only=True))
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))
566
+
567
+ ```
568
+
569
+ ### Subscribe
570
+
571
+ ```angular2html
572
+ async def cb(instance_list: list[Instance]):
573
+ print('received subscribe callback', str(instance_list))
574
+
575
+ await client.subscribe(
576
+ SubscribeServiceParam(service_name='nacos.test.1', group_name='DEFAULT_GROUP', subscribe_callback=cb))
577
+ ```
578
+
579
+
580
+ ### Unsubscribe
581
+
582
+ ```angular2html
583
+ async def cb(instance_list: list[Instance]):
584
+ print('received subscribe callback', str(instance_list))
585
+
586
+ await client.unsubscribe(
587
+ SubscribeServiceParam(service_name='nacos.test.1', group_name='DEFAULT_GROUP', subscribe_callback=cb))
588
+ ```
589
+ Keywords: nacos,nacos-sdk-python
590
+ Platform: UNKNOWN
591
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
592
+ Classifier: Operating System :: OS Independent
593
+ Classifier: Programming Language :: Python
594
+ Classifier: Programming Language :: Python :: 2.7
595
+ Classifier: Programming Language :: Python :: 3.6
596
+ Classifier: Programming Language :: Python :: 3.7
597
+ Description-Content-Type: text/markdown