FastComments.com

FastComments Python SDK

这是 FastComments 的官方 Python SDK。

FastComments API 的官方 Python SDK

仓库

在 GitHub 上查看


安装 Internal Link

从 GitHub 安装

直接从发布标签安装(推荐,完全可复现):

pip install git+https://github.com/fastcomments/fastcomments-python.git@v3.1.0

固定标签而不是分支,以确保构建确定性。相同的写法也适用于 requirements.txt

fastcomments @ git+https://github.com/fastcomments/fastcomments-python.git@v3.1.0

每个带标签的 GitHub Release 也附带了已构建的 wheel,如果你更倾向于直接安装二进制制品,可以使用它。

库内容

该库包含两个模块:生成的 API 客户端和核心 Python 库,后者包含手写的实用工具,以简化 API 的使用,包括 SSO 支持。

公共 API 与受限 API

对于 API 客户端,有三个类,DefaultApiPublicApiModerationApiDefaultApi 包含需要你的 API 密钥的方法,PublicApi 包含可以直接从浏览器/移动设备等无需身份验证调用的方法。ModerationApi 提供了丰富的实时和快速审核 API。每个 ModerationApi 方法都接受 sso 参数,并且可以通过 SSO 或 FastComments.com 会话 Cookie 进行身份验证。

注意事项 Internal Link

广播 ID

你会看到在某些 API 调用中需要传递 broadcast_id。当你接收到事件时,会把这个 ID 返回给你,这样如果你打算在客户端乐观地应用更改,就可以据此忽略该事件(你可能会想这么做,因为它能提供最佳体验)。在此处传递一个 UUID。该 ID 应足够唯一,确保在同一浏览器会话中不会出现两次。

要求 Internal Link

  • Python >= 3.8

基础安装是纯标准库的,并提供 SSO 实用工具。生成的 API 客户端(DefaultApi/PublicApi/ModerationApi)需要 client 额外依赖,它会拉取 urllib3 >= 1.25.3python-dateutil >= 2.8.2pydantic >= 2.0.0typing-extensions >= 4.0.0

pip install "fastcomments[client] @ git+https://github.com/fastcomments/fastcomments-python.git@v3.1.0"

需要帮助?

如果您在使用 Python SDK 时遇到任何问题或有任何疑问,请:

贡献

欢迎贡献!请访问 GitHub 仓库 获取贡献指南。