| Name | py3-apollo-client JSON |
| Version |
1.0.4
JSON |
| download |
| home_page | None |
| Summary | Python3 Client for Ctrip's Apollo |
| upload_time | 2025-09-08 06:31:15 |
| maintainer | None |
| docs_url | None |
| author | None |
| requires_python | >=3.6.0 |
| license | None |
| keywords |
apollo
|
| VCS |
 |
| bugtrack_url |
|
| requirements |
No requirements were recorded.
|
| Travis-CI |
No Travis.
|
| coveralls test coverage |
No coveralls.
|
py3-apollo-client - Python3 Client for Ctrip's Apollo
================
[](https://opensource.org/licenses/Apache-2.0)
方便Python接入配置中心框架 [Apollo](https://github.com/ctripcorp/apollo) 所开发的Python版本客户端。
基于 [onecer/apollo-python](https://github.com/onecer/apollo-python) 修改, 主要修复配置未更新也会触发`change_listener`
## 链接
-----
- [GitHub](https://github.com/renw87/py3-apollo-client)
- [PyPI](https://pypi.org/project/py3-apollo-client)
## 依赖
-----
- python 3.x
## 安装
-----
```bash
pip install py3-apollo-client
```
## 使用
-----
导入包
```
from py3_apollo import ApolloClient
```
```
app_id = 'demo-service'
config_url = 'http://127.0.0.1:8080'
cluster = 'default'
secret = ''
env = 'DEV'
client = ApolloClient(app_id=app_id, config_url=config_url, cluster=cluster, secret=secret, env=env)
lm_API_KEY = client.get_value("lm_API_KEY")
```
也默认支持通过环境变量来传递值,基本和 Java 客户端保持一致
## 客户端初始化参数
| 参数 | 说明 | 默认值 | 环境变量 |
|:-----------------|:--------------|:----------------------|:---------------------------|
| app_id | 应用名 | 无 | APP_ID |
| config_url | 配置中心地址 | http://127.0.0.1:8080 | ${ENV}_META or APOLLO_META |
| cluster | 集群名 | default | IDC |
| secret | 访问密钥 | 无 | APOLLO_ACCESS_KEY_SECRET |
| env | 环境 | DEV | ENV |
| client_ip | 客户端ip | 获取当前 IP | CLIENT_IP |
| cache_path | 配置缓存路径 | tmp/apollo/cache | APOLLO_CACHE_PATH |
| need_hot_update | 是否需要热更新 | True | - |
| change_listener | 配置变更监听器(回调函数) | None | - |
| log_level | 日志级别 | INFO | LOG_LEVEL |
| notification_map | 通知配置 (dict) | None | - |
### 配置变更监听器 change_listener
```python
"""
接受 4 个参数
action:delete \ add \ update
namespace:namespace
key:key
old_value:old_value
"""
def change_listener(action, namespace, key, old_value):
print(f"action:{action} namespace: {namespace} key: {key} old_value: {old_value}")
```
### 通知配置 notification_map
```python
notification_map = {
"application": ["application"],
"application.yml": ["application.yml"]
}
```
## 配置优先级
*** 环境变量 > 代码配置 ***
如果环境变量存在,则优先使用环境变量的值。
如果环境中存在 ENV的环境变量, 如 ENV=DEV。则优先组合出 `DEV_META` 这个环境变量名称来获取 config url。 如果该环境变量不存在,则取 `APOLLO_META` 环境变量的值。如果 `APOLLO_META` 也不存在,则使用代码定义的 config_url 的值。
其它环境变量同理,以此类推。
### 热更新
默认会启动一个线程来定时更新本地缓存的配置,所以,如果每次用的是 get_value 来获取配置,可以实现配置热更新。
## 本地打包 wheel
```
# install uv
pip install uv
# build
uv build
# upload
uv publish --token <TOKEN>
```
## License
-------
This is free and unencumbered software released into the public domain.
Anyone is free to copy, modify, publish, use, compile, sell, or
distribute this software, either in source code form or as a compiled
binary, for any purpose, commercial or non-commercial, and by any means.
[My Blog]: [https://uublog.com](https://uublog.com)
Raw data
{
"_id": null,
"home_page": null,
"name": "py3-apollo-client",
"maintainer": null,
"docs_url": null,
"requires_python": ">=3.6.0",
"maintainer_email": null,
"keywords": "apollo",
"author": null,
"author_email": "renw <renwei_8080@126.com>",
"download_url": "https://files.pythonhosted.org/packages/35/37/9019b8a95ed4e68aa6c1fcd88b680bd911e2a8b4309319a1e6c12661581e/py3_apollo_client-1.0.4.tar.gz",
"platform": null,
"description": "py3-apollo-client - Python3 Client for Ctrip's Apollo\r\n================\r\n[](https://opensource.org/licenses/Apache-2.0)\r\n\r\n\u65b9\u4fbfPython\u63a5\u5165\u914d\u7f6e\u4e2d\u5fc3\u6846\u67b6 [Apollo](https://github.com/ctripcorp/apollo) \u6240\u5f00\u53d1\u7684Python\u7248\u672c\u5ba2\u6237\u7aef\u3002\r\n\r\n\u57fa\u4e8e [onecer/apollo-python](https://github.com/onecer/apollo-python) \u4fee\u6539\uff0c \u4e3b\u8981\u4fee\u590d\u914d\u7f6e\u672a\u66f4\u65b0\u4e5f\u4f1a\u89e6\u53d1`change_listener`\r\n\r\n## \u94fe\u63a5\r\n-----\r\n\r\n- [GitHub](https://github.com/renw87/py3-apollo-client)\r\n- [PyPI](https://pypi.org/project/py3-apollo-client)\r\n\r\n## \u4f9d\u8d56\r\n-----\r\n\r\n- python 3.x\r\n\r\n## \u5b89\u88c5\r\n-----\r\n\r\n```bash\r\npip install py3-apollo-client\r\n```\r\n\r\n## \u4f7f\u7528\r\n-----\r\n\r\n\u5bfc\u5165\u5305\r\n```\r\nfrom py3_apollo import ApolloClient\r\n```\r\n\r\n```\r\napp_id = 'demo-service'\r\nconfig_url = 'http://127.0.0.1:8080'\r\ncluster = 'default'\r\nsecret = ''\r\nenv = 'DEV'\r\n\r\nclient = ApolloClient(app_id=app_id, config_url=config_url, cluster=cluster, secret=secret, env=env)\r\nlm_API_KEY = client.get_value(\"lm_API_KEY\")\r\n```\r\n\r\n\u4e5f\u9ed8\u8ba4\u652f\u6301\u901a\u8fc7\u73af\u5883\u53d8\u91cf\u6765\u4f20\u9012\u503c,\u57fa\u672c\u548c Java \u5ba2\u6237\u7aef\u4fdd\u6301\u4e00\u81f4\r\n\r\n## \u5ba2\u6237\u7aef\u521d\u59cb\u5316\u53c2\u6570\r\n\r\n| \u53c2\u6570 | \u8bf4\u660e | \u9ed8\u8ba4\u503c | \u73af\u5883\u53d8\u91cf |\r\n|:-----------------|:--------------|:----------------------|:---------------------------|\r\n| app_id | \u5e94\u7528\u540d | \u65e0 | APP_ID |\r\n| config_url | \u914d\u7f6e\u4e2d\u5fc3\u5730\u5740 | http://127.0.0.1:8080 | ${ENV}_META or APOLLO_META |\r\n| cluster | \u96c6\u7fa4\u540d | default | IDC |\r\n| secret | \u8bbf\u95ee\u5bc6\u94a5 | \u65e0 | APOLLO_ACCESS_KEY_SECRET |\r\n| env | \u73af\u5883 | DEV | ENV |\r\n| client_ip | \u5ba2\u6237\u7aefip | \u83b7\u53d6\u5f53\u524d IP | CLIENT_IP |\r\n| cache_path | \u914d\u7f6e\u7f13\u5b58\u8def\u5f84 | tmp/apollo/cache | APOLLO_CACHE_PATH |\r\n| need_hot_update | \u662f\u5426\u9700\u8981\u70ed\u66f4\u65b0 | True | - |\r\n| change_listener | \u914d\u7f6e\u53d8\u66f4\u76d1\u542c\u5668(\u56de\u8c03\u51fd\u6570) | None | - |\r\n| log_level | \u65e5\u5fd7\u7ea7\u522b | INFO | LOG_LEVEL |\r\n| notification_map | \u901a\u77e5\u914d\u7f6e (dict) | None | - |\r\n\r\n### \u914d\u7f6e\u53d8\u66f4\u76d1\u542c\u5668 change_listener\r\n\r\n```python\r\n\"\"\"\r\n\u63a5\u53d7 4 \u4e2a\u53c2\u6570 \r\naction\uff1adelete \\ add \\ update\r\nnamespace\uff1anamespace\r\nkey\uff1akey\r\nold_value\uff1aold_value\r\n\"\"\"\r\ndef change_listener(action, namespace, key, old_value):\r\n print(f\"action:{action} namespace: {namespace} key: {key} old_value: {old_value}\")\r\n```\r\n\r\n### \u901a\u77e5\u914d\u7f6e notification_map\r\n\r\n```python\r\nnotification_map = {\r\n \"application\": [\"application\"],\r\n \"application.yml\": [\"application.yml\"]\r\n}\r\n```\r\n\r\n## \u914d\u7f6e\u4f18\u5148\u7ea7\r\n\r\n*** \u73af\u5883\u53d8\u91cf > \u4ee3\u7801\u914d\u7f6e ***\r\n\r\n\u5982\u679c\u73af\u5883\u53d8\u91cf\u5b58\u5728\uff0c\u5219\u4f18\u5148\u4f7f\u7528\u73af\u5883\u53d8\u91cf\u7684\u503c\u3002\r\n\r\n\u5982\u679c\u73af\u5883\u4e2d\u5b58\u5728 ENV\u7684\u73af\u5883\u53d8\u91cf, \u5982 ENV=DEV\u3002\u5219\u4f18\u5148\u7ec4\u5408\u51fa `DEV_META` \u8fd9\u4e2a\u73af\u5883\u53d8\u91cf\u540d\u79f0\u6765\u83b7\u53d6 config url\u3002 \u5982\u679c\u8be5\u73af\u5883\u53d8\u91cf\u4e0d\u5b58\u5728\uff0c\u5219\u53d6 `APOLLO_META` \u73af\u5883\u53d8\u91cf\u7684\u503c\u3002\u5982\u679c `APOLLO_META` \u4e5f\u4e0d\u5b58\u5728\uff0c\u5219\u4f7f\u7528\u4ee3\u7801\u5b9a\u4e49\u7684 config_url \u7684\u503c\u3002\r\n\r\n\u5176\u5b83\u73af\u5883\u53d8\u91cf\u540c\u7406\uff0c\u4ee5\u6b64\u7c7b\u63a8\u3002\r\n\r\n### \u70ed\u66f4\u65b0\r\n\r\n\u9ed8\u8ba4\u4f1a\u542f\u52a8\u4e00\u4e2a\u7ebf\u7a0b\u6765\u5b9a\u65f6\u66f4\u65b0\u672c\u5730\u7f13\u5b58\u7684\u914d\u7f6e\uff0c\u6240\u4ee5\uff0c\u5982\u679c\u6bcf\u6b21\u7528\u7684\u662f get_value \u6765\u83b7\u53d6\u914d\u7f6e\uff0c\u53ef\u4ee5\u5b9e\u73b0\u914d\u7f6e\u70ed\u66f4\u65b0\u3002\r\n\r\n\r\n## \u672c\u5730\u6253\u5305 wheel \r\n\r\n```\r\n# install uv\r\npip install uv\r\n\r\n# build\r\nuv build\r\n\r\n# upload\r\nuv publish --token <TOKEN>\r\n\r\n```\r\n\r\n## License\r\n-------\r\n\r\nThis is free and unencumbered software released into the public domain.\r\n\r\nAnyone is free to copy, modify, publish, use, compile, sell, or\r\ndistribute this software, either in source code form or as a compiled\r\nbinary, for any purpose, commercial or non-commercial, and by any means.\r\n\r\n [My Blog]: [https://uublog.com](https://uublog.com)\r\n",
"bugtrack_url": null,
"license": null,
"summary": "Python3 Client for Ctrip's Apollo",
"version": "1.0.4",
"project_urls": {
"homepage": "https://github.com/renw87/py3-apollo-client",
"repository": "https://github.com/renw87/py3-apollo-client"
},
"split_keywords": [
"apollo"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "4e13e1fe6f3f18278ed8cbfa2ad60a3b1561e73fec99a4baf0a788942179f6e5",
"md5": "f03aedfe83384febf38b75f8e69f6173",
"sha256": "48050c7847bea2596a8090eba6a41741838b1730e300ee0c35024b13bf72bff2"
},
"downloads": -1,
"filename": "py3_apollo_client-1.0.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "f03aedfe83384febf38b75f8e69f6173",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": ">=3.6.0",
"size": 8358,
"upload_time": "2025-09-08T06:31:14",
"upload_time_iso_8601": "2025-09-08T06:31:14.234128Z",
"url": "https://files.pythonhosted.org/packages/4e/13/e1fe6f3f18278ed8cbfa2ad60a3b1561e73fec99a4baf0a788942179f6e5/py3_apollo_client-1.0.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "35379019b8a95ed4e68aa6c1fcd88b680bd911e2a8b4309319a1e6c12661581e",
"md5": "bc87419c56594cd0dcdd51c05b2e712e",
"sha256": "efc9e04b175535aeb62e43d5b118cfef6c101154e1ea5749fac349573a587ae9"
},
"downloads": -1,
"filename": "py3_apollo_client-1.0.4.tar.gz",
"has_sig": false,
"md5_digest": "bc87419c56594cd0dcdd51c05b2e712e",
"packagetype": "sdist",
"python_version": "source",
"requires_python": ">=3.6.0",
"size": 8288,
"upload_time": "2025-09-08T06:31:15",
"upload_time_iso_8601": "2025-09-08T06:31:15.408733Z",
"url": "https://files.pythonhosted.org/packages/35/37/9019b8a95ed4e68aa6c1fcd88b680bd911e2a8b4309319a1e6c12661581e/py3_apollo_client-1.0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-09-08 06:31:15",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "renw87",
"github_project": "py3-apollo-client",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "py3-apollo-client"
}