Skip to content

Conversation

lhoestq
Copy link
Member

@lhoestq lhoestq commented Sep 22, 2025

>>> from huggingface_hub import create_webhook_job
>>> payload = create_webhook_job(
...     watched=[{"type": "user", "name": "julien-c"}, {"type": "org", "name": "HuggingFaceH4"}],
...     image="python:3.12",
...     command=["bash", "-c", r"echo An event occured in $WEBHOOK_REPO_ID: $WEBHOOK_PAYLOAD"],
...     domains=["repo", "discussion"],
... )

or with a UV script

>>> from huggingface_hub import create_webhook_uv_job
>>> payload = create_webhook_uv_job(
...     script="my_script.py",
...     watched=[{"type": "user", "name": "julien-c"}, {"type": "org", "name": "HuggingFaceH4"}],
...     domains=["repo", "discussion"],
... )
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"
)

TODO:

  • docs
  • [?] tests - there is no jobs on staging afaik I can use for a test

cc @Wauplin @hanouticelina if you want to take a quick look while I dive into doing more docs

No CLI for this one for now, since there is no CLI for webhooks and I'm not sure this would fit very well, but lmk what you think.

note for me for later: update https://huggingface.co/docs/hub/en/webhooks-guide-metadata-review

@HuggingFaceDocBuilderDev

The docs for this PR live here. All of your documentation changes will be reflected on that endpoint. The docs are available until 30 days after the last update.

@Wauplin
Copy link
Contributor

Wauplin commented Sep 22, 2025

High level comment made on slack (internal):

I really like the feature but looking at https://github.com/huggingface/huggingface_hub/pull/3379/files it feels much more complicated to do it via API rather than doing it from the UI.

In the UI user creates a "job webhook" by copy-pasting an existing Job ID.
In the API user create a "job webhook" by re-defining all the Job specs.

I would really prefer if we could have the same logic on the API side as well so that we have a clear distinction between "creating a Job" and "binding a webhook to a Job". Dunno if the update has to be done rather server-side or client-side

@lhoestq
Copy link
Member Author

lhoestq commented Sep 23, 2025

I switched to a simpler approach (same as in the UI):

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"
)

@lhoestq lhoestq marked this pull request as ready for review September 23, 2025 17:54
@lhoestq lhoestq requested a review from Wauplin September 23, 2025 17:55
Copy link
Contributor

@Wauplin Wauplin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Thank you!

Co-authored-by: Lucain <lucain@huggingface.co>
@lhoestq lhoestq merged commit c2e6129 into main Oct 1, 2025
23 of 25 checks passed
@lhoestq lhoestq deleted the webhook-jobs branch October 1, 2025 15:05
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

3 participants