Skip to content

Commit 8695cfa

Browse files
feat: add list_daily_papers method to fetch daily papers by date
1 parent 1a39248 commit 8695cfa

File tree

2 files changed

+47
-0
lines changed

2 files changed

+47
-0
lines changed

src/huggingface_hub/hf_api.py

Lines changed: 36 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9702,6 +9702,41 @@ def paper_info(self, id: str) -> PaperInfo:
97029702
hf_raise_for_status(r)
97039703
return PaperInfo(**r.json())
97049704

9705+
def list_daily_papers(
9706+
self,
9707+
*,
9708+
date: str,
9709+
token: Union[bool, str, None] = None,
9710+
) -> Iterable[PaperInfo]:
9711+
"""
9712+
List the daily papers published on a given date on the Hugging Face Hub.
9713+
9714+
Args:
9715+
date (`str`):
9716+
Date in ISO format (YYYY-MM-DD) for which to fetch daily papers.
9717+
token (Union[bool, str, None], *optional*):
9718+
A valid user access token (string). Defaults to the locally saved
9719+
token. To disable authentication, pass `False`.
9720+
9721+
Returns:
9722+
`Iterable[PaperInfo]`: an iterable of [`huggingface_hub.hf_api.PaperInfo`] objects.
9723+
9724+
Example:
9725+
9726+
```python
9727+
>>> from huggingface_hub import HfApi
9728+
9729+
>>> api = HfApi()
9730+
>>> list(api.list_daily_papers(date="2025-10-29"))
9731+
```
9732+
"""
9733+
path = f"{self.endpoint}/api/daily_papers"
9734+
params = {"date": date}
9735+
r = get_session().get(path, params=params, headers=self._build_hf_headers(token=token))
9736+
hf_raise_for_status(r)
9737+
for paper in r.json():
9738+
yield PaperInfo(**paper)
9739+
97059740
def auth_check(
97069741
self, repo_id: str, *, repo_type: Optional[str] = None, token: Union[bool, str, None] = None
97079742
) -> None:
@@ -10723,6 +10758,7 @@ def _parse_revision_from_pr_url(pr_url: str) -> str:
1072310758

1072410759
list_papers = api.list_papers
1072510760
paper_info = api.paper_info
10761+
list_daily_papers = api.list_daily_papers
1072610762

1072710763
repo_exists = api.repo_exists
1072810764
revision_exists = api.revision_exists

tests/test_hf_api.py

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -64,6 +64,7 @@
6464
SpaceInfo,
6565
SpaceRuntime,
6666
User,
67+
PaperInfo,
6768
WebhookInfo,
6869
WebhookWatchedItem,
6970
repo_type_and_id_from_hf_id,
@@ -4228,6 +4229,16 @@ def test_get_paper_by_id_not_found(self) -> None:
42284229
self.api.paper_info("1234.56789")
42294230
assert context.exception.response.status_code == 404
42304231

4232+
def test_list_daily_papers_by_date(self) -> None:
4233+
papers = list(self.api.list_daily_papers(date="2025-10-29"))
4234+
assert len(papers) > 0
4235+
assert hasattr(papers[0], "id")
4236+
assert hasattr(papers[0], "title")
4237+
4238+
def test_list_daily_papers_by_date_invalid_date(self) -> None:
4239+
with self.assertRaises(ValueError):
4240+
list(self.api.list_daily_papers(date="2025-13-40"))
4241+
42314242

42324243
class WebhookApiTest(HfApiCommonTest):
42334244
def setUp(self) -> None:

0 commit comments

Comments
 (0)