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.25.8

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.25.8
File Size Uploaded Provenance Actions
python_cnb-1.25.8.tar.gz 39.7 kB Without provenance Details for python_cnb-1.25.8.tar.gz

Built distribution (wheel)

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

Total release size: 98.6 kB

Release files / python_cnb-1.25.8.tar.gz

Download URL python_cnb-1.25.8.tar.gz
Size 39.7 kB
Tags Source
SHA-256 checksum
How to use checksums
91390c943074673a6bc9653bc89abd1d14db9e958b8772b0eaf8674e9c1ec17b
BLAKE2b-256 checksum
How to use checksums
e8f627ec2d85a676f9643ee3dceeb2a898372836e27c9abfc153f38451dd326b
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.25.8-py3-none-any.whl

Download URL python_cnb-1.25.8-py3-none-any.whl
Size 58.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
a6b120b1723733356fb250bafe6577ef716b87a92fd2eed7fbad538aa1d1b872
BLAKE2b-256 checksum
How to use checksums
a8472ed1c053302689cf3cb77b6197270bf93cec56b32f4a4c0357c23b96caba
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.25.8

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