Hub Python 库文档
工作机会
加入 Hugging Face 社区
并获得增强的文档体验
开始使用
作业
查看 HfApi 文档页面,了解管理 Hub 上的作业的方法参考。
- 运行作业: run_job()
- 获取日志: fetch_job_logs()
- 检查作业: inspect_job()
- 列出作业: list_jobs()
- 取消作业: cancel_job()
- 运行 UV 作业: run_uv_job()
数据结构
JobInfo
class huggingface_hub.JobInfo
< source >( **kwargs )
参数
- id (
str
) — 作业 ID。 - created_at (
datetime
或None
) — 作业创建时间。 - docker_image (
str
或None
) — 用于作业的 Docker Hub Docker 镜像。如果存在 space_id,则可以为 None。 - space_id (
str
或None
) — 用于作业的 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 (
str
或None
) — 硬件类型,与 Hugging Face Spaces 中的相同。有关可能的值,请参阅 SpaceHardware。例如"cpu-basic"
。 - status — (
JobStatus
或None
): 作业状态,例如JobStatus(stage="RUNNING", message=None)
。有关可能的阶段值,请参阅 JobStage。 - status — (
JobOwner
或None
): 作业所有者,例如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
JobStage
class huggingface_hub.JobStage
< source >( value names = None module = None qualname = None type = None start = 1 )
Hub 上作业可能阶段的枚举。
取自 https://github.com/huggingface/moon-landing/blob/main/server/job_types/JobInfo.ts#L61 (私有 URL)。