huggingface-hub

Compare original and translation side by side

🇺🇸

Original

English
🇨🇳

Translation

Chinese

Hugging Face CLI (
hf
) Reference Guide

Hugging Face CLI(
hf
)参考指南

The
hf
command is the modern command-line interface for interacting with the Hugging Face Hub, providing tools to manage repositories, models, datasets, and Spaces.
IMPORTANT: The
hf
command replaces the now deprecated
huggingface-cli
command.
hf
命令是用于与Hugging Face Hub交互的现代化命令行界面,提供管理仓库、模型、数据集和Spaces的工具。
重要提示:
hf
命令已取代现已弃用的
huggingface-cli
命令。

Quick Start

快速开始

  • Installation:
    curl -LsSf https://hf.co/cli/install.sh | bash -s
  • Help: Use
    hf --help
    to view all available functions and real-world examples.
  • Authentication: Recommended via
    HF_TOKEN
    environment variable or the
    --token
    flag.

  • 安装:
    curl -LsSf https://hf.co/cli/install.sh | bash -s
  • 帮助: 使用
    hf --help
    查看所有可用功能及实际示例。
  • 身份验证: 推荐通过
    HF_TOKEN
    环境变量或
    --token
    标志进行验证。

Core Commands

核心命令

General Operations

常规操作

  • hf download REPO_ID
    : Download files from the Hub.
  • hf upload REPO_ID
    : Upload files/folders (recommended for single-commit).
  • hf upload-large-folder REPO_ID LOCAL_PATH
    : Recommended for resumable uploads of large directories.
  • hf sync
    : Sync files between a local directory and a bucket.
  • hf env
    /
    hf version
    : View environment and version details.
  • hf download REPO_ID
    :从Hub下载文件。
  • hf upload REPO_ID
    :上传文件/文件夹(推荐用于单次提交)。
  • hf upload-large-folder REPO_ID LOCAL_PATH
    :推荐用于大目录的可恢复上传。
  • hf sync
    :在本地目录与存储桶之间同步文件。
  • hf env
    /
    hf version
    :查看环境和版本详情。

Authentication (
hf auth
)

身份验证(
hf auth

  • login
    /
    logout
    : Manage sessions using tokens from huggingface.co/settings/tokens.
  • list
    /
    switch
    : Manage and toggle between multiple stored access tokens.
  • whoami
    : Identify the currently logged-in account.
  • login
    /
    logout
    :使用huggingface.co/settings/tokens获取的令牌管理会话。
  • list
    /
    switch
    :管理并切换多个已存储的访问令牌。
  • whoami
    :查看当前登录的账户。

Repository Management (
hf repos
)

仓库管理(
hf repos

  • create
    /
    delete
    : Create or permanently remove repositories.
  • duplicate
    : Clone a model, dataset, or Space to a new ID.
  • move
    : Transfer a repository between namespaces.
  • branch
    /
    tag
    : Manage Git-like references.
  • delete-files
    : Remove specific files using patterns.

  • create
    /
    delete
    :创建或永久删除仓库。
  • duplicate
    :将模型、数据集或Space克隆到新ID。
  • move
    :在命名空间之间转移仓库。
  • branch
    /
    tag
    :管理类Git引用。
  • delete-files
    :使用模式删除特定文件。

Specialized Hub Interactions

专属Hub交互

Datasets & Models

数据集与模型

  • Datasets:
    hf datasets list
    ,
    info
    , and
    parquet
    (list parquet URLs).
  • SQL Queries:
    hf datasets sql SQL
    — Execute raw SQL via DuckDB against dataset parquet URLs.
  • Models:
    hf models list
    and
    info
    .
  • Papers:
    hf papers list
    — View daily papers.
  • 数据集:
    hf datasets list
    info
    parquet
    (列出parquet URL)。
  • SQL查询:
    hf datasets sql SQL
    — 通过DuckDB针对数据集parquet URL执行原生SQL。
  • 模型:
    hf models list
    info
  • 论文:
    hf papers list
    — 查看每日论文。

Discussions & Pull Requests (
hf discussions
)

讨论与拉取请求(
hf discussions

  • Manage the lifecycle of Hub contributions:
    list
    ,
    create
    ,
    info
    ,
    comment
    ,
    close
    ,
    reopen
    , and
    rename
    .
  • diff
    : View changes in a PR.
  • merge
    : Finalize pull requests.
  • 管理Hub贡献的生命周期:
    list
    create
    info
    comment
    close
    reopen
    rename
  • diff
    :查看PR中的变更。
  • merge
    :完成拉取请求。

Infrastructure & Compute

基础设施与计算

  • Endpoints: Deploy and manage Inference Endpoints (
    deploy
    ,
    pause
    ,
    resume
    ,
    scale-to-zero
    ,
    catalog
    ).
  • Jobs: Run compute tasks on HF infrastructure. Includes
    hf jobs uv
    for running Python scripts with inline dependencies and
    stats
    for resource monitoring.
  • Spaces: Manage interactive apps. Includes
    dev-mode
    and
    hot-reload
    for Python files without full restarts.
  • 端点: 部署并管理推理端点(
    deploy
    pause
    resume
    scale-to-zero
    catalog
    )。
  • 任务: 在HF基础设施上运行计算任务。包括
    hf jobs uv
    用于运行带有内联依赖的Python脚本,以及
    stats
    用于资源监控。
  • Spaces: 管理交互式应用。包括
    dev-mode
    hot-reload
    ,无需完全重启即可更新Python文件。

Storage & Automation

存储与自动化

  • Buckets: Full S3-like bucket management (
    create
    ,
    cp
    ,
    mv
    ,
    rm
    ,
    sync
    ).
  • Cache: Manage local storage with
    list
    ,
    prune
    (remove detached revisions), and
    verify
    (checksum checks).
  • Webhooks: Automate workflows by managing Hub webhooks (
    create
    ,
    watch
    ,
    enable
    /
    disable
    ).
  • Collections: Organize Hub items into collections (
    add-item
    ,
    update
    ,
    list
    ).

  • 存储桶: 完整的类S3存储桶管理(
    create
    cp
    mv
    rm
    sync
    )。
  • 缓存: 通过
    list
    prune
    (移除分离的修订版本)和
    verify
    (校验和检查)管理本地存储。
  • Webhooks: 通过管理Hub Webhooks(
    create
    watch
    enable
    /
    disable
    )实现工作流自动化。
  • 集合: 将Hub项目组织到集合中(
    add-item
    update
    list
    )。

Advanced Usage & Tips

高级用法与技巧

Global Flags

全局标志

  • --format json
    : Produces machine-readable output for automation.
  • -q
    /
    --quiet
    : Limits output to IDs only.
  • --format json
    :生成机器可读的输出以用于自动化。
  • -q
    /
    --quiet
    :将输出限制为仅显示ID。

Extensions & Skills

扩展与技能

  • Extensions: Extend CLI functionality via GitHub repositories using
    hf extensions install REPO_ID
    .
  • Skills: Manage AI assistant skills with
    hf skills add
    .
  • 扩展: 使用
    hf extensions install REPO_ID
    通过GitHub仓库扩展CLI功能。
  • Skills: 使用
    hf skills add
    管理AI助手技能。