Hub Python 库文档

工作机会

Hugging Face's logo
加入 Hugging Face 社区

并获得增强的文档体验

开始使用

作业

查看 HfApi 文档页面,了解管理 Hub 上的作业的方法参考。

数据结构

JobInfo

class huggingface_hub.JobInfo

< >

( **kwargs )

参数

  • id (str) — 作业 ID。
  • created_at (datetimeNone) — 作业创建时间。
  • docker_image (strNone) — 用于作业的 Docker Hub Docker 镜像。如果存在 space_id,则可以为 None。
  • space_id (strNone) — 用于作业的 Hugging Face Spaces Docker 镜像。如果存在 docker_image,则可以为 None。
  • command (List[str]None) — 作业命令,例如 ["python", "-c", "print('hello world')"]
  • arguments (List[str]None) — 传递给命令的参数
  • environment (Dict[str]None) — 作业的环境变量,以字典形式表示。
  • secrets (Dict[str]None) — 作业的秘密环境变量(已加密)。
  • flavor (strNone) — 硬件类型,与 Hugging Face Spaces 中的相同。有关可能的值,请参阅 SpaceHardware。例如 "cpu-basic"
  • status — (JobStatusNone): 作业状态,例如 JobStatus(stage="RUNNING", message=None)。有关可能的阶段值,请参阅 JobStage
  • status — (JobOwnerNone): 作业所有者,例如 JobOwner(id="5e9ecfc04957053f60648a3e", name="lhoestq", type="user")

包含有关作业的信息。

示例

>>> from huggingface_hub import run_job
>>> job = run_job(
...     image="python:3.12",
...     command=["python", "-c", "print('Hello from the cloud!')"]
... )
>>> job
JobInfo(id='687fb701029421ae5549d998', created_at=datetime.datetime(2025, 7, 22, 16, 6, 25, 79000, tzinfo=datetime.timezone.utc), docker_image='python:3.12', space_id=None, command=['python', '-c', "print('Hello from the cloud!')"], arguments=[], environment={}, secrets={}, flavor='cpu-basic', status=JobStatus(stage='RUNNING', message=None), owner=JobOwner(id='5e9ecfc04957053f60648a3e', name='lhoestq', type='user'), endpoint='https://huggingface.co', url='https://huggingface.co/jobs/lhoestq/687fb701029421ae5549d998')
>>> job.id
'687fb701029421ae5549d998'
>>> job.url
'https://huggingface.co/jobs/lhoestq/687fb701029421ae5549d998'
>>> job.status.stage
'RUNNING'

JobOwner

class huggingface_hub.JobOwner

< >

( id: str name: str type: str )

JobStage

class huggingface_hub.JobStage

< >

( value names = None module = None qualname = None type = None start = 1 )

Hub 上作业可能阶段的枚举。

值可以与字符串进行比较

assert JobStage.COMPLETED == "COMPLETED"

取自 https://github.com/huggingface/moon-landing/blob/main/server/job_types/JobInfo.ts#L61 (私有 URL)。

JobStatus

class huggingface_hub.JobStatus

< >

( stage: JobStage message: typing.Optional[str] )

< > 在 GitHub 上更新