# Managing collections

请查阅 [HfApi](/docs/huggingface_hub/v2.4.0/zh/package_reference/hf_api#huggingface_hub.HfApi) 文档页面，以获取管理 Hub 上 Space 的方法参考。

- 获取集合内容：[get_collection()](/docs/huggingface_hub/v2.4.0/zh/package_reference/hf_api#huggingface_hub.HfApi.get_collection)
- 创建新集合：[create_collection()](/docs/huggingface_hub/v2.4.0/zh/package_reference/hf_api#huggingface_hub.HfApi.create_collection)
- 更新集合：[update_collection_metadata()](/docs/huggingface_hub/v2.4.0/zh/package_reference/hf_api#huggingface_hub.HfApi.update_collection_metadata)
- 更新集合的资源组：[update_collection_resource_group()](/docs/huggingface_hub/v2.4.0/zh/package_reference/hf_api#huggingface_hub.HfApi.update_collection_resource_group)
- 删除集合：[delete_collection()](/docs/huggingface_hub/v2.4.0/zh/package_reference/hf_api#huggingface_hub.HfApi.delete_collection)
- 向集合添加一个项目：[add_collection_item()](/docs/huggingface_hub/v2.4.0/zh/package_reference/hf_api#huggingface_hub.HfApi.add_collection_item)
- 更新集合中的项目：[update_collection_item()](/docs/huggingface_hub/v2.4.0/zh/package_reference/hf_api#huggingface_hub.HfApi.update_collection_item)
- 从集合中删除一个项目：[delete_collection_item()](/docs/huggingface_hub/v2.4.0/zh/package_reference/hf_api#huggingface_hub.HfApi.delete_collection_item)

### 集合[[huggingface_hub.Collection]]

#### huggingface_hub.Collection[[huggingface_hub.Collection]]

```python
huggingface_hub.Collection(**kwargs)
```

[源代码](https://github.com/huggingface/huggingface_hub/blob/v2.4.0/src/huggingface_hub/hf_api.py#L1381)

**参数：**

slug (`str`) : 集合的 Slug。例如 `"TheBloke/recent-models-64f9a55bb3115b4f513ec026"`。

title (`str`) : 集合的标题。例如 `"Recent models"`。

owner (`str`) : 集合的所有者。例如 `"TheBloke"`。

items (`list[CollectionItem]`) : 集合中的项目列表。

last_updated (`datetime`) : 该集合的最后更新日期。

position (`int`) : 该集合在所有者集合列表中的位置。

private (`bool`) : 该集合是否为私有。

theme (`str`) : 集合的主题。例如 `"green"`。

upvotes (`int`) : 该收藏的点赞数。

description (`str`, *可选*) : 集合的描述，以纯文本形式表示。

url (`str`) : (property) Hub 上该集合的 URL。

包含有关 Hub 上 Collection 的信息。

### CollectionItem[[huggingface_hub.CollectionItem]]

#### huggingface_hub.CollectionItem[[huggingface_hub.CollectionItem]]

```python
huggingface_hub.CollectionItem(_id: str, id: str, type: CollectionItemType_T, position: int, note: dict | None = None, **kwargs)
```

[源代码](https://github.com/huggingface/huggingface_hub/blob/v2.4.0/src/huggingface_hub/hf_api.py#L1333)

**参数：**

item_object_id (`str`) : 集合中该项目的唯一 ID。

item_id (`str`) : Hub 上底层对象的 ID。可以是 repo_id、论文 ID、集合 slug 或 bucket ID。例如 `"jbilcke-hf/ai-comic-factory"`、`"2307.09288"`、`"celinah/cerebras-function-calling-682607169c35fbfa98b30b9a"`。

item_type (`str`) : 底层对象的类型。可以是 `"model"`、`"dataset"`、`"space"`、`"paper"`、`"collection"` 或 `"bucket"` 之一。

position (`int`) : 该元素在集合中的位置。

note (`str`, *可选*) : 与该条目相关的备注，以纯文本形式表示。

包含有关 Collection（模型、数据集、Space、论文、collection 或 bucket）中某个项目的信息。

