Skip to main content

Python API Wrapper for OpenAlex

Project description

diophila

Python API Wrapper for OpenAlex.

Entities / Endpoints

OpenAlex currently describes five different scholarly entity types and their connections:

Each entity type comes with an endpoint of the same name that can be queried for a single (random or specific) entity or multiple (grouped or listed) entities.

Installation

pip (or pip3) install diophila

Usage

First off, you need to initialize a client. The client offers all methods to query the API.

from diophila import OpenAlex

openalex = OpenAlex()

You can use the client to query for a single random entity with the method get_random_<entity>:

random_author = openalex.get_random_author()
random_author['id']

Or if you have a specific entity in mind, you can use the client using one of the entity's IDs via the get_single_<entity> method:

specific_work = openalex.get_single_work("https://doi.org/10.1364/PRJ.433188", "doi")
specific_work['display_name']

If you are interested in entities grouped into facets, use the get_groups_of_<entities> method:

grouped_institutions = openalex.get_groups_of_institutions("type")
for group in grouped_institutions['group_by']:
    group['key']

And last but not least you can get multiple entities from a type in a list by using the get_list_of_<entities> method. Note that this method uses pagination, either basic paging or cursor paging depending on whether the pages parameter is supplied:

# if no `pages` parameter is supplied, we use cursor paging
pages = None
# if `pages` parameter is supplied, we use basic paging
pages = [1, 2, 3]

filters = {"is_oa": "true",
           "works_count": ">15000"}
pages_of_venues = openalex.get_list_of_venues(filters=filters, pages=pages)

for page in pages_of_venues:        # loop through pages
    for venue in page['results']:   # loop though list of venues
        venue['id']

Bonus: If you want to retrieve all works connected to another entity, you may use the entity's works_api_url property with the get_works_by_api_url method:

works_api_url = "https://api.openalex.org/works?filter=author.id:A1969205032"
pages_of_works = openalex.get_works_by_api_url(works_api_url)

for page in pages_of_works:
    for work in page['results']:
        work['display_name']

The Polite Pool

It's a good idea to use OpenAlex polite pool which offers faster response times for users providing an email address. If you would like to use it, simply initialize the client with your email address.

from diophila import OpenAlex

openalex = OpenAlex("your-email@address.com")

Rate limits

The API currently doesn't have rate limits. However, if you need more than 100,000 calls per day, please drop the OpenAlex team a line at team@ourresearch.org or alternatively look into using a snapshot.

Citation

If you are using OpenAlex in your research, the OpenAlex team kindly asks you to cite https://doi.org/10.48550/arXiv.2205.01833

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

diophila-0.4.0.tar.gz (11.0 kB view details)

Uploaded Source

Built Distribution

diophila-0.4.0-py3-none-any.whl (11.2 kB view details)

Uploaded Python 3

File details

Details for the file diophila-0.4.0.tar.gz.

File metadata

  • Download URL: diophila-0.4.0.tar.gz
  • Upload date:
  • Size: 11.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.13

File hashes

Hashes for diophila-0.4.0.tar.gz
Algorithm Hash digest
SHA256 6fcc04c9d707a601ab6b447d6616de9e6fee118fdf4bc4d9e08bf6c4132704e3
MD5 ebe76a5bbc891c847684f7d4a8dae694
BLAKE2b-256 a044402da824c41f1cd95c5718fedef14a39789c8af15e73d2c18f0c9cbf825b

See more details on using hashes here.

File details

Details for the file diophila-0.4.0-py3-none-any.whl.

File metadata

  • Download URL: diophila-0.4.0-py3-none-any.whl
  • Upload date:
  • Size: 11.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.1 CPython/3.7.13

File hashes

Hashes for diophila-0.4.0-py3-none-any.whl
Algorithm Hash digest
SHA256 b2dab4464026efe1a7b3384b5bfe94c2f29436e0a70643ec842644bf649c2044
MD5 395176aee800dc0b51efe93bb97293e3
BLAKE2b-256 0ba92092e732a65cc5d8e2e71c4db5a2c62e41103f307f7543be1196399adfe1

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page