Skip to main content

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

Project description

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文件

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

python_cnb-1.23.19.tar.gz (38.3 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

python_cnb-1.23.19-py3-none-any.whl (57.1 kB view details)

Uploaded Python 3

File details

Details for the file python_cnb-1.23.19.tar.gz.

File metadata

  • Download URL: python_cnb-1.23.19.tar.gz
  • Upload date:
  • Size: 38.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for python_cnb-1.23.19.tar.gz
Algorithm Hash digest
SHA256 8cd261187a68cf90b2eaa94bb7e11c36b3e2dc3bdc00c7fc47f80455ed6e8c77
MD5 b03acacd49c5e5f980b30ea8318dfd7e
BLAKE2b-256 da0db726ba4c5f8554e115444cbf41ca77d9600286a5d78533c557d06db43dc3

See more details on using hashes here.

File details

Details for the file python_cnb-1.23.19-py3-none-any.whl.

File metadata

  • Download URL: python_cnb-1.23.19-py3-none-any.whl
  • Upload date:
  • Size: 57.1 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for python_cnb-1.23.19-py3-none-any.whl
Algorithm Hash digest
SHA256 483e526c4f4ca3747f88f94973e78c4aea06e9be3b99c9d34c5c36c385433447
MD5 a92b869402408bf62401fe59c04143f3
BLAKE2b-256 8ea938640b6bf35d2cd805c9a0c09b105a30fb212ec1673a5091f691fceea813

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page