Skip to content

Commit

Permalink
Support resource_group_id in create_repo (#2324)
Browse files Browse the repository at this point in the history
* Support resource_group_id in create_repo

* docs

* as tip

* typoe
  • Loading branch information
Wauplin committed Jun 24, 2024
1 parent e15cae3 commit 67686d6
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 1 deletion.
6 changes: 6 additions & 0 deletions docs/source/en/guides/repository.md
Original file line number Diff line number Diff line change
Expand Up @@ -61,6 +61,12 @@ When you create a repository, you can set your repository visibility with the `p

If you want to change the repository visibility at a later time, you can use the [`update_repo_visibility`] function.

<Tip>

If you are part of an organization with an Enterprise plan, you can create a repo in a specific resource group by passing `resource_group_id` as parameter to [`create_repo`]. Resource groups are a security feature to control which members from your org can access a given resource. You can get the resource group ID by copying it from your org settings page url on the Hub (e.g. `"https://huggingface.co/organizations/huggingface/settings/resource-groups/66670e5163145ca562cb1988"` => `"66670e5163145ca562cb1988"`). For more details about resource group, check out this [guide](https://huggingface.co/docs/hub/en/security-resource-groups).

</Tip>

### Delete a repository

Delete a repository with [`delete_repo`]. Make sure you want to delete a repository because this is an irreversible process!
Expand Down
11 changes: 10 additions & 1 deletion src/huggingface_hub/hf_api.py
Original file line number Diff line number Diff line change
Expand Up @@ -3089,6 +3089,7 @@ def create_repo(
private: bool = False,
repo_type: Optional[str] = None,
exist_ok: bool = False,
resource_group_id: Optional[str] = None,
space_sdk: Optional[str] = None,
space_hardware: Optional[SpaceHardware] = None,
space_storage: Optional[SpaceStorage] = None,
Expand All @@ -3115,6 +3116,11 @@ def create_repo(
`None`.
exist_ok (`bool`, *optional*, defaults to `False`):
If `True`, do not raise an error if repo already exists.
resource_group_id (`str`, *optional*):
Resource group in which to create the repo. Resource groups is only available for organizations and
allow to define which members of the organization can access the resource. The ID of a resource group
can be found in the URL of the resource's page on the Hub (e.g. `"66670e5163145ca562cb1988"`).
To learn more about resource groups, see https://huggingface.co/docs/hub/en/security-resource-groups.
space_sdk (`str`, *optional*):
Choice of SDK to use if repo_type is "space". Can be "streamlit", "gradio", "docker", or "static".
space_hardware (`SpaceHardware` or `str`, *optional*):
Expand Down Expand Up @@ -3182,8 +3188,11 @@ def create_repo(
# Testing purposes only.
# See https://github.com/huggingface/huggingface_hub/pull/733/files#r820604472
json["lfsmultipartthresh"] = self._lfsmultipartthresh # type: ignore
headers = self._build_hf_headers(token=token)

if resource_group_id is not None:
json["resourceGroupId"] = resource_group_id

headers = self._build_hf_headers(token=token)
while True:
r = get_session().post(path, headers=headers, json=json)
if r.status_code == 409 and "Cannot create repo: another conflicting operation is in progress" in r.text:
Expand Down

0 comments on commit 67686d6

Please sign in to comment.