Skip to main content

Python CNB OpenAPI SDK

PyPI Python Version License

CNB OpenAPI的Python SDK,方便与CNB平台进行交互。

该 sdk 由 cnb-sdk-generator 生成

功能特性

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

安装

pip install -e .

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

pip install python-cnb

快速开始

#!/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文件

Metadata

Release files for python-cnb 1.29.15

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for python-cnb 1.29.15
File Size Uploaded Provenance Actions
python_cnb-1.29.15.tar.gz 42.8 kB Without provenance Details for python_cnb-1.29.15.tar.gz

Built distribution (wheel)

Table of built distributions (wheels) for python-cnb 1.29.15
File Interpreter ABI Platform Actions
python_cnb-1.29.15-py3-none-any.whl Python 3 none any Details for python_cnb-1.29.15-py3-none-any.whl

Total release size: 106.2 kB

Release files / python_cnb-1.29.15.tar.gz

Download URL python_cnb-1.29.15.tar.gz
Size 42.8 kB
Tags Source
SHA-256 checksum
How to use checksums
3ce5292c2845754616101f9a16465c7d99da6674d82f4d4f2f8285f0ff75c240
BLAKE2b-256 checksum
How to use checksums
94255da22030f7d24f49b7e10ee4dd55310634738331e0b8379f6b2de02ce9ef
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.7

Release files / python_cnb-1.29.15-py3-none-any.whl

Download URL python_cnb-1.29.15-py3-none-any.whl
Size 63.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
346008854d3687a2d2885360b2666f4473095e53adf4bfb575c9e8179016a67d
BLAKE2b-256 checksum
How to use checksums
a7f52f5e2e941a1fd21b22c2e9c081fbcb56f5e4ef528cd5c6b0ae8e16fb1e79
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/7.0.0 CPython/3.12.7

Security for python-cnb 1.29.15

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page