nacos-sdk-python 0.1.7__tar.gz → 0.1.16__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.
@@ -0,0 +1,259 @@
1
+ Metadata-Version: 2.1
2
+ Name: nacos-sdk-python
3
+ Version: 0.1.16
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
+ A Python implementation of Nacos OpenAPI.
15
+
16
+ see: https://nacos.io/zh-cn/docs/open-API.html
17
+
18
+ [![Pypi Version](https://badge.fury.io/py/nacos-sdk-python.svg)](https://badge.fury.io/py/nacos-sdk-python)
19
+ [![License](https://img.shields.io/badge/license-Apache%202.0-blue.svg)](https://github.com/nacos-group/nacos-sdk-python/blob/master/LICENSE)
20
+
21
+
22
+ ### Supported Python version:
23
+
24
+ Python 2.7
25
+ Python 3.6
26
+ Python 3.7
27
+
28
+ ### Supported Nacos version
29
+ Nacos 0.8.0 ~ 1.3.2
30
+
31
+
32
+ ## Installation
33
+ ```shell
34
+ pip install nacos-sdk-python
35
+ ```
36
+
37
+ ## Getting Started
38
+ ```python
39
+ import nacos
40
+
41
+ # Both HTTP/HTTPS protocols are supported, if not set protocol prefix default is HTTP, and HTTPS with no ssl check(verify=False)
42
+ # "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"
43
+ SERVER_ADDRESSES = "server addresses split by comma"
44
+ NAMESPACE = "namespace id"
45
+
46
+ # no auth mode
47
+ client = nacos.NacosClient(SERVER_ADDRESSES, namespace=NAMESPACE)
48
+ # auth mode
49
+ #client = nacos.NacosClient(SERVER_ADDRESSES, namespace=NAMESPACE, ak="{ak}", sk="{sk}")
50
+
51
+ # get config
52
+ data_id = "config.nacos"
53
+ group = "group"
54
+ print(client.get_config(data_id, group))
55
+ ```
56
+
57
+ ## Configuration
58
+ ```
59
+ client = NacosClient(server_addresses, namespace=your_ns, ak=your_ak, sk=your_sk)
60
+ ```
61
+
62
+ * *server_addresses* - **required** - Nacos server address, comma separated if more than 1.
63
+ * *namespace* - Namespace. | default: `None`
64
+ * *ak* - The accessKey to authenticate. | default: null
65
+ * *sk* - The secretKey to authentication. | default: null
66
+ * *log_level* - Log level. | default: null
67
+ * *log_rotation_backup_count* - The number of log files to keep. | default: `7`
68
+
69
+ #### Extra Options
70
+ Extra option can be set by `set_options`, as following:
71
+
72
+ ```
73
+ client.set_options({key}={value})
74
+ # client.set_options(proxies={"http":"192.168.3.50:809"})
75
+ ```
76
+
77
+ Configurable options are:
78
+
79
+ * *default_timeout* - Default timeout for get config from server in seconds.
80
+ * *pulling_timeout* - Long polling timeout in seconds.
81
+ * *pulling_config_size* - Max config items number listened by one polling process.
82
+ * *callback_thread_num* - Concurrency for invoking callback.
83
+ * *failover_base* - Dir to store failover config files.
84
+ * *snapshot_base* - Dir to store snapshot config files.
85
+ * *no_snapshot* - To disable default snapshot behavior, this can be overridden by param *no_snapshot* in *get* method.
86
+ * *proxies* - Dict proxy mapping, some environments require proxy access, so you can set this parameter, this way http requests go through the proxy.
87
+
88
+ ## API Reference
89
+
90
+ ### Get Config
91
+ >`NacosClient.get_config(data_id, group, timeout, no_snapshot)`
92
+
93
+ * `param` *data_id* Data id.
94
+ * `param` *group* Group, use `DEFAULT_GROUP` if no group specified.
95
+ * `param` *timeout* Timeout for requesting server in seconds.
96
+ * `param` *no_snapshot* Whether to use local snapshot while server is unavailable.
97
+ * `return`
98
+ W
99
+ Get value of one config item following priority:
100
+
101
+ * Step 1 - Get from local failover dir(default: `${cwd}/nacos-data/data`).
102
+ * Failover dir can be manually copied from snapshot dir(default: `${cwd}/nacos-data/snapshot`) in advance.
103
+ * This helps to suppress the effect of known server failure.
104
+
105
+ * Step 2 - Get from one server until value is got or all servers tried.
106
+ * Content will be save to snapshot dir after got from server.
107
+
108
+ * Step 3 - Get from snapshot dir.
109
+
110
+ ### Add Watchers
111
+ >`NacosClient.add_config_watchers(data_id, group, cb_list)`
112
+
113
+ * `param` *data_id* Data id.
114
+ * `param` *group* Group, use `DEFAULT_GROUP` if no group specified.
115
+ * `param` *cb_list* List of callback functions to add.
116
+ * `return`
117
+
118
+ Add watchers to a specified config item.
119
+ * Once changes or deletion of the item happened, callback functions will be invoked.
120
+ * If the item is already exists in server, callback functions will be invoked for once.
121
+ * Multiple callbacks on one item is allowed and all callback functions are invoked concurrently by `threading.Thread`.
122
+ * Callback functions are invoked from current process.
123
+
124
+ ### Remove Watcher
125
+ >`NacosClient.remove_config_watcher(data_id, group, cb, remove_all)`
126
+
127
+ * `param` *data_id* Data id.
128
+ * `param` *group* Group, use "DEFAULT_GROUP" if no group specified.
129
+ * `param` *cb* Callback function to delete.
130
+ * `param` *remove_all* Whether to remove all occurrence of the callback or just once.
131
+ * `return`
132
+
133
+ Remove watcher from specified key.
134
+
135
+ ### Publish Config
136
+ >`NacosClient.publish_config(data_id, group, content, timeout)`
137
+
138
+ * `param` *data_id* Data id.
139
+ * `param` *group* Group, use "DEFAULT_GROUP" if no group specified.
140
+ * `param` *content* Config value.
141
+ * `param` *timeout* Timeout for requesting server in seconds.
142
+ * `return` True if success or an exception will be raised.
143
+
144
+ Publish one data item to Nacos.
145
+ * If the data key is not exist, create one first.
146
+ * If the data key is exist, update to the content specified.
147
+ * Content can not be set to None, if there is need to delete config item, use function **remove** instead.
148
+
149
+ ### Remove Config
150
+ >`NacosClient.remove_config(data_id, group, timeout)`
151
+ * `param` *data_id* Data id.
152
+ * `param` *group* Group, use "DEFAULT_GROUP" if no group specified.
153
+ * `param` *timeout* Timeout for requesting server in seconds.
154
+ * `return` True if success or an exception will be raised.
155
+
156
+ Remove one data item from Nacos.
157
+
158
+ ### Register Instance
159
+ >`NacosClient.add_naming_instance(service_name, ip, port, cluster_name, weight, metadata, enable, healthy,ephemeral,group_name,heartbeat_interval)`
160
+ * `param` *service_name* **required** Service name to register to.
161
+ * `param` *ip* **required** IP of the instance.
162
+ * `param` *port* **required** Port of the instance.
163
+ * `param` *cluster_name* Cluster to register to.
164
+ * `param` *weight* A float number for load balancing weight.
165
+ * `param` *metadata* Extra info in JSON string format or dict format
166
+ * `param` *enable* A bool value to determine whether instance is enabled or not.
167
+ * `param` *healthy* A bool value to determine whether instance is healthy or not.
168
+ * `param` *ephemeral* A bool value to determine whether instance is ephemeral or not.
169
+ * `param` *heartbeat_interval* Auto daemon heartbeat interval in seconds.
170
+ * `return` True if success or an exception will be raised.
171
+
172
+ ### Deregister Instance
173
+ >`NacosClient.remove_naming_instance(service_name, ip, port, cluster_name)`
174
+ * `param` *service_name* **required** Service name to deregister from.
175
+ * `param` *ip* **required** IP of the instance.
176
+ * `param` *port* **required** Port of the instance.
177
+ * `param` *cluster_name* Cluster to deregister from.
178
+ * `param` *ephemeral* A bool value to determine whether instance is ephemeral or not.
179
+ * `return` True if success or an exception will be raised.
180
+
181
+ ### Modify Instance
182
+ >`NacosClient.modify_naming_instance(service_name, ip, port, cluster_name, weight, metadata, enable)`
183
+ * `param` *service_name* **required** Service name.
184
+ * `param` *ip* **required** IP of the instance.
185
+ * `param` *port* **required** Port of the instance.
186
+ * `param` *cluster_name* Cluster name.
187
+ * `param` *weight* A float number for load balancing weight.
188
+ * `param` *metadata* Extra info in JSON string format or dict format.
189
+ * `param` *enable* A bool value to determine whether instance is enabled or not.
190
+ * `param` *ephemeral* A bool value to determine whether instance is ephemeral or not.
191
+ * `return` True if success or an exception will be raised.
192
+
193
+ ### Query Instances
194
+ >`NacosClient.list_naming_instance(service_name, clusters, namespace_id, group_name, healthy_only)`
195
+ * `param` *service_name* **required** Service name to query.
196
+ * `param` *clusters* Cluster names separated by comma.
197
+ * `param` *namespace_id* Customized group name, default `blank`.
198
+ * `param` *group_name* Customized group name , default `DEFAULT_GROUP`.
199
+ * `param` *healthy_only* A bool value for querying healthy instances or not.
200
+ * `return` Instance info list if success or an exception will be raised.
201
+
202
+ ### Query Instance Detail
203
+ >`NacosClient.get_naming_instance(service_name, ip, port, cluster_name)`
204
+ * `param` *service_name* **required** Service name.
205
+ * `param` *ip* **required** IP of the instance.
206
+ * `param` *port* **required** Port of the instance.
207
+ * `param` *cluster_name* Cluster name.
208
+ * `return` Instance info if success or an exception will be raised.
209
+
210
+ ### Send Instance Beat
211
+ >`NacosClient.send_heartbeat(service_name, ip, port, cluster_name, weight, metadata)`
212
+ * `param` *service_name* **required** Service name.
213
+ * `param` *ip* **required** IP of the instance.
214
+ * `param` *port* **required** Port of the instance.
215
+ * `param` *cluster_name* Cluster to register to.
216
+ * `param` *weight* A float number for load balancing weight.
217
+ * `param` *ephemeral* A bool value to determine whether instance is ephemeral or not.
218
+ * `param` *metadata* Extra info in JSON string format or dict format.
219
+ * `return` A JSON object include server recommended beat interval if success or an exception will be raised.
220
+
221
+ ### Subscribe Service Instances Changed
222
+ >`NacosClient.subscribe(listener_fn, listener_interval=7, *args, **kwargs)`
223
+ * `param` *listener_fn* **required** Customized listener function.
224
+ * `param` *listener_interval* Listen interval , default 7 second.
225
+ * `param` *service_name* **required** Service name which subscribes.
226
+ * `param` *clusters* Cluster names separated by comma.
227
+ * `param` *namespace_id* Customized group name, default `blank`.
228
+ * `param` *group_name* Customized group name , default `DEFAULT_GROUP`.
229
+ * `param` *healthy_only* A bool value for querying healthy instances or not.
230
+ * `return`
231
+
232
+ ### Unsubscribe Service Instances Changed
233
+ >`NacosClient.unsubscribe(service_name, listener_name)`
234
+ * `param` *service_name* **required** Service name to subscribed.
235
+ * `param` *listener_name* listener_name which is customized.
236
+ * `return`
237
+
238
+ ### Stop All Service Subscribe
239
+ >`NacosClient.stop_subscribe()`
240
+ * `return`
241
+
242
+ ## Debugging Mode
243
+ Debugging mode if useful for getting more detailed log on console.
244
+
245
+ Debugging mode can be set by:
246
+ ```
247
+ client = nacos.NacosClient(SERVER_ADDRESSES, namespace=NAMESPACE, username=USERNAME, password=PASSWORD,log_level="DEBUG")
248
+ ```
249
+
250
+
251
+ Keywords: nacos,nacos-sdk-python
252
+ Platform: UNKNOWN
253
+ Classifier: Topic :: Software Development :: Libraries :: Python Modules
254
+ Classifier: Operating System :: OS Independent
255
+ Classifier: Programming Language :: Python
256
+ Classifier: Programming Language :: Python :: 2.7
257
+ Classifier: Programming Language :: Python :: 3.6
258
+ Classifier: Programming Language :: Python :: 3.7
259
+ Description-Content-Type: text/markdown
@@ -34,7 +34,7 @@ NAMESPACE = "namespace id"
34
34
  # no auth mode
35
35
  client = nacos.NacosClient(SERVER_ADDRESSES, namespace=NAMESPACE)
36
36
  # auth mode
37
- #client = nacos.NacosClient(SERVER_ADDRESSES, namespace=NAMESPACE, username="nacos", password="nacos")
37
+ #client = nacos.NacosClient(SERVER_ADDRESSES, namespace=NAMESPACE, ak="{ak}", sk="{sk}")
38
38
 
39
39
  # get config
40
40
  data_id = "config.nacos"
@@ -44,11 +44,15 @@ print(client.get_config(data_id, group))
44
44
 
45
45
  ## Configuration
46
46
  ```
47
- client = NacosClient(server_addresses, namespace=your_ns)
47
+ client = NacosClient(server_addresses, namespace=your_ns, ak=your_ak, sk=your_sk)
48
48
  ```
49
49
 
50
50
  * *server_addresses* - **required** - Nacos server address, comma separated if more than 1.
51
51
  * *namespace* - Namespace. | default: `None`
52
+ * *ak* - The accessKey to authenticate. | default: null
53
+ * *sk* - The secretKey to authentication. | default: null
54
+ * *log_level* - Log level. | default: null
55
+ * *log_rotation_backup_count* - The number of log files to keep. | default: `7`
52
56
 
53
57
  #### Extra Options
54
58
  Extra option can be set by `set_options`, as following:
@@ -140,7 +144,7 @@ Publish one data item to Nacos.
140
144
  Remove one data item from Nacos.
141
145
 
142
146
  ### Register Instance
143
- >`NacosClient.add_naming_instance(service_name, ip, port, cluster_name, weight, metadata, enable, healthy)`
147
+ >`NacosClient.add_naming_instance(service_name, ip, port, cluster_name, weight, metadata, enable, healthy,ephemeral,group_name,heartbeat_interval)`
144
148
  * `param` *service_name* **required** Service name to register to.
145
149
  * `param` *ip* **required** IP of the instance.
146
150
  * `param` *port* **required** Port of the instance.
@@ -150,6 +154,7 @@ Remove one data item from Nacos.
150
154
  * `param` *enable* A bool value to determine whether instance is enabled or not.
151
155
  * `param` *healthy* A bool value to determine whether instance is healthy or not.
152
156
  * `param` *ephemeral* A bool value to determine whether instance is ephemeral or not.
157
+ * `param` *heartbeat_interval* Auto daemon heartbeat interval in seconds.
153
158
  * `return` True if success or an exception will be raised.
154
159
 
155
160
  ### Deregister Instance
@@ -227,7 +232,6 @@ Debugging mode if useful for getting more detailed log on console.
227
232
 
228
233
  Debugging mode can be set by:
229
234
  ```
230
- NacosClient.set_debugging()
231
- # only effective within the current process
235
+ client = nacos.NacosClient(SERVER_ADDRESSES, namespace=NAMESPACE, username=USERNAME, password=PASSWORD,log_level="DEBUG")
232
236
  ```
233
237