Hub Python 庫文件
工作機會
加入 Hugging Face 社群
並獲得增強的文件體驗
開始使用
任務
請參閱 HfApi 文件頁面,瞭解管理 Hub 上任務的方法。
- 執行任務:run_job()
- 獲取日誌:fetch_job_logs()
- 獲取指標:fetch_job_metrics()
- 檢查任務:inspect_job()
- 列出任務:list_jobs()
- 取消任務:cancel_job()
- 執行 UV 任務:run_uv_job()
資料結構
JobInfo
class huggingface_hub.JobInfo
< source >( **kwargs )
引數
- id (
str) — 任務 ID。 - created_at (
datetimeorNone) — 任務建立時間。 - docker_image (
strorNone) — 從 Docker Hub 拉取的用於該任務的 Docker 映象。如果存在 space_id,則可能為 None。 - space_id (
strorNone) — 來自 Hugging Face Spaces 的用於該任務的 Docker 映象。如果存在 docker_image,則可能為 None。 - command (
list[str]orNone) — 任務的命令,例如["python", "-c", "print('hello world')"] - arguments (
list[str]orNone) — 傳遞給命令的引數 - environment (
dict[str]orNone) — 任務的環境變數,以字典形式表示。 - secrets (
dict[str]orNone) — 任務的秘密環境變數(已加密)。 - flavor (
strorNone) — 硬體的配置,如同 Hugging Face Spaces 中的一樣。有關可能值,請參閱 SpaceHardware。例如"cpu-basic"。 - labels (
dict[str, str]orNone) — 要附加到任務的標籤(鍵值對)。 - status — (
JobStatusorNone): 任務狀態,例如JobStatus(stage="RUNNING", message=None)。有關可能的狀態值,請參閱 JobStage。 - owner — (
JobOwnerorNone): 任務的所有者,例如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', labels=None, 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 上任務的可能階段的列舉。
可能的值為:`COMPLETED`、`CANCELED`、`ERROR`、`DELETED`、`RUNNING`。取自 https://github.com/huggingface/moon-landing/blob/main/server/job_types/JobInfo.ts#L61 (私有 URL)。