Files
kenaito-conf/kenaito-conf-python-client/README.md
T
odboy 03a95abb4b refactor: 客户端目录统一添加 kenaito-conf- 前缀
- go-client → kenaito-conf-go-client
- python-client → kenaito-conf-python-client
- python-client-demo → kenaito-conf-python-client-demo
- nodejs-client → kenaito-conf-nodejs-client
- nodejs-client-demo → kenaito-conf-nodejs-client-demo
- 更新所有 README 和 package.json 中的路径引用
2026-02-26 21:13:49 +08:00

77 lines
1.7 KiB
Markdown
Raw Blame History

This file contains ambiguous Unicode characters
This file contains Unicode characters that might be confused with other characters. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.
# Kenaito Config Center Python Client
## 安装
```bash
cd kenaito-conf-python-client
pip3 install -e .
```
## 快速开始
```python
from kenaito_conf import Config, ConfigClient
config = Config(
base_url="http://localhost:8080",
app_name="my-app",
env="daily",
sync_interval=30,
)
client = ConfigClient(config)
# 监听配置变更
def on_change(changed):
for k, v in changed.items():
print(f"config changed: {k} = {v}")
client.on_change(on_change)
# 启动客户端(拉取配置 + 开启定时同步)
client.start()
# 获取配置
value = client.get("database.host")
all_configs = client.get_all()
# 停止
client.stop()
```
## 配置项
| 参数 | 说明 | 默认值 |
|------|------|--------|
| `base_url` | 配置中心地址 | 必填 |
| `app_name` | 应用名称 | 必填 |
| `env` | 环境(dev/daily/prod) | `dev` |
| `version` | 配置版本 | `latest` |
| `token` | 认证令牌 | 空 |
| `sync_interval` | 同步间隔(秒) | `60` |
| `ignore_global` | 是否忽略全局配置 | `False` |
| `cache_dir` | 本地缓存目录 | `.` |
## Demo
```bash
cd kenaito-conf-python-client-demo
pip3 install -r requirements.txt
python3 app.py
```
Demo 默认监听 `8082` 端口,访问 `http://localhost:8082/` 查看配置。
环境变量覆盖:
| 环境变量 | 说明 | 默认值 |
|----------|------|--------|
| `SERVER_PORT` | 服务端口 | `8082` |
| `KENAITO_BASE_URL` | 配置中心地址 | `http://localhost:8080` |
| `KENAITO_APP_NAME` | 应用名称 | `kenaito-springboot-demo` |
| `KENAITO_PROFILE` | 环境 | `daily` |
| `KENAITO_VERSION` | 配置版本 | `latest` |
| `KENAITO_TOKEN` | 认证令牌 | 空 |
| `KENAITO_SYNC_INTERVAL` | 同步间隔(秒) | `30` |
| `KENAITO_CACHE_DIR` | 缓存目录 | `.` |