CNB OpenAPI的Python SDK,方便与CNB平台进行交互
Project description
Python CNB OpenAPI SDK
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
Release history Release notifications | RSS feed
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-0.8.0b1.tar.gz
(33.7 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file python_cnb-0.8.0b1.tar.gz.
File metadata
- Download URL: python_cnb-0.8.0b1.tar.gz
- Upload date:
- Size: 33.7 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
142f40a0be1be3919d264527a0e39b88fbf6d39c86cbe4be08188621c77521e5
|
|
| MD5 |
9ce9f72dd5a7d07b997be8bbac56b819
|
|
| BLAKE2b-256 |
3d7a22d5d87ceb2c68a1cf9f331506ae42e25f01cd8317ad43d8be588c85a0c7
|
File details
Details for the file python_cnb-0.8.0b1-py3-none-any.whl.
File metadata
- Download URL: python_cnb-0.8.0b1-py3-none-any.whl
- Upload date:
- Size: 51.3 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.12.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
2608c2ae27ada56ff0a20abc7d548e1c3821e7f956ab3ddc6383205f6dfb4ec1
|
|
| MD5 |
4e0358a785a0e0120c729093b8a1bcfc
|
|
| BLAKE2b-256 |
3b6f3c3f4141b03016efedba5317267475e2a30b57886e7b2cf64313efcc2315
|