# Spaceランタイムの管理

Hub上のSpaceを管理するためのメソッドの参考情報については、[HfApi](/docs/huggingface_hub/v2.4.0/ja/package_reference/hf_api#huggingface_hub.HfApi)のドキュメントページを確認してください。

- 現在のランタイムを取得します: [get_space_runtime()](/docs/huggingface_hub/v2.4.0/ja/package_reference/hf_api#huggingface_hub.HfApi.get_space_runtime)
- ビルドまたは実行ログを取得します: [fetch_space_logs()](/docs/huggingface_hub/v2.4.0/ja/package_reference/hf_api#huggingface_hub.HfApi.fetch_space_logs)
- シークレットの管理: [add_space_secret()](/docs/huggingface_hub/v2.4.0/ja/package_reference/hf_api#huggingface_hub.HfApi.add_space_secret) および [delete_space_secret()](/docs/huggingface_hub/v2.4.0/ja/package_reference/hf_api#huggingface_hub.HfApi.delete_space_secret)
- ハードウェアの管理: [request_space_hardware()](/docs/huggingface_hub/v2.4.0/ja/package_reference/hf_api#huggingface_hub.HfApi.request_space_hardware)
- 状態の管理: [pause_space()](/docs/huggingface_hub/v2.4.0/ja/package_reference/hf_api#huggingface_hub.HfApi.pause_space)、[restart_space()](/docs/huggingface_hub/v2.4.0/ja/package_reference/hf_api#huggingface_hub.HfApi.restart_space)、[set_space_sleep_time()](/docs/huggingface_hub/v2.4.0/ja/package_reference/hf_api#huggingface_hub.HfApi.set_space_sleep_time)
- Space が準備できるまで待機します: [wait_for_space()](/docs/huggingface_hub/v2.4.0/ja/package_reference/hf_api#huggingface_hub.HfApi.wait_for_space)
- ZeroGPUのクォータを確認します: [get_zero_gpu_quota()](/docs/huggingface_hub/v2.4.0/ja/package_reference/hf_api#huggingface_hub.HfApi.get_zero_gpu_quota)

## データ構造

### SpaceRuntime[[huggingface_hub.SpaceRuntime]]

#### huggingface_hub.SpaceRuntime[[huggingface_hub.SpaceRuntime]]

```python
huggingface_hub.SpaceRuntime(data: dict)
```

[ソース](https://github.com/huggingface/huggingface_hub/blob/v2.4.0/src/huggingface_hub/_space_api.py#L201)

**パラメータ:**

stage (`str`) : スペースの現在のステージ。例: RUNNING。

hardware (`str` または `None`) : Space の現在のハードウェア。例: "cpu-basic"。Space が初めて `BUILDING` 状態にある場合は、`None` になる可能性があります。

requested_hardware (`str` または `None`) : 要求されたハードウェア。`hardware` とは異なる場合があります。特に、要求がまさに実行された直後です。例: "t4-medium"。まだハードウェアが要求されていない場合は `None` になる場合があります。

sleep_time (`int` または `None`) : 最後のリクエストから Space がアクティブな状態を維持する秒数。デフォルト（値が `None` の場合）、アップグレードされたハードウェアで実行されている場合は Space は決してスリープしませんが、無料の 'cpu-basic' ハードウェアでは 48 時間後にスリープします。詳細については、https://huggingface.co/docs/hub/spaces-gpus#sleep-time を参照してください。

volumes (`list[Volume]` または `None`) : Space にマウントされているボリュームのリストです。各ボリュームは、その種類、ソース、マウントパス、およびオプションの設定を記述する [Volume](/docs/huggingface_hub/v2.4.0/ja/package_reference/jobs#huggingface_hub.Volume) オブジェクトです。ボリュームが接続されていない場合は `None` になります。

raw (`dict`) : サーバーからの生レスポンス。Space ランタイムに関する追加情報（レプリカ数、CPU 数、メモリサイズなど）が含まれます。

Spaceの現在のランタイムに関する情報を含みます。

### SpaceHardware[[huggingface_hub.SpaceHardware]]

#### huggingface_hub.SpaceHardware[[huggingface_hub.SpaceHardware]]

```python
huggingface_hub.SpaceHardware(value, names = None, module = None, qualname = None, type = None, start = 1)
```

[ソース](https://github.com/huggingface/huggingface_hub/blob/v2.4.0/src/huggingface_hub/_space_api.py#L68)

Hub上のSpaceを実行するために利用可能なハードウェアの列挙。

Value は文字列と比較できます:
```py
assert SpaceHardware.CPU_BASIC == "cpu-basic"
```

https://github.com/huggingface-internal/moon-landing/blob/main/server/repo_types/SpaceHardwareFlavor.ts (非公開URL) より引用。

### SpaceStage[[huggingface_hub.SpaceStage]]

#### huggingface_hub.SpaceStage[[huggingface_hub.SpaceStage]]

```python
huggingface_hub.SpaceStage(value, names = None, module = None, qualname = None, type = None, start = 1)
```

[ソース](https://github.com/huggingface/huggingface_hub/blob/v2.4.0/src/huggingface_hub/_space_api.py#L22)

Hub上のSpaceのステージとして考えられる値の列挙。

Value は文字列と比較できます:
```py
assert SpaceStage.BUILDING == "BUILDING"
```

https://github.com/huggingface/moon-landing/blob/main/server/repo_types/SpaceInfo.ts#L61（非公開URL）から引用しています。

### SpaceStorage[[huggingface_hub.SpaceStorage]]

#### huggingface_hub.SpaceStorage[[huggingface_hub.SpaceStorage]]

```python
huggingface_hub.SpaceStorage(value, names = None, module = None, qualname = None, type = None, start = 1)
```

[ソース](https://github.com/huggingface/huggingface_hub/blob/v2.4.0/src/huggingface_hub/_space_api.py#L110)

Hub上のSpaceで利用可能な永続ストレージの列挙。

Value は文字列と比較できます:
```py
assert SpaceStorage.SMALL == "small"
```

https://github.com/huggingface/moon-landing/blob/main/server/repo_types/SpaceHardwareFlavor.ts#L24 (非公開URL) より引用。

### SpaceVariable[[huggingface_hub.SpaceVariable]]

#### huggingface_hub.SpaceVariable[[huggingface_hub.SpaceVariable]]

```python
huggingface_hub.SpaceVariable(key: str, values: dict)
```

[ソース](https://github.com/huggingface/huggingface_hub/blob/v2.4.0/src/huggingface_hub/_space_api.py#L280)

**パラメータ:**

key (`str`) : 変数のキー。例: `"MODEL_REPO_ID"`

value (`str`) : 変数の値。例: `"the_model_repo_id"`。

description (`str` または None) : 変数の説明。例: `"Model Repo ID of the implemented model"`。

updatedAt (`datetime` または None) : 変数の最終更新時刻（変数が少なくとも一度更新された場合）。

Spaceの現在の変数に関する情報を含みます。

### SpaceTemplate[[huggingface_hub.SpaceTemplate]]

#### huggingface_hub.SpaceTemplate[[huggingface_hub.SpaceTemplate]]

```python
huggingface_hub.SpaceTemplate(data: dict)
```

[ソース](https://github.com/huggingface/huggingface_hub/blob/v2.4.0/src/huggingface_hub/_space_api.py#L375)

**パラメータ:**

name (`str`) : テンプレルの人間が読みやすい名前（例: `"JupyterLab"`、`"chatbot"`）。

repo_id (`str`) : テンプレート Space のリポジトリ ID（例: `"SpacesExamples/jupyterlab"`）。

sdk (`str`) : テンプレートが構築されているSDK（例: `"gradio"`、`"docker"`、`"static"`）。

preferred_private (`bool`) : このテンプレートから作成される Spaces が非公開であることが推奨されるかどうか。

Hubで利用可能なSpaceテンプレートに関する情報を含みます。

[HfApi.list_space_templates()](/docs/huggingface_hub/v2.4.0/ja/package_reference/hf_api#huggingface_hub.HfApi.list_space_templates) によって返されます。`repo_id` を `space_template` として [HfApi.create_repo()](/docs/huggingface_hub/v2.4.0/ja/package_reference/hf_api#huggingface_hub.HfApi.create_repo) に渡すことで、そのテンプレートから新しい Space を作成できます。

### ZeroGpuQuota[[huggingface_hub.ZeroGpuQuota]]

#### huggingface_hub.ZeroGpuQuota[[huggingface_hub.ZeroGpuQuota]]

```python
huggingface_hub.ZeroGpuQuota(data: dict)
```

[ソース](https://github.com/huggingface/huggingface_hub/blob/v2.4.0/src/huggingface_hub/_space_api.py#L406)

**パラメータ:**

base (`float`) : GPU秒単位の総クォータ。

remaining (`float`) : GPU秒で表した残りのクォータ。

resets_at (`datetime` または `None`) : クォータがリセットされる日付。クォータがまだ使用されていない場合は `None`。

overquota_used (`float` または `None`) : 基本クォータを使い切った後に消費されたオーバークォータ（有料）GPU 秒数です。PRO、Team、Enterprise ユーザーは、https://huggingface.co/settings/billing?add-credits=true でクレジットを購入し、基本クォータを超えて利用できます。

認証済みユーザーのZeroGPUクォータに関する情報を含みます。

ZeroGPUのクォータは、ZeroGPU Spaceを使用するたびに（UIからでも、そのAPIを通じてでも）消費され、定期的にリセットされます。詳細については、https://huggingface.co/docs/hub/spaces-zerogpu を参照してください。

[HfApi.get_zero_gpu_quota()](/docs/huggingface_hub/v2.4.0/ja/package_reference/hf_api#huggingface_hub.HfApi.get_zero_gpu_quota)によって返されます。

