Identifier¶
Within OpenAlex, IDs consist of two core components: a consistent base, https://openalex.org/
, and a unique resource identifier called the Key, such as A000000000
. Consequently, a complete ID is structured as https://openalex.org/A000000000
.
While querying the API using the full ID is an option, at pub analyzer, we prefer utilizing only the key. This choice enhances the clarity of logs and proves especially helpful during debugging.
Hence, the subsequent functions have been devised. They accept entity models as input and yield the corresponding keys from their IDs.
Info
For further details about the OpenAlex IDs, consult the documentation.
How to recognize the type of entity?
You can deduce the entity's type from the ID itself. This is possible because all keys commence with a letter that corresponds to the entity's type: W(ork), A(uthor), S(ource), I(nstitution), C(oncept), P(ublisher), or F(under). Quite convenient, isn't it?
Functions to extract OpenAlex IDs from Models.
get_author_id ¶
def get_author_id(
author: Author | AuthorResult | DehydratedAuthor,
) -> AuthorOpenAlexKey
Extract OpenAlex ID from author Model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
author
|
Author | AuthorResult | DehydratedAuthor
|
Author model instance. |
required |
Returns:
Type | Description |
---|---|
AuthorOpenAlexKey
|
Author OpenAlex ID. |
get_institution_id ¶
def get_institution_id(
institution: Institution
| InstitutionResult
| DehydratedInstitution,
) -> InstitutionOpenAlexKey
Extract OpenAlex ID from institution Model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
institution
|
Institution | InstitutionResult | DehydratedInstitution
|
Institution model instance. |
required |
Returns:
Type | Description |
---|---|
InstitutionOpenAlexKey
|
Institution OpenAlex ID. |
get_source_id ¶
def get_source_id(source: DehydratedSource | Source) -> str
Extract OpenAlex ID from Source Model.
Parameters:
Name | Type | Description | Default |
---|---|---|---|
source
|
DehydratedSource | Source
|
Source model instance. |
required |
Returns:
Type | Description |
---|---|
str
|
Source OpenAlex ID. |