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.9.tar.gz
(14.9 kB
view details)
Built Distribution
File details
Details for the file nacos-starter-1.0.9.tar.gz
.
File metadata
- Download URL: nacos-starter-1.0.9.tar.gz
- Upload date:
- Size: 14.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/4.0.0 CPython/3.8.8
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 5ad76df65d45224050506648cd1b6ec3c575932f8ed79162380ec9fc1c057910 |
|
MD5 | 754c667c3bddc2ebad88d73e2d82a3b1 |
|
BLAKE2b-256 | 3240d44e6e1a05e655f42e43fa7357d997b6f432f81e580fa18b4a7484aa582a |
File details
Details for the file nacos_starter-1.0.9-py3-none-any.whl
.
File metadata
- Download URL: nacos_starter-1.0.9-py3-none-any.whl
- Upload date:
- Size: 16.1 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 | cd52b9c71aca6d475c0a6b71a94bb842b97ccdffc74dde85b2ca129a2fd1faa6 |
|
MD5 | b94f02721487d774e23a9585111cb30f |
|
BLAKE2b-256 | f76c915f841f12c5d51313fdd571649043ea00812bb73bc472c8ed5440358865 |