Hub documentation
Webhooks 自动化
单点登录(SSO) 审计日志 存储区域 用于私有数据集的 Data Studio 资源组(访问控制) 高级计算选项 高级安全 令牌管理 服务账号 发布者分析 门控组集合 网络安全 下载分析 速率限制 博客文章
PRO 计划 仓库 入门仓库 仓库设置 存储限制 存储后端(Xet) 本地缓存 Pull Requests 与 Discussions 通知 集合 Webhooks GitHub Actions Notebooks 后续步骤 许可证
模型 数据集 Spaces Spaces 概览 Spaces GPU 升级 Spaces ZeroGPU Spaces 开发模式 Spaces 磁盘使用量与存储 Spaces 自定义域名 Spaces 作为 MCP 服务器 Spaces 作为智能体工具 将 Spaces 用作 API 端点 Gradio Spaces Streamlit Spaces 静态 HTML Spaces Docker Spaces 嵌入您的 Space 使用 Docker 运行 Spaces Spaces 配置参考 使用 HF 登录按钮 精选 Spaces Spaces 更新日志 高级主题
存储桶 new 容器镜像 new 任务 智能体 智能体概述 Hugging Face AI 智能体 CLI Hugging Face MCP 服务器 Hugging Face Agent Skills 使用 HF SDK 构建智能体 使用 llama.cpp 的本地代理 Agent 库 会话跟踪格式
其他 Webhooks 自动化
Webhooks 允许你监听 Hugging Face 上特定仓库或存储桶的新变更,或监听属于特定用户/组织集合的所有仓库(不仅限于你自己的仓库,而是任意仓库)上的变更。
在 huggingface_hub Python 客户端中使用 create_webhook 创建一个 webhook,当 Hugging Face 仓库中发生更改时触发 Job:
from huggingface_hub import create_webhook
# Example: Creating a webhook that triggers a Job
webhook = create_webhook(
job_id=job_id,
watched=[{"type": "user", "name": "your-username"}, {"type": "org", "name": "your-org-name"}],
domains=["repo", "discussion"],
secret="your-secret"
)当 bucket 中有文件被添加或删除时,要运行 Job,请监视该 bucket:
webhook = create_webhook(
job_id=job_id,
watched=[{"type": "bucket", "name": "your-username/your-bucket"}],
domains=["repo"],
secrets={"HF_TOKEN": "hf_***"},
)完整示例请参见 使用 Jobs 处理存储桶中的新文件。
Webhook 使用以下环境变量触发 Job:
WEBHOOK_PAYLOAD:完整的 webhook 负载,以 JSON 字符串形式表示WEBHOOK_REPO_ID:仓库或存储桶名称(例如user/repo-name)WEBHOOK_REPO_TYPE:仓库类型(model、dataset、space或bucket)WEBHOOK_SECRET:如果已配置,则为 webhook 密钥WEBHOOK_ID:投递的唯一标识符,在该次投递的重试过程中保持稳定
Webhook 运行不会保留 Job 的卷或密钥。请在
create_webhook中通过secrets=传入 Job 所需的密钥,例如HF_TOKEN。若要通过 Webhook 运行 UV 脚本,请使用hf jobs run <image> uv run <url>定义您的 Job,否则hf jobs uv run会将脚本上传到卷中,而 Webhook 运行并不具备该卷。
Webhook 负载包含多个字段,以下是一些有用的字段:
- event:
- action: one of "create", "delete", "move", "update"
- scope: string
- repo:
- owner: string
- headSha: string (not sent for buckets)
- name: string
- type: one of "dataset", "model", "space", "bucket"
- updatedFiles: for bucket file changes, the list of added and deleted files您可以在 huggingface_hub Webhooks 文档 中查找有关 Webhooks 的更多信息。