Skip to content

Commit 3d4ee3a

Browse files
davanstrienclaude
andauthored
data-processing: set the token on the webhook, not the base Job (#128)
huggingface_hub#5009 adds --secrets to hf webhooks create, so the setup steps use one CLI command and the WEBHOOK_SECRET fallback is no longer needed: a triggered run now gets HF_TOKEN as a secret. Claude-Session: https://claude.ai/code/session_015YLK3QPDdiiZGuDxoFrEag Co-authored-by: Claude Opus 5 (1M context) <noreply@anthropic.com>
1 parent 68b54ce commit 3d4ee3a

2 files changed

Lines changed: 8 additions & 21 deletions

File tree

‎data-processing/README.md‎

Lines changed: 4 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -50,18 +50,12 @@ Use `hf jobs run ... uv run <url>` here, not `hf jobs uv run <url>`. `hf jobs uv
5050

5151
**2. Create a webhook on the input bucket that re-runs this Job:**
5252

53-
```python
54-
from huggingface_hub import create_webhook
55-
56-
create_webhook(
57-
job_id="<job id from step 1>",
58-
watched=[{"type": "bucket", "name": "<user>/my-raw-files"}],
59-
domains=["repo"],
60-
secret="<fine-grained token>",
61-
)
53+
```bash
54+
hf webhooks create --job-id <job id from step 1> \
55+
--watch bucket:<user>/my-raw-files --domain repo --secrets HF_TOKEN
6256
```
6357

64-
The Job uses the webhook `secret` as its token to read and write the buckets. Use a fine-grained token, not your main one.
58+
`--secrets HF_TOKEN` stores a token with the webhook, encrypted, and every triggered run receives it as a secret to read and write the buckets. The value comes from `HF_TOKEN` in your environment, or from the token you logged in with; pass `--secrets HF_TOKEN=hf_…` to use a different one. Use a fine-grained token, not your main one. The base Job needs no `--secrets`, because a webhook run does not inherit the Job's own secrets.
6559

6660
**3. Upload a file:**
6761

‎data-processing/optimize-parquet.py‎

Lines changed: 4 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -19,13 +19,10 @@
1919
uv run https://huggingface.co/datasets/uv-scripts/data-processing/raw/main/optimize-parquet.py
2020
2121
# 2. A webhook on the input bucket that re-runs that Job on every change.
22-
from huggingface_hub import create_webhook
23-
create_webhook(
24-
job_id="<job id from step 1>",
25-
watched=[{"type": "bucket", "name": "<user>/<input-bucket>"}],
26-
domains=["repo"],
27-
secret="<fine-grained token>",
28-
)
22+
# --secrets HF_TOKEN gives every triggered run a token for the two buckets;
23+
# a webhook run does not inherit the base Job's own secrets.
24+
hf webhooks create --job-id <job id from step 1> \\
25+
--watch bucket:<user>/<input-bucket> --domain repo --secrets HF_TOKEN
2926
3027
Then upload files to the input bucket, e.g.
3128
`hf buckets cp data.csv hf://buckets/<user>/<input-bucket>/data.csv`,
@@ -40,10 +37,6 @@
4037

4138
from datasets import load_dataset
4239

43-
# Use the webhook secret as the token when HF_TOKEN is not set.
44-
if "HF_TOKEN" not in os.environ and "WEBHOOK_SECRET" in os.environ:
45-
os.environ["HF_TOKEN"] = os.environ["WEBHOOK_SECRET"]
46-
4740
BUILDERS = {".csv": "csv", ".json": "json", ".jsonl": "json", ".parquet": "parquet"}
4841

4942
event = json.loads(os.environ.get("WEBHOOK_PAYLOAD", "{}"))

0 commit comments

Comments
 (0)