Skip to content

Commit 6a66890

Browse files
BastienGimbertBastien GIMBERTWauplinSamoedgithub-actions[bot]
authored
Add daily papers endpoint (#3502)
* feat: add list_daily_papers method to fetch daily papers by date * feat: update list_daily_papers method to support optional date parameter and add tests for default behavior ( After Wauplin review ) * Apply suggestion from @Wauplin * Update src/huggingface_hub/hf_api.py Co-authored-by: Roman Solomatin <[email protected]> * Apply style fixes --------- Co-authored-by: Bastien GIMBERT <[email protected]> Co-authored-by: Lucain <[email protected]> Co-authored-by: Roman Solomatin <[email protected]> Co-authored-by: github-actions[bot] <github-actions[bot]@users.noreply.github.com>
1 parent 55bbd21 commit 6a66890

File tree

3 files changed

+56
-0
lines changed

3 files changed

+56
-0
lines changed

src/huggingface_hub/__init__.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -232,6 +232,7 @@
232232
"inspect_scheduled_job",
233233
"list_accepted_access_requests",
234234
"list_collections",
235+
"list_daily_papers",
235236
"list_datasets",
236237
"list_inference_catalog",
237238
"list_inference_endpoints",
@@ -894,6 +895,7 @@
894895
"interpreter_login",
895896
"list_accepted_access_requests",
896897
"list_collections",
898+
"list_daily_papers",
897899
"list_datasets",
898900
"list_inference_catalog",
899901
"list_inference_endpoints",
@@ -1254,6 +1256,7 @@ def __dir__():
12541256
inspect_scheduled_job, # noqa: F401
12551257
list_accepted_access_requests, # noqa: F401
12561258
list_collections, # noqa: F401
1259+
list_daily_papers, # noqa: F401
12571260
list_datasets, # noqa: F401
12581261
list_inference_catalog, # noqa: F401
12591262
list_inference_endpoints, # noqa: F401

src/huggingface_hub/hf_api.py

Lines changed: 37 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -9885,6 +9885,42 @@ def paper_info(self, id: str) -> PaperInfo:
98859885
hf_raise_for_status(r)
98869886
return PaperInfo(**r.json())
98879887

9888+
def list_daily_papers(
9889+
self,
9890+
*,
9891+
date: Optional[str] = None,
9892+
token: Union[bool, str, None] = None,
9893+
) -> Iterable[PaperInfo]:
9894+
"""
9895+
List the daily papers published on a given date on the Hugging Face Hub.
9896+
9897+
Args:
9898+
date (`str`, *optional*):
9899+
Date in ISO format (YYYY-MM-DD) for which to fetch daily papers.
9900+
Defaults to most recent ones.
9901+
token (Union[bool, str, None], *optional*):
9902+
A valid user access token (string). Defaults to the locally saved
9903+
token. To disable authentication, pass `False`.
9904+
9905+
Returns:
9906+
`Iterable[PaperInfo]`: an iterable of [`huggingface_hub.hf_api.PaperInfo`] objects.
9907+
9908+
Example:
9909+
9910+
```python
9911+
>>> from huggingface_hub import HfApi
9912+
9913+
>>> api = HfApi()
9914+
>>> list(api.list_daily_papers(date="2025-10-29"))
9915+
```
9916+
"""
9917+
path = f"{self.endpoint}/api/daily_papers"
9918+
params = {"date": date} if date is not None else {}
9919+
r = get_session().get(path, params=params, headers=self._build_hf_headers(token=token))
9920+
hf_raise_for_status(r)
9921+
for paper in r.json():
9922+
yield PaperInfo(**paper)
9923+
98889924
def auth_check(
98899925
self, repo_id: str, *, repo_type: Optional[str] = None, token: Union[bool, str, None] = None
98909926
) -> None:
@@ -10906,6 +10942,7 @@ def _parse_revision_from_pr_url(pr_url: str) -> str:
1090610942

1090710943
list_papers = api.list_papers
1090810944
paper_info = api.paper_info
10945+
list_daily_papers = api.list_daily_papers
1090910946

1091010947
repo_exists = api.repo_exists
1091110948
revision_exists = api.revision_exists

tests/test_hf_api.py

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -4283,6 +4283,22 @@ def test_get_paper_by_id_not_found(self) -> None:
42834283
self.api.paper_info("1234.56789")
42844284
assert context.exception.response.status_code == 404
42854285

4286+
def test_list_daily_papers_by_date(self) -> None:
4287+
papers = list(self.api.list_daily_papers(date="2025-10-29"))
4288+
assert len(papers) > 0
4289+
assert hasattr(papers[0], "id")
4290+
assert hasattr(papers[0], "title")
4291+
4292+
def test_list_daily_papers_by_date_invalid_date(self) -> None:
4293+
with self.assertRaises(BadRequestError):
4294+
list(self.api.list_daily_papers(date="2025-13-40"))
4295+
4296+
def test_list_daily_papers_default_date(self) -> None:
4297+
papers = list(self.api.list_daily_papers())
4298+
assert len(papers) > 0
4299+
assert hasattr(papers[0], "id")
4300+
assert hasattr(papers[0], "title")
4301+
42864302

42874303
class WebhookApiTest(HfApiCommonTest):
42884304
def setUp(self) -> None:

0 commit comments

Comments
 (0)