Nacos starter for python
Project description
nacos sdk for python
用户接入nacos,进行注册、配置获取等。基于nacos的web接口实现操作。
支持nacos版本
- 1.4
- 2.0
使用
注册到nacos
from nacos_starter import Nacos
# 创建初始nacos连接对象
nacos_server = Nacos(host=NACOS_SERVER_ADDR, username=NACOS_USERNAME, password=NACOS_PASSWORD)
# 配置服务注册的参数
nacos_server.register_service(service_ip=NACOS_IP,service_port=NACOS_SERVER_PORT,service_name=SERVER_NAME)
# 开启监听配置的线程和服务注册心跳进程的健康检查进程
nacos_server.healthy_check()
#### 如果在flask环境启用远程配置,建议如下用法:
flask_env = {}
# 将本地配置注入到nacos对象中即可获取远程配置,并监听配置变化实时变更
nacos_server.config(env="test",app_config=flask_env)
for item in flask_env:
app.config[item] = flask_env[item]
"""
参数说明:
service_ip: 本机ip,用于让其他服务调用自己,如果是docker启动或者有内外网ip需要手动指定,否则自动获取本机ip
service_port: 指定本服务端口号
service_name: 本服务名称,用于注册到nacos以及让其他服务调用自己
env: 远程配置时用于区分环境,例如service-a-test.yaml,表示test环境,也可以不指定
app_config: 用于指定要接收的配置变量,字典类型,读取的远程配置会放到这里
"""
TODO
- 简化配置
- 基于flask插件快速集成
Project details
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
nacos-starter-1.0.10.tar.gz
(15.0 kB
view details)
Built Distribution
File details
Details for the file nacos-starter-1.0.10.tar.gz
.
File metadata
- Download URL: nacos-starter-1.0.10.tar.gz
- Upload date:
- Size: 15.0 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | e57f9bf589959e6d3362a6543205aa0efb76d8f203de91e14605667f609a2aa3 |
|
MD5 | de4a9cabd6f145f5b0ac79cf9351f716 |
|
BLAKE2b-256 | 18945c2f11a5e4be674a7b81ef0dc8a56ee032444afa995004e881f24ad5fcf8 |
File details
Details for the file nacos_starter-1.0.10-py3-none-any.whl
.
File metadata
- Download URL: nacos_starter-1.0.10-py3-none-any.whl
- Upload date:
- Size: 16.2 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 34de53a5c49521a4c9765afdcdce45d2069712409bbe94237a601e975f8bb61e |
|
MD5 | 14739f16e3769966531824eebc7decb2 |
|
BLAKE2b-256 | ff6d0b4bbb21205e3ffc310b33d65ec23679ffdef1a46981be1831e33d72a24f |