Skip to content

Conversation

@BastienGimbert
Copy link
Contributor

Problem :

There was no function to list models from an organization on the Hub.

Summary :

Add HfApi.list_organization_models(organization, p=1, sort=None, search=None, token=None)
This calls /api/organizations/{organization}/models-json
Add a test to check the list returns ModelInfo objects.

Testing :

pytest -q tests/test_hf_api.py::UserApiTest::test_list_organization_models

Copy link
Contributor

@Wauplin Wauplin left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Hi @BastienGimbert , it's actually already possible to list models from a given organization using list_models:

list_models(author=huggingface_hub)

I'm therefore closing this PR. I do think it's best not to have multiple ways of doing the same thing. The /api/organizations/{organization}/models-json route is also less robust to pagination and only used to display models in the UI.

@BastienGimbert
Copy link
Contributor Author

BastienGimbert commented Oct 30, 2025

Hi @BastienGimbert , it's actually already possible to list models from a given organization using list_models:

list_models(author=huggingface_hub)

I'm therefore closing this PR. I do think it's best not to have multiple ways of doing the same thing. The /api/organizations/{organization}/models-json route is also less robust to pagination and only used to display models in the UI.

No problem 👍 thanks for the clarification!

In any case, I would use these routes on my side to take advantage of the parameters .

Out of curiosity, do you think it could still be useful to use some of the more “UI-oriented” routes like quicksearch or discussions in the SDK?
Even if they’re mainly designed for the web, they could have some interesting use cases — for example, quicksearch could be used to provide autocomplete suggestions instead of calling list_models, list_datasets many time separately like i do rn.

@Wauplin
Copy link
Contributor

Wauplin commented Oct 30, 2025

For quicksearch I think we can yes. For discussions, what do you have in mind? We already have helpers to manage the community tab (list discussions and PRs, comment, open, close, merge, etc.). See https://huggingface.co/docs/huggingface_hub/guides/community

@BastienGimbert
Copy link
Contributor Author

For quicksearch I think we can yes. For discussions, what do you have in mind? We already have helpers to manage the community tab (list discussions and PRs, comment, open, close, merge, etc.). See https://huggingface.co/docs/huggingface_hub/guides/community

For example, we could add all the sorting parameters.
And just like get_repo_discussions, it would be nice to support discussions from Spaces and Datasets too. Currently, it only works for models.

@Wauplin
Copy link
Contributor

Wauplin commented Oct 30, 2025

Signature of get_repo_discussions is:

    def get_repo_discussions(
        self,
        repo_id: str,
        *,
        author: Optional[str] = None,
        discussion_type: Optional[constants.DiscussionTypeFilter] = None,
        discussion_status: Optional[constants.DiscussionStatusFilter] = None,
        repo_type: Optional[str] = None,
        token: Union[bool, str, None] = None,
    ) -> Iterator[Discussion]:

So it works for all types of repo (with repo_type) + returns an iterator (meaning you can scroll through all of them). Regarding sorting it's true it's not available in this method (yet?) but mainly due to the fact that sorting discussions is a pretty recent feature.

@BastienGimbert
Copy link
Contributor Author

Signature of get_repo_discussions is:

    def get_repo_discussions(
        self,
        repo_id: str,
        *,
        author: Optional[str] = None,
        discussion_type: Optional[constants.DiscussionTypeFilter] = None,
        discussion_status: Optional[constants.DiscussionStatusFilter] = None,
        repo_type: Optional[str] = None,
        token: Union[bool, str, None] = None,
    ) -> Iterator[Discussion]:

So it works for all types of repo (with repo_type) + returns an iterator (meaning you can scroll through all of them). Regarding sorting it's true it's not available in this method (yet?) but mainly due to the fact that sorting discussions is a pretty recent feature.

Oh okay, good to know!
I only checked the doc, not the method itself.
The doc could be updated too, it’s missing this info.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants