Skip to main content

Coze API 工具包

Python 3.7+ License

基于 Coze 工作流 API 的简化 Python 工具包,提供函数式 API 设计,使 API 调用更加简洁直观。

特性

  • 函数式设计:直接函数调用,无需实例化对象
  • 简单易用:无需关注底层实现,专注于业务逻辑
  • 多种认证方式:支持参数、环境变量或配置文件方式提供API令牌
  • 完整示例:提供命令行和 GUI 示例应用

快速开始

安装

# 克隆代码库
git clone https://github.com/your-username/coze-api-toolkit.git
cd coze-api-toolkit

# 安装依赖
pip install -r requirements.txt

配置API令牌

使用工具包前,您需要配置有效的 Coze API 令牌。支持以下方式:

  1. 直接传入令牌

    image_urls = get_imgs_by_key(prompt="一只猫", token="您的API令牌")
    
  2. 环境变量

    # Linux/Mac
    export COZE_API_TOKEN="您的API令牌"
    
    # Windows
    set COZE_API_TOKEN=您的API令牌
    
  3. 配置文件

    # 创建配置目录
    mkdir -p ~/.coze
    
    # 创建配置文件
    echo '{"token": "您的API令牌"}' > ~/.coze/config.json
    

基本使用

from api.get_imgs_by_key import get_imgs_by_key

# 生成图片
image_urls = get_imgs_by_key("一只可爱的猫")  # 自动从环境变量或配置文件加载令牌

# 处理结果
for url in image_urls:
    print(url)

示例应用

本工具包提供了多种示例,展示如何在不同场景下使用 API:

命令行示例

运行简单的命令行示例:

python examples/simple_example.py

此示例将引导您配置API令牌,并根据输入的关键词生成图片URL。

GUI 示例

运行图形界面示例(需要安装 Pillow):

# 先安装额外依赖
pip install pillow

# 运行 GUI 示例
python examples/gui_example.py

GUI示例提供了令牌配置界面,可以保存令牌到配置文件,让使用更加便捷。

项目结构

coze-api-toolkit/
├── api/                  # API 函数实现
│   └── get_imgs_by_key.py  # 图片生成API
├── config/               # 配置文件
│   └── api_catalog.json    # API 接口配置
├── core/                 # 核心实现
│   └── api_client.py       # API 客户端
├── docs/                 # 文档
│   └── design.md           # 设计文档
├── examples/             # 示例应用
│   ├── simple_example.py   # 命令行示例
│   └── gui_example.py      # GUI 示例
├── README.md             # 主文档
├── README_TOOLKIT.md     # 工具包详细文档
└── requirements.txt      # 项目依赖

详细文档

可用 API 的完整说明请查看 README_TOOLKIT.md。

设计理念

该工具包采用三层架构设计:

  1. API 客户端层:负责与 Coze API 通信
  2. 函数式 API 层:提供简化的函数接口
  3. 业务应用层:用户自行实现的业务逻辑

详细的设计思路请参考 docs/design.md 文档。

注意事项

  • 请妥善保管您的 API 令牌,不要将其硬编码在源代码中或提交到公共仓库
  • 目前支持的 API:
    • get_imgs_by_key:根据关键词生成图片
  • 更多 API 将在未来版本中添加

许可证

本项目采用 MIT 许可证,详情请参阅 LICENSE 文件。

贡献指南

欢迎贡献代码、报告问题或提出建议。请通过 GitHub Issues 或 Pull Requests 参与项目开发。

Metadata

Release files for ddq-coze-toolkit 0.1.0

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

Source distribution (sdist)

Source distribution for ddq-coze-toolkit 0.1.0
File Size Uploaded Provenance
ddq_coze_toolkit-0.1.0.tar.gz 11.7 kB Without provenance Details

Built distribution (wheel)

Table of built distributions (wheels) for ddq-coze-toolkit 0.1.0
File Interpreter ABI Platform
ddq_coze_toolkit-0.1.0-py3-none-any.whl Python 3 none any Details

Total release size: 27.0 kB

Release files / ddq_coze_toolkit-0.1.0.tar.gz

Download URL ddq_coze_toolkit-0.1.0.tar.gz
Size 11.7 kB
Tags Source
SHA-256 checksum
How to use checksums
b18cbcb0888994122fad64836dabab7b92c2907ca388bc63ed793c8668578bf5
BLAKE2b-256 checksum
How to use checksums
2326a10a3d38f3224f0a7f182150d19d3782308e4da3f072a08801c2cef83f20
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Release files / ddq_coze_toolkit-0.1.0-py3-none-any.whl

Download URL ddq_coze_toolkit-0.1.0-py3-none-any.whl
Size 15.3 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1744f084b7158df95637c6d66ddc5b1a98dffb1d8fe03e74e6da4191e4229eda
BLAKE2b-256 checksum
How to use checksums
da490fcea3c5a5612ec6e547a044d61fe9a0dc1712f1d99a5024a28ff6b23a58
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/6.1.0 CPython/3.12.3

Security for ddq-coze-toolkit 0.1.0

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.

Release history Release notifications | RSS feed

This release

0.1.0 This release

2 release files No provenance

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