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.28.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.28.8
File Size Uploaded Provenance Actions
python_cnb-1.28.8.tar.gz 42.6 kB Without provenance Details for python_cnb-1.28.8.tar.gz

Built distribution (wheel)

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

Total release size: 105.9 kB

Release files / python_cnb-1.28.8.tar.gz

Download URL python_cnb-1.28.8.tar.gz
Size 42.6 kB
Tags Source
SHA-256 checksum
How to use checksums
d8ff8078f53cf70081b964435adc231abc9208c41e939c54594d6c2ca3f439d8
BLAKE2b-256 checksum
How to use checksums
4ded8ba43ca4bb49f352f2d60cecd393b68dd0c68f352e0d71b3f9ffdd3989e7
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.28.8-py3-none-any.whl

Download URL python_cnb-1.28.8-py3-none-any.whl
Size 63.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
13fedc952b042f593c99d830b1fceae2e5adc2dd64ea9d6aaec7cb725333dc4d
BLAKE2b-256 checksum
How to use checksums
1016ce6c37f8ca3657a72c43388b07b54a06ea24d9053f29035e302f9427002f
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.28.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