# nacos-client-py
## 安装
```
pip install nacos-client-py
```
## 使用说明
## 配置项
```json
# nacos 服务配置
SERVER_ADDRESSES = ""
NAMESPACE = ""
USERNAME = ""
PASSWORD = ""
# 服务名
SERVICE_NAME = ""
# 服务端口
SERVICE_PORT = 8080
```
### 服务注册
```
import config
from nacos_client import NacosClient, get_local_ip
nc = NacosClient(config.SERVER_ADDRESSES, config.NAMESPACE, config.USERNAME, config.PASSWORD)
# 服务注册
nc.register(config.SERVICE_NAME, get_local_ip(), config.SERVICE_PORT)
# 开启调试模式
nc.set_debugging()
```
### 服务调用
```
import config
from nacos_client import NacosClient
nc = NacosClient(config.SERVER_ADDRESSES, config.NAMESPACE, config.USERNAME, config.PASSWORD)
@nc.request(service='test-service', path='/test', method='GET')
def test_get():
pass
@nc.request(service='test-service', path='/test', method='POST')
def test_post():
pass
# 服务调用 参数传递遵循requests参数规范。
try:
# get请求参数使用params键传递
response = test_get(params={'test': 'test'})
# post表单
response = test_post(data={'test': 'test'}, headers={'Token': 'test'})
# post json
response = test_post(json={'test': 'test'}, timeout=5)
print(response.json())
except Exception as e:
print(str(e))
```
Raw data
{
"_id": null,
"home_page": "",
"name": "nacos-client-py",
"maintainer": "",
"docs_url": null,
"requires_python": ">=3.6",
"maintainer_email": "",
"keywords": "nacos-client-py",
"author": "rencanwei",
"author_email": "rencanwei@58.com",
"download_url": "https://files.pythonhosted.org/packages/5a/46/2f31dd3b628e1eaadc9fd58b8785ba1022c24968c7c792050bb9d4855305/nacos-client-py-0.0.17.tar.gz",
"platform": null,
"description": "\n# nacos-client-py\n## \u5b89\u88c5\n```\npip install nacos-client-py\n```\n## \u4f7f\u7528\u8bf4\u660e\n## \u914d\u7f6e\u9879\n```json\n\n# nacos \u670d\u52a1\u914d\u7f6e\nSERVER_ADDRESSES = \"\"\nNAMESPACE = \"\"\nUSERNAME = \"\"\nPASSWORD = \"\"\n\n# \u670d\u52a1\u540d\nSERVICE_NAME = \"\"\n# \u670d\u52a1\u7aef\u53e3\nSERVICE_PORT = 8080\n\n```\n### \u670d\u52a1\u6ce8\u518c\n```\nimport config\nfrom nacos_client import NacosClient, get_local_ip\n\nnc = NacosClient(config.SERVER_ADDRESSES, config.NAMESPACE, config.USERNAME, config.PASSWORD)\n\n# \u670d\u52a1\u6ce8\u518c\nnc.register(config.SERVICE_NAME, get_local_ip(), config.SERVICE_PORT)\n\n# \u5f00\u542f\u8c03\u8bd5\u6a21\u5f0f\nnc.set_debugging()\n```\n### \u670d\u52a1\u8c03\u7528\n```\nimport config\nfrom nacos_client import NacosClient\n\nnc = NacosClient(config.SERVER_ADDRESSES, config.NAMESPACE, config.USERNAME, config.PASSWORD)\n\n\n@nc.request(service='test-service', path='/test', method='GET')\ndef test_get():\n pass\n\n\n@nc.request(service='test-service', path='/test', method='POST')\ndef test_post():\n pass\n\n\n# \u670d\u52a1\u8c03\u7528 \u53c2\u6570\u4f20\u9012\u9075\u5faarequests\u53c2\u6570\u89c4\u8303\u3002\ntry:\n # get\u8bf7\u6c42\u53c2\u6570\u4f7f\u7528params\u952e\u4f20\u9012\n response = test_get(params={'test': 'test'})\n\n # post\u8868\u5355\n response = test_post(data={'test': 'test'}, headers={'Token': 'test'})\n\n # post json\n response = test_post(json={'test': 'test'}, timeout=5)\n\n print(response.json())\n\nexcept Exception as e:\n print(str(e))\n```\n\n\n",
"bugtrack_url": null,
"license": "Apache License 2.0",
"summary": "Python client for Nacos",
"version": "0.0.17",
"project_urls": null,
"split_keywords": [
"nacos-client-py"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "f6209002283934d26b185a86e3a2b07cf3ba74cd70d7b4a2a60838595d50d3b4",
"md5": "99437012fe4a5d5c5fa55dc27a07aa48",
"sha256": "62d9172e0b03475a0193cc67f26a3ed1dd42882235d4044aa51237f9c1a3d4a8"
},
"downloads": -1,
"filename": "nacos_client_py-0.0.17-py2.py3-none-any.whl",
"has_sig": false,
"md5_digest": "99437012fe4a5d5c5fa55dc27a07aa48",
"packagetype": "bdist_wheel",
"python_version": "py2.py3",
"requires_python": ">=3.6",
"size": 18031,
"upload_time": "2023-05-26T09:20:03",
"upload_time_iso_8601": "2023-05-26T09:20:03.503998Z",
"url": "https://files.pythonhosted.org/packages/f6/20/9002283934d26b185a86e3a2b07cf3ba74cd70d7b4a2a60838595d50d3b4/nacos_client_py-0.0.17-py2.py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "5a462f31dd3b628e1eaadc9fd58b8785ba1022c24968c7c792050bb9d4855305",
"md5": "a5fed18d562df0679ed0ac8c3b6c739e",
"sha256": "91d4044eab1ca8a49981366f752758f3fdece3ee3852c0783de2fd34a7632f30"
},
"downloads": -1,
"filename": "nacos-client-py-0.0.17.tar.gz",
"has_sig": false,
"md5_digest": "a5fed18d562df0679ed0ac8c3b6c739e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6",
"size": 16179,
"upload_time": "2023-05-26T09:20:06",
"upload_time_iso_8601": "2023-05-26T09:20:06.281953Z",
"url": "https://files.pythonhosted.org/packages/5a/46/2f31dd3b628e1eaadc9fd58b8785ba1022c24968c7c792050bb9d4855305/nacos-client-py-0.0.17.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2023-05-26 09:20:06",
"github": false,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"lcname": "nacos-client-py"
}