python-cnb


Namepython-cnb JSON
Version 0.6.0 PyPI version JSON
download
home_pagehttps://cnb.cool
SummaryCNB OpenAPI的Python SDK,方便与CNB平台进行交互
upload_time2025-07-09 08:25:48
maintainerNone
docs_urlNone
authorTencent Cloud
requires_python>=3.8
licenseMIT
keywords
VCS
bugtrack_url
requirements No requirements were recorded.
Travis-CI No Travis.
coveralls test coverage No coveralls.
            # Python CNB OpenAPI SDK

[![PyPI](https://img.shields.io/pypi/v/python-cnb.svg)](https://pypi.org/project/python-cnb/)
[![Python Version](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)
[![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)
<a href="https://yuanbao.tencent.com"><img src="https://img.shields.io/badge/AI-Code%20Assist-EB9FDA"></a>

CNB OpenAPI的Python SDK,方便与CNB平台进行交互。
> 该 sdk 由 [cnb-sdk-generator](https://cnb.cool/cnb/sdk/cnb-sdk-generator) 生成

## 功能特性

- 完整的API覆盖(用户、仓库、Issue等)
- 基于Pydantic的强类型模型
- 完善的错误处理机制
- 自动重试和超时控制

## 安装

```bash
pip install -e .
```

或通过PyPI安装(已发布):

```bash
pip install python-cnb
```

## 快速开始

```python
#!/usr/bin/env python

import os
from dotenv import load_dotenv
from cnb import CNBClient
from cnb.exceptions import CNBAPIError
from cnb.models import api

# 加载环境变量
load_dotenv()

def get_user_info():
    # 初始化客户端
    client = CNBClient(
        base_url="https://api.cnb.cool",
        api_key=os.getenv("CNB_TOKEN"),  # 从环境变量获取API Key
        max_retries=3,  # 最大重试次数
        timeout=30,     # 请求超时时间(秒)
    )

    try:
        user_info = client.cnb.users.get_user_info()
        print(f"user_info: {user_info}")

    except CNBAPIError as e:
        print(f"API调用失败: {e}")

def create_issue():
    # 初始化客户端
    client = CNBClient(
        base_url="https://api.cnb.cool",
        api_key=os.getenv("CNB_TOKEN"),  # 从环境变量获取API Key
        max_retries=3,  # 最大重试次数
        timeout=30,     # 请求超时时间(秒)
    )

    try:
        issue = client.cnb.issues.create_issue(
            repo="looc/test-ci", 
            body_params=api.PostIssueForm(
                title="测试 Issue",
                priority="111"
            )
        )
        print(f"issue: {issue}")

    except CNBAPIError as e:
        print(f"API调用失败: {e.errcode}")       

if __name__ == "__main__":
    get_user_info()
    list_issues()

```

## 许可证

MIT License - 详见[LICENSE](LICENSE)文件

            

Raw data

            {
    "_id": null,
    "home_page": "https://cnb.cool",
    "name": "python-cnb",
    "maintainer": null,
    "docs_url": null,
    "requires_python": ">=3.8",
    "maintainer_email": null,
    "keywords": null,
    "author": "Tencent Cloud",
    "author_email": "ericdduan@tencent.com",
    "download_url": "https://files.pythonhosted.org/packages/6e/f2/47a06859472ee32ca4fca749d4bb5067fa36f627fd31910ad4eda33b442c/python_cnb-0.6.0.tar.gz",
    "platform": null,
    "description": "# Python CNB OpenAPI SDK\n\n[![PyPI](https://img.shields.io/pypi/v/python-cnb.svg)](https://pypi.org/project/python-cnb/)\n[![Python Version](https://img.shields.io/badge/python-3.8+-blue.svg)](https://www.python.org/downloads/)\n[![License](https://img.shields.io/badge/license-MIT-green.svg)](LICENSE)\n<a href=\"https://yuanbao.tencent.com\"><img src=\"https://img.shields.io/badge/AI-Code%20Assist-EB9FDA\"></a>\n\nCNB OpenAPI\u7684Python SDK\uff0c\u65b9\u4fbf\u4e0eCNB\u5e73\u53f0\u8fdb\u884c\u4ea4\u4e92\u3002\n> \u8be5 sdk \u7531 [cnb-sdk-generator](https://cnb.cool/cnb/sdk/cnb-sdk-generator) \u751f\u6210\n\n## \u529f\u80fd\u7279\u6027\n\n- \u5b8c\u6574\u7684API\u8986\u76d6\uff08\u7528\u6237\u3001\u4ed3\u5e93\u3001Issue\u7b49\uff09\n- \u57fa\u4e8ePydantic\u7684\u5f3a\u7c7b\u578b\u6a21\u578b\n- \u5b8c\u5584\u7684\u9519\u8bef\u5904\u7406\u673a\u5236\n- \u81ea\u52a8\u91cd\u8bd5\u548c\u8d85\u65f6\u63a7\u5236\n\n## \u5b89\u88c5\n\n```bash\npip install -e .\n```\n\n\u6216\u901a\u8fc7PyPI\u5b89\u88c5\uff08\u5df2\u53d1\u5e03\uff09\uff1a\n\n```bash\npip install python-cnb\n```\n\n## \u5feb\u901f\u5f00\u59cb\n\n```python\n#!/usr/bin/env python\n\nimport os\nfrom dotenv import load_dotenv\nfrom cnb import CNBClient\nfrom cnb.exceptions import CNBAPIError\nfrom cnb.models import api\n\n# \u52a0\u8f7d\u73af\u5883\u53d8\u91cf\nload_dotenv()\n\ndef get_user_info():\n    # \u521d\u59cb\u5316\u5ba2\u6237\u7aef\n    client = CNBClient(\n        base_url=\"https://api.cnb.cool\",\n        api_key=os.getenv(\"CNB_TOKEN\"),  # \u4ece\u73af\u5883\u53d8\u91cf\u83b7\u53d6API Key\n        max_retries=3,  # \u6700\u5927\u91cd\u8bd5\u6b21\u6570\n        timeout=30,     # \u8bf7\u6c42\u8d85\u65f6\u65f6\u95f4(\u79d2)\n    )\n\n    try:\n        user_info = client.cnb.users.get_user_info()\n        print(f\"user_info: {user_info}\")\n\n    except CNBAPIError as e:\n        print(f\"API\u8c03\u7528\u5931\u8d25: {e}\")\n\ndef create_issue():\n    # \u521d\u59cb\u5316\u5ba2\u6237\u7aef\n    client = CNBClient(\n        base_url=\"https://api.cnb.cool\",\n        api_key=os.getenv(\"CNB_TOKEN\"),  # \u4ece\u73af\u5883\u53d8\u91cf\u83b7\u53d6API Key\n        max_retries=3,  # \u6700\u5927\u91cd\u8bd5\u6b21\u6570\n        timeout=30,     # \u8bf7\u6c42\u8d85\u65f6\u65f6\u95f4(\u79d2)\n    )\n\n    try:\n        issue = client.cnb.issues.create_issue(\n            repo=\"looc/test-ci\", \n            body_params=api.PostIssueForm(\n                title=\"\u6d4b\u8bd5 Issue\",\n                priority=\"111\"\n            )\n        )\n        print(f\"issue: {issue}\")\n\n    except CNBAPIError as e:\n        print(f\"API\u8c03\u7528\u5931\u8d25: {e.errcode}\")       \n\nif __name__ == \"__main__\":\n    get_user_info()\n    list_issues()\n\n```\n\n## \u8bb8\u53ef\u8bc1\n\nMIT License - \u8be6\u89c1[LICENSE](LICENSE)\u6587\u4ef6\n",
    "bugtrack_url": null,
    "license": "MIT",
    "summary": "CNB OpenAPI\u7684Python SDK,\u65b9\u4fbf\u4e0eCNB\u5e73\u53f0\u8fdb\u884c\u4ea4\u4e92",
    "version": "0.6.0",
    "project_urls": {
        "Documentation": "https://docs.cnb.cool",
        "Homepage": "https://cnb.cool",
        "Source": "https://cnb.cool/cnb/sdk/python-cnb"
    },
    "split_keywords": [],
    "urls": [
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "9852aa3a3ac74235a5c0de85122027d1c82e45bd4f2219e6c77920b36c15de8f",
                "md5": "32378f2e0acd2cd35a501c4d94013f7f",
                "sha256": "4fe3bb21f0bfd9ba81527df2687dfcf9ef020e76fb85315dec906e25032f33d8"
            },
            "downloads": -1,
            "filename": "python_cnb-0.6.0-py3-none-any.whl",
            "has_sig": false,
            "md5_digest": "32378f2e0acd2cd35a501c4d94013f7f",
            "packagetype": "bdist_wheel",
            "python_version": "py3",
            "requires_python": ">=3.8",
            "size": 62673,
            "upload_time": "2025-07-09T08:25:47",
            "upload_time_iso_8601": "2025-07-09T08:25:47.447209Z",
            "url": "https://files.pythonhosted.org/packages/98/52/aa3a3ac74235a5c0de85122027d1c82e45bd4f2219e6c77920b36c15de8f/python_cnb-0.6.0-py3-none-any.whl",
            "yanked": false,
            "yanked_reason": null
        },
        {
            "comment_text": null,
            "digests": {
                "blake2b_256": "6ef247a06859472ee32ca4fca749d4bb5067fa36f627fd31910ad4eda33b442c",
                "md5": "729ebe4854d513c91d3b5808318700a3",
                "sha256": "a236e91b1899b9f92ea61552ec2d382dfd0c53e0159704f41fe3b51026d4b6c1"
            },
            "downloads": -1,
            "filename": "python_cnb-0.6.0.tar.gz",
            "has_sig": false,
            "md5_digest": "729ebe4854d513c91d3b5808318700a3",
            "packagetype": "sdist",
            "python_version": "source",
            "requires_python": ">=3.8",
            "size": 42480,
            "upload_time": "2025-07-09T08:25:48",
            "upload_time_iso_8601": "2025-07-09T08:25:48.761893Z",
            "url": "https://files.pythonhosted.org/packages/6e/f2/47a06859472ee32ca4fca749d4bb5067fa36f627fd31910ad4eda33b442c/python_cnb-0.6.0.tar.gz",
            "yanked": false,
            "yanked_reason": null
        }
    ],
    "upload_time": "2025-07-09 08:25:48",
    "github": false,
    "gitlab": false,
    "bitbucket": false,
    "codeberg": false,
    "lcname": "python-cnb"
}
        
Elapsed time: 1.25389s