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:
openalexPro::pro_request_parquet() / pro_fetch() downloadsIt is meant for project-sized corpora, not the whole snapshot.
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")
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")
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.
cites and cited_by. AND, OR (a|b),
negation (!a), ranges, and null for “field missing” all work.group_by on one dimension, with OpenAlex’s key formats.
:include_unknown is supported.search,
search.exact and the <field>.search filters, plus searches in
affiliation strings and author names. All words must match, quoted
phrases must appear in order, proximity ("a"~N~"b", "a b"~N)
works, and wildcards work with .exact. Results are ranked by
relevance_score (BM25)./links serves the corpus’s link table (links/ next to the
corpus), shaped like OpenAlex’s /links, with all link types and
relations the source wrote (e.g. every related identifier of a Zenodo
corpus), filters on origin, target, link_type, relation, and
group_by.select, sort, per_page, page, cursor
and sample/seed, and look up single works by ID or DOI.referenced_works), so
/links is empty there.group_by results (“AU” rather than “Australia”).group_by on several
dimensions, and OQL’s comparisons and nested queries. 156 of
OpenAlex’s 174 OQL example queries run locally
(tools/oql_coverage.R).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 |
prepare_corpus()) takes 3 to 7
times the space of the Parquet files: about 7 GB per million works.group_by on references or keywords, and
200 records per page with all fields.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.
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.