openalexAPI

Beta. openalexAPI works and is tested, and its functions and routes are settled; details of arguments and responses may still change between versions.

openalexAPI serves a local Parquet corpus of OpenAlex works through a web API that answers like the OpenAlex API. You can run the same queries against your own data that you run against OpenAlex: classic filter= / search= URLs, OQL (OpenAlex Query Language), OQO (OpenAlex Query Object), group_by, sort and paging. It also includes a small web page for running queries in the browser.

Because the answers look like OpenAlex’s, the download functions of openalexPro work against the local server unchanged. Point pro_query() at it with endpoint =.

The corpus can come from:

It is meant for project-sized corpora, not the whole snapshot.

Installation

From the openalexPro r-universe, with its dependencies. openalexPro, to download from the server in R, is installed the same way:

install.packages(
  "openalexAPI",
  repos = c("https://openalexpro.r-universe.dev", "https://cloud.r-project.org")
)

The development version from GitHub:

# install.packages("pak")
pak::pak("openalexPro/openalexAPI@dev")

Quick start

library(openalexAPI)

# A corpus downloaded with openalexPro, or any folder of works Parquet files
serve_corpus("my_project/parquet", port = 8000)

Then open http://127.0.0.1:8000/ for the web page, or query the API:

http://127.0.0.1:8000/works?filter=type:article,publication_year:>2015&search=coral bleaching
http://127.0.0.1:8000/works?filter=type:article&group_by=authorships.countries
http://127.0.0.1:8000/?oql=works where type is article and year >= 2015
http://127.0.0.1:8000/works/W2741809807

From another R session, download a subset of the corpus with openalexPro, exactly as from OpenAlex:

library(openalexPro)
q <- pro_query(
  entity = "works", type = "article", search = "coral bleaching",
  endpoint = "http://127.0.0.1:8000"
)
pro_fetch(q, project_folder = "subset")

How it works

classic URL or OQL --> OpenAlex /query (free) --> OQO --> DuckDB SQL --> OpenAlex-shaped JSON
OQO                -----------------------------^  (offline)

prepare_corpus() (run by serve_corpus()) reads the Parquet files into a cached DuckDB database. The cache holds one row per work, IDs and DOIs normalised so they match in any form, and full-text indexes over title and abstract. OpenAlex’s free /query endpoint translates classic URLs and OQL into an OQO, so the query languages are exactly OpenAlex’s. oqo_to_sql() compiles the OQO into SQL. An OQO sent directly runs without network access.

What is supported

Differences from OpenAlex

Corpus size and memory

Query times, database size, build time and memory for 10,000 to 9.6 million works

These figures come from tools/benchmark.R (75 queries covering every feature) on parts of the OpenAlex snapshot, run on a Mac with 14 cores and 36 GB of RAM (tools/benchmark_scaling.csv, figure by tools/plot_scaling.R):

Works Parquet Database Build Median query Slowest query Queries > 1 s
10,000 0.02 GB 0.04 GB 2 s 0.01 s 1.8 s 1 of 75
100,000 0.18 GB 0.5 GB 14 s 0.04 s 2.5 s 3 of 75
1 million 1.6 GB 7 GB 1 min 0.05 s 4.9 s 3 of 75
4.9 million 8.6 GB 28 GB 5 min 0.29 s 18 s 16 of 75
9.6 million 21 GB 63 GB 13 min 0.74 s 51 s 33 of 75

Recommendations:

Works RAM Disk for the cache Use
up to 1 million 16 GB up to 10 GB interactive, on a laptop
up to 5 million 32 GB or more up to 40 GB interactive; heavy queries take seconds
about 10 million 64–96 GB (estimate) 70 GB needs a server; on 36 GB, occasional queries only

Put the cache (cache_dir) on a fast local SSD. The whole OpenAlex snapshot (over 250 million works) is out of scope.

Running on a server

serve_corpus() serves the API and the page from one process, so it can run on a server for a group. Each release is published as a Docker image, ghcr.io/openalexpro/openalexapi. With docker/compose.yaml and docker/Caddyfile, a server needs only Docker and the Parquet files: Caddy in front adds HTTPS with a free certificate. The vignette’s section “Running on a server” has the steps, plus what the server does not do (logins, more than one request at a time).

See vignette("openalexAPI") for the details.