bscp-sdk-test


Namebscp-sdk-test JSON
Version 0.0.4 PyPI version JSON
download
home_pagehttps://github.com/TencentBlueKing/bscp-python-sdk
SummaryThe Python SDK for blueking bscp project.
upload_time2024-07-22 09:49:24
maintainerNone
docs_urlNone
authorblueking
requires_python>=3.8
licenseNone
keywords python bscp
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            ## BSCP-PYTHON-SDK
[![license](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)]()

[EnglishDocs](./readme_en.md)

## Overview

bscp-python-sdk 是蓝鲸 BSCP 项目的 Python SDK,它能帮助你轻松访问项目保存在 BSCP 上的配置内容。

## Features

- kv 配置拉取
- kv 配置 watch

## 使用示例

### 客户端对象 `BscpClient`

使用 `BscpClient` 来完成主要操作,其支持两种不同的调用风格。

普通风格:

```python
from bk_bscp.client import BscpClient

client = BscpClient(server_addrs, token, biz_id)
try:
    pair = client.get("app1", "key1")
finally:
    client.close()
```

- 普通风格要求你手动管理连接,适合复用长连接,在需要完成大量操作时使用

上下文管理器风格:

```python
from bk_bscp.client import BscpClient

with BscpClient(server_addrs, token, biz_id) as client:
    pair = client.get("app1", "key1")
```

- 在这种风格下,client 的连接会自动关闭,适合短连接,操作次数不多时的场景


### 示例文件

更多示例代码请参考 examples/ 目录。

### 开发指南

执行单元测试:

    poetry run pytest -s tests/

一些相关的环境变量配置项:

```
# 设置日志打印级别,默认为 INFO
BSCP_LOG_LEVEL=DEBUG
```

#### 启用集成测试

为了更好地测试 SDK 的功能,本项目编写了一些会连接真实 BSCP 服务器的集成测试用例。这些测试默认处于未启用状态,你可以配置以下环境变量来启用:

```bash
BSCP_SERVER_ADDRS="your-bscp.example.com:9090"
BSCP_TOKEN="your_token"
BSCP_BIZ_ID="1"

# 启用 Get 功能测试
BSCP_EXISTENT_APP_KEY="your_app,your_key"
```

#### 同步自动生成的 gRPC 源码文件

在项目的 `bk_bscp/grpc_lib` 目录里,存放着由 grpc 相关工具链自动生成的 Python 源码文件。需注意的是,这些源码所依赖的原始 proto 定义文件,并未保存在本 SDK 项目中,而是存放于 bscp 主项目里。当你需要更新这批文件时,请先将 bscp 项目克隆到本地,切换到项目根目录中,执行以下命令:

```bash
find ./pkg/protocol/core ./pkg/protocol/feed-server -name "*.proto" | \
    xargs python -m grpc_tools.protoc -I. -I ./pkg/thirdparty/protobuf/ --python_out=. --pyi_out=. --grpc_python_out=.
```

然后,回到本 SDK 项目的 scripts/ 子目录,执行以下脚本完成同步:

```bash
# 将 {bscp_project_path} 替换为真实的 bscp 项目目录
bash sync_grpc_generated.sh {bscp_project_path}
```

## Support

- [蓝鲸论坛](https://bk.tencent.com/s-mart/community)
- [蓝鲸 DevOps 在线视频教程](https://bk.tencent.com/s-mart/video/)
- 联系我们,技术交流QQ群:

<img src="https://github.com/Tencent/bk-PaaS/raw/master/docs/resource/img/bk_qq_group.png" width="250" hegiht="250" align=center />

## BlueKing Community

- [BK-CI](https://github.com/Tencent/bk-ci):蓝鲸持续集成平台是一个开源的持续集成和持续交付系统,可以轻松将你的研发流程呈现到你面前。
- [BK-BCS](https://github.com/Tencent/bk-bcs):蓝鲸容器管理平台是以容器技术为基础,为微服务业务提供编排管理的基础服务平台。
- [BK-PaaS](https://github.com/Tencent/bk-PaaS):蓝鲸PaaS平台是一个开放式的开发平台,让开发者可以方便快捷地创建、开发、部署和管理SaaS应用。
- [BK-SOPS](https://github.com/Tencent/bk-sops):标准运维(SOPS)是通过可视化的图形界面进行任务流程编排和执行的系统,是蓝鲸体系中一款轻量级的调度编排类SaaS产品。
- [BK-CMDB](https://github.com/Tencent/bk-cmdb):蓝鲸配置平台是一个面向资产及应用的企业级配置管理平台。

## Contributing

如果你有好的意见或建议,欢迎给我们提 Issues 或 Pull Requests,为蓝鲸开源社区贡献力量。

## License

bscp-python-sdk 是基于MIT协议, 详细请参考[LICENSE](./LICENSE.txt)。

            

Raw data

            {
    "_id": null,
    "home_page": "https://github.com/TencentBlueKing/bscp-python-sdk",
    "name": "bscp-sdk-test",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": "python, bscp",
    "author": "blueking",
    "author_email": "blueking@tencent.com",
    "download_url": "https://files.pythonhosted.org/packages/25/0a/aa5a57228a38d0ee274c46e9d270bcd37db8b7bdfee658231fc5af1a563a/bscp-sdk-test-0.0.4.tar.gz",
    "platform": null,
    "description": "## BSCP-PYTHON-SDK\n[![license](https://img.shields.io/badge/license-MIT-brightgreen.svg?style=flat)]()\n\n[EnglishDocs](./readme_en.md)\n\n## Overview\n\nbscp-python-sdk \u662f\u84dd\u9cb8 BSCP \u9879\u76ee\u7684 Python SDK\uff0c\u5b83\u80fd\u5e2e\u52a9\u4f60\u8f7b\u677e\u8bbf\u95ee\u9879\u76ee\u4fdd\u5b58\u5728 BSCP \u4e0a\u7684\u914d\u7f6e\u5185\u5bb9\u3002\n\n## Features\n\n- kv \u914d\u7f6e\u62c9\u53d6\n- kv \u914d\u7f6e watch\n\n## \u4f7f\u7528\u793a\u4f8b\n\n### \u5ba2\u6237\u7aef\u5bf9\u8c61 `BscpClient`\n\n\u4f7f\u7528 `BscpClient` \u6765\u5b8c\u6210\u4e3b\u8981\u64cd\u4f5c\uff0c\u5176\u652f\u6301\u4e24\u79cd\u4e0d\u540c\u7684\u8c03\u7528\u98ce\u683c\u3002\n\n\u666e\u901a\u98ce\u683c\uff1a\n\n```python\nfrom bk_bscp.client import BscpClient\n\nclient = BscpClient(server_addrs, token, biz_id)\ntry:\n    pair = client.get(\"app1\", \"key1\")\nfinally:\n    client.close()\n```\n\n- \u666e\u901a\u98ce\u683c\u8981\u6c42\u4f60\u624b\u52a8\u7ba1\u7406\u8fde\u63a5\uff0c\u9002\u5408\u590d\u7528\u957f\u8fde\u63a5\uff0c\u5728\u9700\u8981\u5b8c\u6210\u5927\u91cf\u64cd\u4f5c\u65f6\u4f7f\u7528\n\n\u4e0a\u4e0b\u6587\u7ba1\u7406\u5668\u98ce\u683c\uff1a\n\n```python\nfrom bk_bscp.client import BscpClient\n\nwith BscpClient(server_addrs, token, biz_id) as client:\n    pair = client.get(\"app1\", \"key1\")\n```\n\n- \u5728\u8fd9\u79cd\u98ce\u683c\u4e0b\uff0cclient \u7684\u8fde\u63a5\u4f1a\u81ea\u52a8\u5173\u95ed\uff0c\u9002\u5408\u77ed\u8fde\u63a5\uff0c\u64cd\u4f5c\u6b21\u6570\u4e0d\u591a\u65f6\u7684\u573a\u666f\n\n\n### \u793a\u4f8b\u6587\u4ef6\n\n\u66f4\u591a\u793a\u4f8b\u4ee3\u7801\u8bf7\u53c2\u8003 examples/ \u76ee\u5f55\u3002\n\n### \u5f00\u53d1\u6307\u5357\n\n\u6267\u884c\u5355\u5143\u6d4b\u8bd5\uff1a\n\n    poetry run pytest -s tests/\n\n\u4e00\u4e9b\u76f8\u5173\u7684\u73af\u5883\u53d8\u91cf\u914d\u7f6e\u9879\uff1a\n\n```\n# \u8bbe\u7f6e\u65e5\u5fd7\u6253\u5370\u7ea7\u522b\uff0c\u9ed8\u8ba4\u4e3a INFO\nBSCP_LOG_LEVEL=DEBUG\n```\n\n#### \u542f\u7528\u96c6\u6210\u6d4b\u8bd5\n\n\u4e3a\u4e86\u66f4\u597d\u5730\u6d4b\u8bd5 SDK \u7684\u529f\u80fd\uff0c\u672c\u9879\u76ee\u7f16\u5199\u4e86\u4e00\u4e9b\u4f1a\u8fde\u63a5\u771f\u5b9e BSCP \u670d\u52a1\u5668\u7684\u96c6\u6210\u6d4b\u8bd5\u7528\u4f8b\u3002\u8fd9\u4e9b\u6d4b\u8bd5\u9ed8\u8ba4\u5904\u4e8e\u672a\u542f\u7528\u72b6\u6001\uff0c\u4f60\u53ef\u4ee5\u914d\u7f6e\u4ee5\u4e0b\u73af\u5883\u53d8\u91cf\u6765\u542f\u7528\uff1a\n\n```bash\nBSCP_SERVER_ADDRS=\"your-bscp.example.com:9090\"\nBSCP_TOKEN=\"your_token\"\nBSCP_BIZ_ID=\"1\"\n\n# \u542f\u7528 Get \u529f\u80fd\u6d4b\u8bd5\nBSCP_EXISTENT_APP_KEY=\"your_app,your_key\"\n```\n\n#### \u540c\u6b65\u81ea\u52a8\u751f\u6210\u7684 gRPC \u6e90\u7801\u6587\u4ef6\n\n\u5728\u9879\u76ee\u7684 `bk_bscp/grpc_lib` \u76ee\u5f55\u91cc\uff0c\u5b58\u653e\u7740\u7531 grpc \u76f8\u5173\u5de5\u5177\u94fe\u81ea\u52a8\u751f\u6210\u7684 Python \u6e90\u7801\u6587\u4ef6\u3002\u9700\u6ce8\u610f\u7684\u662f\uff0c\u8fd9\u4e9b\u6e90\u7801\u6240\u4f9d\u8d56\u7684\u539f\u59cb proto \u5b9a\u4e49\u6587\u4ef6\uff0c\u5e76\u672a\u4fdd\u5b58\u5728\u672c SDK \u9879\u76ee\u4e2d\uff0c\u800c\u662f\u5b58\u653e\u4e8e bscp \u4e3b\u9879\u76ee\u91cc\u3002\u5f53\u4f60\u9700\u8981\u66f4\u65b0\u8fd9\u6279\u6587\u4ef6\u65f6\uff0c\u8bf7\u5148\u5c06 bscp \u9879\u76ee\u514b\u9686\u5230\u672c\u5730\uff0c\u5207\u6362\u5230\u9879\u76ee\u6839\u76ee\u5f55\u4e2d\uff0c\u6267\u884c\u4ee5\u4e0b\u547d\u4ee4\uff1a\n\n```bash\nfind ./pkg/protocol/core ./pkg/protocol/feed-server -name \"*.proto\" | \\\n    xargs python -m grpc_tools.protoc -I. -I ./pkg/thirdparty/protobuf/ --python_out=. --pyi_out=. --grpc_python_out=.\n```\n\n\u7136\u540e\uff0c\u56de\u5230\u672c SDK \u9879\u76ee\u7684 scripts/ \u5b50\u76ee\u5f55\uff0c\u6267\u884c\u4ee5\u4e0b\u811a\u672c\u5b8c\u6210\u540c\u6b65\uff1a\n\n```bash\n# \u5c06 {bscp_project_path} \u66ff\u6362\u4e3a\u771f\u5b9e\u7684 bscp \u9879\u76ee\u76ee\u5f55\nbash sync_grpc_generated.sh {bscp_project_path}\n```\n\n## Support\n\n- [\u84dd\u9cb8\u8bba\u575b](https://bk.tencent.com/s-mart/community)\n- [\u84dd\u9cb8 DevOps \u5728\u7ebf\u89c6\u9891\u6559\u7a0b](https://bk.tencent.com/s-mart/video/)\n- \u8054\u7cfb\u6211\u4eec\uff0c\u6280\u672f\u4ea4\u6d41QQ\u7fa4\uff1a\n\n<img src=\"https://github.com/Tencent/bk-PaaS/raw/master/docs/resource/img/bk_qq_group.png\" width=\"250\" hegiht=\"250\" align=center />\n\n## BlueKing Community\n\n- [BK-CI](https://github.com/Tencent/bk-ci)\uff1a\u84dd\u9cb8\u6301\u7eed\u96c6\u6210\u5e73\u53f0\u662f\u4e00\u4e2a\u5f00\u6e90\u7684\u6301\u7eed\u96c6\u6210\u548c\u6301\u7eed\u4ea4\u4ed8\u7cfb\u7edf\uff0c\u53ef\u4ee5\u8f7b\u677e\u5c06\u4f60\u7684\u7814\u53d1\u6d41\u7a0b\u5448\u73b0\u5230\u4f60\u9762\u524d\u3002\n- [BK-BCS](https://github.com/Tencent/bk-bcs)\uff1a\u84dd\u9cb8\u5bb9\u5668\u7ba1\u7406\u5e73\u53f0\u662f\u4ee5\u5bb9\u5668\u6280\u672f\u4e3a\u57fa\u7840\uff0c\u4e3a\u5fae\u670d\u52a1\u4e1a\u52a1\u63d0\u4f9b\u7f16\u6392\u7ba1\u7406\u7684\u57fa\u7840\u670d\u52a1\u5e73\u53f0\u3002\n- [BK-PaaS](https://github.com/Tencent/bk-PaaS)\uff1a\u84dd\u9cb8PaaS\u5e73\u53f0\u662f\u4e00\u4e2a\u5f00\u653e\u5f0f\u7684\u5f00\u53d1\u5e73\u53f0\uff0c\u8ba9\u5f00\u53d1\u8005\u53ef\u4ee5\u65b9\u4fbf\u5feb\u6377\u5730\u521b\u5efa\u3001\u5f00\u53d1\u3001\u90e8\u7f72\u548c\u7ba1\u7406SaaS\u5e94\u7528\u3002\n- [BK-SOPS](https://github.com/Tencent/bk-sops)\uff1a\u6807\u51c6\u8fd0\u7ef4\uff08SOPS\uff09\u662f\u901a\u8fc7\u53ef\u89c6\u5316\u7684\u56fe\u5f62\u754c\u9762\u8fdb\u884c\u4efb\u52a1\u6d41\u7a0b\u7f16\u6392\u548c\u6267\u884c\u7684\u7cfb\u7edf\uff0c\u662f\u84dd\u9cb8\u4f53\u7cfb\u4e2d\u4e00\u6b3e\u8f7b\u91cf\u7ea7\u7684\u8c03\u5ea6\u7f16\u6392\u7c7bSaaS\u4ea7\u54c1\u3002\n- [BK-CMDB](https://github.com/Tencent/bk-cmdb)\uff1a\u84dd\u9cb8\u914d\u7f6e\u5e73\u53f0\u662f\u4e00\u4e2a\u9762\u5411\u8d44\u4ea7\u53ca\u5e94\u7528\u7684\u4f01\u4e1a\u7ea7\u914d\u7f6e\u7ba1\u7406\u5e73\u53f0\u3002\n\n## Contributing\n\n\u5982\u679c\u4f60\u6709\u597d\u7684\u610f\u89c1\u6216\u5efa\u8bae\uff0c\u6b22\u8fce\u7ed9\u6211\u4eec\u63d0 Issues \u6216 Pull Requests\uff0c\u4e3a\u84dd\u9cb8\u5f00\u6e90\u793e\u533a\u8d21\u732e\u529b\u91cf\u3002\n\n## License\n\nbscp-python-sdk \u662f\u57fa\u4e8eMIT\u534f\u8bae\uff0c \u8be6\u7ec6\u8bf7\u53c2\u8003[LICENSE](./LICENSE.txt)\u3002\n",
    "bugtrack_url": null,
    "license": null,
    "summary": "The Python SDK for blueking bscp project.",
    "version": "0.0.4",
    "project_urls": {
        "Homepage": "https://github.com/TencentBlueKing/bscp-python-sdk"
    },
    "split_keywords": [
        "python",
        " bscp"
    ],
    "urls": [
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "6ec82394fa96ad6b7bef1964ca8f7efe4686fc1c6129d9ba9aa8823204d58176",
                "md5": "f6f30928455c740607b615ab182e3d8e",
                "sha256": "02c34af1f15ac47065518eb42b0dbc4473d0a7b8d731e304eaeea7ff15670a5a"
            },
            "downloads": -1,
            "filename": "bscp_sdk_test-0.0.4-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "f6f30928455c740607b615ab182e3d8e",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 19179,
            "upload_time": "2024-07-22T09:49:22",
            "upload_time_iso_8601": "2024-07-22T09:49:22.164273Z",
            "url": "https://files.pythonhosted.org/packages/6e/c8/2394fa96ad6b7bef1964ca8f7efe4686fc1c6129d9ba9aa8823204d58176/bscp_sdk_test-0.0.4-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": "",
            "digests": {
                "blake2b_256": "250aaa5a57228a38d0ee274c46e9d270bcd37db8b7bdfee658231fc5af1a563a",
                "md5": "00f740aa1e781d1a1146cc175f4ae95a",
                "sha256": "58cb0e6ea2953981e7a14554e61bd4e769d34842df178088a43025abd535e0d7"
            },
            "downloads": -1,
            "filename": "bscp-sdk-test-0.0.4.tar.gz",
            "has_sig": false,
            "md5_digest": "00f740aa1e781d1a1146cc175f4ae95a",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 16629,
            "upload_time": "2024-07-22T09:49:24",
            "upload_time_iso_8601": "2024-07-22T09:49:24.502848Z",
            "url": "https://files.pythonhosted.org/packages/25/0a/aa5a57228a38d0ee274c46e9d270bcd37db8b7bdfee658231fc5af1a563a/bscp-sdk-test-0.0.4.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2024-07-22 09:49:24",
    "github": true,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "github_user": "TencentBlueKing",
    "github_project": "bscp-python-sdk",
    "travis_ci": false,
    "coveralls": false,
    "github_actions": true,
    "lcname": "bscp-sdk-test"
}
        
Elapsed time: 0.28771s