-
Notifications
You must be signed in to change notification settings - Fork 18
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Implemented autocomplete endpoint and added documentation #33
Merged
Merged
Changes from all commits
Commits
Show all changes
8 commits
Select commit
Hold shift + click to select a range
fe0eabc
added function to autocomplete (entity specific)
romain894 1e2b191
fully implemented autocomplete endpoint
romain894 2b203eb
added documentation in readme for retries
romain894 2ce6f2f
fixed linter errors
romain894 3d56949
fixed README
romain894 50584c9
Merge branch 'J535D165:main' into main
romain894 947e391
modified pull request according to comments + added tests
romain894 7d75309
fixed readme import names
romain894 File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -23,7 +23,7 @@ The following features of OpenAlex are currently supported by PyAlex: | |
- [x] Select fields | ||
- [x] Sample | ||
- [x] Pagination | ||
- [ ] [Autocomplete endpoint](https://docs.openalex.org/how-to-use-the-api/get-lists-of-entities/autocomplete-entities) | ||
- [x] Autocomplete endpoint | ||
- [x] N-grams | ||
- [x] Authentication | ||
|
||
|
@@ -45,10 +45,10 @@ pip install pyalex | |
|
||
## Getting started | ||
|
||
PyAlex offers support for all [Entity Objects](https://docs.openalex.org/api-entities/entities-overview): [Works](https://docs.openalex.org/api-entities/works), [Authors](https://docs.openalex.org/api-entities/authors), [Sources](https://docs.openalex.org/api-entities/sourcese), [Institutions](https://docs.openalex.org/api-entities/institutions), [Concepts](https://docs.openalex.org/api-entities/concepts), [Publishers](https://docs.openalex.org/api-entities/publishers), and [Funders](https://docs.openalex.org/api-entities/funders). | ||
PyAlex offers support for all [Entity Objects](https://docs.openalex.org/api-entities/entities-overview): [Works](https://docs.openalex.org/api-entities/works), [Authors](https://docs.openalex.org/api-entities/authors), [Sources](https://docs.openalex.org/api-entities/sourcese), [Institutions](https://docs.openalex.org/api-entities/institutions), [Concepts](https://docs.openalex.org/api-entities/concepts), [Publishers](https://docs.openalex.org/api-entities/publishers), [Funders](https://docs.openalex.org/api-entities/funders), and [Autocomplete](https://docs.openalex.org/how-to-use-the-api/get-lists-of-entities/autocomplete-entities). | ||
|
||
```python | ||
from pyalex import Works, Authors, Sources, Institutions, Concepts, Publishers, Funders | ||
from pyalex import Works, Authors, Sources, Institutions, Concepts, Publishers, Funders, autocomplete | ||
``` | ||
|
||
### The polite pool | ||
|
@@ -63,6 +63,18 @@ import pyalex | |
pyalex.config.email = "[email protected]" | ||
``` | ||
|
||
### Max retries | ||
|
||
By default, PyAlex will raise an error at the first failure when querying the OpenAlex API. You can set `max_retries` to a number higher than 0 to allow PyAlex to retry when an error occurs. `retry_backoff_factor` is related to the delay between two retry, and `retry_http_codes` are the HTTP error codes that should trigger a retry. | ||
|
||
```python | ||
from pyalex import config | ||
|
||
config.max_retries = 0 | ||
config.retry_backoff_factor = 0.1 | ||
config.retry_http_codes = [429, 500, 503] | ||
``` | ||
|
||
### Get single entity | ||
|
||
Get a single Work, Author, Source, Institution, Concept, Publisher or Funder from OpenAlex by the | ||
|
@@ -305,6 +317,32 @@ for page in pager: | |
``` | ||
|
||
|
||
### Autocomplete | ||
|
||
OpenAlex reference: [Autocomplete entities](https://docs.openalex.org/how-to-use-the-api/get-lists-of-entities/autocomplete-entities). | ||
|
||
Autocomplete a string: | ||
```python | ||
from pyalex import autocomplete | ||
|
||
autocomplete("stockholm resilience centre") | ||
``` | ||
|
||
Autocomplete a string to get a specific type of entities: | ||
```python | ||
from pyalex import Institutions | ||
|
||
Institutions().autocomplete("stockholm resilience centre") | ||
``` | ||
|
||
You can also use the filters to autocomplete: | ||
```python | ||
from pyalex import Works | ||
|
||
r = Works().filter(publication_year=2023).autocomplete("planetary boundaries") | ||
``` | ||
|
||
|
||
### Get N-grams | ||
|
||
OpenAlex reference: [Get N-grams](https://docs.openalex.org/api-entities/works/get-n-grams). | ||
|
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
My suggestion would be to implement it like this:
Also, it's not the nicest option, but it keeps the autocomplete functionality separated from everything else. We don't need the changes above. As I don't think this was the most intuitive implementation OpenAlex chose, we might benefit from keeping it separate from the rest of the class.
I changed
_get_from_url
to accept an extra argument.