From 391c16a1c70bf6f4e78b3120826c2c9a11716e58 Mon Sep 17 00:00:00 2001 From: Iunio Quarto Russo <48384880+iqrusso@users.noreply.github.com> Date: Mon, 26 Aug 2024 11:17:45 +0200 Subject: [PATCH 1/9] Fix user-agent string (#48) --- pyalex/api.py | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pyalex/api.py b/pyalex/api.py index 17f9d96..73afb01 100644 --- a/pyalex/api.py +++ b/pyalex/api.py @@ -23,7 +23,7 @@ def __setattr__(self, key, value): config = AlexConfig( email=None, api_key=None, - user_agent="pyalex/{__version__}", + user_agent=f"pyalex/{__version__}", openalex_url="https://api.openalex.org", max_retries=0, retry_backoff_factor=0.1, From 1b736fe61c0d0e67832e2545f6febdc2a1319861 Mon Sep 17 00:00:00 2001 From: Jonathan de Bruin Date: Mon, 26 Aug 2024 11:18:44 +0200 Subject: [PATCH 2/9] Add test and docs on serializing results (#49) --- README.md | 12 ++++++++++++ tests/test_pyalex.py | 11 +++++++++++ 2 files changed, 23 insertions(+) diff --git a/README.md b/README.md index ea70093..6bffa65 100644 --- a/README.md +++ b/README.md @@ -354,6 +354,18 @@ Works()["W2023271753"].ngrams() ``` +### Serialize + +All results from PyAlex can be serialized. For example, save the results to a JSON file: + +```python +with open(Path("works.json"), "w") as f: + json.dump(Works().get(), f) + +with open(Path("works.json")) as f: + works = [Work(w) for w in json.load(f)] +``` + ## Code snippets A list of awesome use cases of the OpenAlex dataset. diff --git a/tests/test_pyalex.py b/tests/test_pyalex.py index a02b32e..3f73660 100644 --- a/tests/test_pyalex.py +++ b/tests/test_pyalex.py @@ -244,6 +244,17 @@ def test_serializable(tmpdir): assert "W4238809453" in json.load(f)["id"] +def test_serializable_list(tmpdir): + with open(Path(tmpdir, "test.json"), "w") as f: + json.dump(Works().get(), f) + + with open(Path(tmpdir, "test.json")) as f: + works = [Work(w) for w in json.load(f)] + + assert len(works) == 25 + assert all(isinstance(w, Work) for w in works) + + def test_ngrams_without_metadata(): r = Works()["W2023271753"].ngrams(return_meta=False) From b647d889ccaabf53f77226808e397d44cafa4096 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Mon, 26 Aug 2024 11:25:57 +0200 Subject: [PATCH 3/9] [pre-commit.ci] pre-commit autoupdate (#46) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 52fae4a..867500b 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,7 +8,7 @@ repos: - id: check-yaml - id: check-added-large-files - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.5.7 + rev: v0.6.1 hooks: - id: ruff args: [--fix] From 480aa098fead4345a343c7fd509e6c66aab23828 Mon Sep 17 00:00:00 2001 From: Michele Pasin Date: Wed, 25 Sep 2024 16:34:47 +0100 Subject: [PATCH 4/9] Fix README examples (#52) --- README.md | 7 +++++-- 1 file changed, 5 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index 6bffa65..8406cae 100644 --- a/README.md +++ b/README.md @@ -102,7 +102,7 @@ Works()["W2741809807"]["open_access"] The previous works also for Authors, Sources, Institutions, Concepts and Topics ```python -Authors()["A2887243803"] +Authors()["A5027479191"] Authors()["https://orcid.org/0000-0002-4297-0502"] # same ``` @@ -115,7 +115,6 @@ Works().random() Authors().random() Sources().random() Institutions().random() -Concepts().random() Topics().random() Publishers().random() Funders().random() @@ -359,6 +358,10 @@ Works()["W2023271753"].ngrams() All results from PyAlex can be serialized. For example, save the results to a JSON file: ```python +import json +from pathlib import Path +from pyalex import Work + with open(Path("works.json"), "w") as f: json.dump(Works().get(), f) From 5e78f1c3768464f6617600325e024d53755a53c2 Mon Sep 17 00:00:00 2001 From: "pre-commit-ci[bot]" <66853113+pre-commit-ci[bot]@users.noreply.github.com> Date: Wed, 25 Sep 2024 17:36:05 +0200 Subject: [PATCH 5/9] [pre-commit.ci] pre-commit autoupdate (#51) --- .pre-commit-config.yaml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/.pre-commit-config.yaml b/.pre-commit-config.yaml index 867500b..099c678 100644 --- a/.pre-commit-config.yaml +++ b/.pre-commit-config.yaml @@ -8,7 +8,7 @@ repos: - id: check-yaml - id: check-added-large-files - repo: https://github.com/astral-sh/ruff-pre-commit - rev: v0.6.1 + rev: v0.6.7 hooks: - id: ruff args: [--fix] From 9c0ba4535a30686f2a11e41e4d90b054fc282444 Mon Sep 17 00:00:00 2001 From: Jonathan de Bruin Date: Thu, 28 Nov 2024 10:10:39 +0100 Subject: [PATCH 6/9] Add new maintainer @PeterLombaers --- README.md | 3 ++- 1 file changed, 2 insertions(+), 1 deletion(-) diff --git a/README.md b/README.md index 8406cae..aa5316c 100644 --- a/README.md +++ b/README.md @@ -442,6 +442,7 @@ R users can use the excellent [OpenAlexR](https://github.com/ropensci/openalexR) > This library is a community contribution. The authors of this Python library aren't affiliated with OpenAlex. +This library is maintained by [J535D165](https://github.com/J535D165) and [PeterLombaers](https://github.com/PeterLombaers). Feel free to reach out with questions, remarks, and suggestions. The -[issue tracker](/issues) is a good starting point. You can also email me at +[issue tracker](/issues) is a good starting point. You can also reach out via [jonathandebruinos@gmail.com](mailto:jonathandebruinos@gmail.com). From 64fd997edfb2da029ded08dda1197b6435f75fba Mon Sep 17 00:00:00 2001 From: Andrew Hundt Date: Sun, 22 Dec 2024 07:32:43 -0500 Subject: [PATCH 7/9] Update README.md with citing publications case and better wording (#55) --- README.md | 11 +++++++++-- 1 file changed, 9 insertions(+), 2 deletions(-) diff --git a/README.md b/README.md index aa5316c..1e80a5a 100644 --- a/README.md +++ b/README.md @@ -373,7 +373,7 @@ with open(Path("works.json")) as f: A list of awesome use cases of the OpenAlex dataset. -### Cited publications (referenced works) +### Cited publications (works referenced by this paper, outgoing citations) ```python from pyalex import Works @@ -384,6 +384,13 @@ w = Works()["W2741809807"] Works()[w["referenced_works"]] ``` +### Citing publications (other works that reference this paper, incoming citations) + +``` +from pyalex import Works +Works().filter(cites="W2741809807").get() +``` + ### Get works of a single author ```python @@ -442,7 +449,7 @@ R users can use the excellent [OpenAlexR](https://github.com/ropensci/openalexR) > This library is a community contribution. The authors of this Python library aren't affiliated with OpenAlex. -This library is maintained by [J535D165](https://github.com/J535D165) and [PeterLombaers](https://github.com/PeterLombaers). +This library is maintained by [J535D165](https://github.com/J535D165) and [PeterLombaers](https://github.com/PeterLombaers). Feel free to reach out with questions, remarks, and suggestions. The [issue tracker](/issues) is a good starting point. You can also reach out via [jonathandebruinos@gmail.com](mailto:jonathandebruinos@gmail.com). From a0fc2a5e4b964571dc31b549bb17d5aa3b4d6a43 Mon Sep 17 00:00:00 2001 From: Jonathan de Bruin Date: Sun, 22 Dec 2024 14:15:52 +0000 Subject: [PATCH 8/9] Fix test that fails repeatedly due to changes in OA database --- tests/test_pyalex.py | 10 +++++++--- 1 file changed, 7 insertions(+), 3 deletions(-) diff --git a/tests/test_pyalex.py b/tests/test_pyalex.py index 3f73660..e0a9257 100644 --- a/tests/test_pyalex.py +++ b/tests/test_pyalex.py @@ -204,13 +204,17 @@ def test_referenced_works(): # the work to extract the referenced works of w = Works()["W2741809807"] - _, m = ( + w_new, m = ( Works() .filter(openalex_id="|".join(w["referenced_works"])) - .get(return_meta=True) + .get(return_meta=True, per_page=100) ) - assert m["count"] == len(w["referenced_works"]) + assert set([w["id"] for w in w_new]).difference(set(w["referenced_works"])) == set() + # assert set(w["referenced_works"]).difference(set([w["id"] for w in w_new])) + # == set() + + assert m["count"] < len(w["referenced_works"]) @pytest.mark.xfail() From c8d00f87719ae28ceda0d1228f5ecc48a245d5cf Mon Sep 17 00:00:00 2001 From: Jonathan de Bruin Date: Sun, 22 Dec 2024 14:26:15 +0000 Subject: [PATCH 9/9] Skip ngram tests as API is not available --- tests/test_pyalex.py | 2 ++ 1 file changed, 2 insertions(+) diff --git a/tests/test_pyalex.py b/tests/test_pyalex.py index e0a9257..9b3855f 100644 --- a/tests/test_pyalex.py +++ b/tests/test_pyalex.py @@ -259,12 +259,14 @@ def test_serializable_list(tmpdir): assert all(isinstance(w, Work) for w in works) +@pytest.mark.skip("This test is not working due to unavailable API.") def test_ngrams_without_metadata(): r = Works()["W2023271753"].ngrams(return_meta=False) assert len(r) == 1068 +@pytest.mark.skip("This test is not working due to unavailable API.") def test_ngrams_with_metadata(): r, meta = Works()["W2023271753"].ngrams(return_meta=True)