Skip to content

[CLI] Add get_space_secrets + hf spaces secrets ls#4182

Merged
Wauplin merged 3 commits intomainfrom
add-get-space-secrets
May 5, 2026
Merged

[CLI] Add get_space_secrets + hf spaces secrets ls#4182
Wauplin merged 3 commits intomainfrom
add-get-space-secrets

Conversation

@Wauplin
Copy link
Copy Markdown
Contributor

@Wauplin Wauplin commented May 4, 2026

Follow-up on https://github.com/huggingface-internal/moon-landing/pull/18019 (internal) and #4170.

  • Add SpaceSecret dataclass + HfApi.get_space_secrets() method calling GET /api/spaces/{repo_id}/secrets
  • Add hf spaces secrets ls CLI command
  • update docs
$ hf spaces secrets ls smolagents/ml-intern          
KEY                     UPDATED_AT
----------------------- ----------
GITHUB_TOKEN            2026-01-27
HF_ADMIN_TOKEN          2026-01-28
ANTHROPIC_API_KEY       2026-04-23
INFERENCE_TOKEN         2026-02-13
HF_NAMESPACE            2026-02-13
HF_SESSION_UPLOAD_TOKEN 2026-03-05
HF_BILL_TO              2026-04-22
CLAUDE_FREE_DAILY       2026-04-23
CLAUDE_PRO_DAILY        2026-04-23
AWS_ACCESS_KEY_ID       2026-04-23
AWS_SECRET_ACCESS_KEY   2026-04-23
AWS_REGION              2026-04-23
MONGODB_DB              2026-04-28
MONGODB_URI             2026-04-28
OPENAI_API_KEY          2026-04-29

$ hf spaces variables ls smolagents/ml-intern
KEY             VALUE       UPDATED_AT
--------------- ----------- ----------
HF_EMPLOYEE_ORG huggingface 2026-05-01
>>> from huggingface_hub import HfApi
>>> api = HfApi()
>>> api.get_space_secrets("username/my-space")
{'HF_TOKEN': SpaceSecret(key='HF_TOKEN', description=None, updated_at=datetime.datetime(...))}

🤖 Generated with Claude Code


Note

Low Risk
Low risk additive change that introduces a new GET /api/spaces/{repo_id}/secrets wrapper and a CLI listing command; main risk is compatibility with the backend response shape and exposing secret metadata in outputs (values remain write-only).

Overview
Adds support to list Space secrets without revealing values.

Introduces SpaceSecret plus HfApi.get_space_secrets() (and top-level get_space_secrets) to call GET /api/spaces/{repo_id}/secrets and parse secret metadata (key/description/updated timestamp). Exposes this in the CLI via hf spaces secrets list / ls, updates the CLI reference, and refreshes guides to document that listing shows metadata only (no secret values).

Reviewed by Cursor Bugbot for commit ffcbe66. Bugbot is set up for automated code reviews on this repo. Configure here.

Add support for listing Space secrets via the new GET /api/spaces/{repo_id}/secrets endpoint.

- Add `SpaceSecret` dataclass in `_space_api.py` (key, description, updated_at — no value since secrets are write-only)
- Add `get_space_secrets()` method in `HfApi`
- Add `hf spaces secrets ls` CLI command
- Update docs (manage-spaces guide, CLI guide)

Co-Authored-By: Claude Opus 4.6 <[email protected]>
@Wauplin Wauplin requested a review from davanstrien May 4, 2026 12:48
Copy link
Copy Markdown

@cursor cursor Bot left a comment

Choose a reason for hiding this comment

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

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit 18d67e9. Configure here.

Comment thread src/huggingface_hub/hf_api.py
@Wauplin Wauplin requested a review from hanouticelina May 4, 2026 12:48
@bot-ci-comment
Copy link
Copy Markdown

bot-ci-comment Bot commented May 4, 2026

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.

Copy link
Copy Markdown
Member

@davanstrien davanstrien left a comment

Choose a reason for hiding this comment

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

Thanks!

@Wauplin Wauplin merged commit 7c0abeb into main May 5, 2026
21 checks passed
@Wauplin Wauplin deleted the add-get-space-secrets branch May 5, 2026 15:21
@huggingface-hub-bot
Copy link
Copy Markdown
Contributor

This PR has been shipped as part of the v1.14.0 release.

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.

2 participants