Metadata-Version: 2.4
Name: openalex-reporting
Version: 0.2.0
Summary: A bibliometric data warehouse for any set of OpenAlex works
Author-email: Gael Bernard <gael.bernard@epfl.ch>
License-Expression: MIT
Project-URL: Homepage, https://github.com/epfl-p-data/OpenAlexReporting
Project-URL: Repository, https://github.com/epfl-p-data/OpenAlexReporting
Project-URL: Issues, https://github.com/epfl-p-data/OpenAlexReporting/issues
Keywords: bibliometrics,OpenAlex,DuckDB,reporting
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Science/Research
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Programming Language :: Python :: 3.13
Classifier: Programming Language :: Python :: 3.14
Classifier: Topic :: Scientific/Engineering :: Information Analysis
Requires-Python: >=3.11
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: duckdb>=2.0
Requires-Dist: pandas>=2.0
Requires-Dist: requests>=2.31
Provides-Extra: build
Requires-Dist: openalex-metrics>=0.5; extra == "build"
Provides-Extra: test
Requires-Dist: pytest>=8; extra == "test"
Dynamic: license-file

# OAR — bibliometric reporting from OpenAlex

[![PyPI](https://img.shields.io/pypi/v/openalex-reporting)](https://pypi.org/project/openalex-reporting/)

OAR builds a bibliometric database for a university. The same call works for a researcher, a country, a funder or a list of DOIs. The result is one DuckDB file and a markdown guide beside it. The guide holds the queries, each with its result on that file. Reading them needs DuckDB 2.0 or newer and nothing else.

The citation scores come from [OAM](https://github.com/epfl-p-data/OpenAlexImpactMetrics). OAM compares each paper with papers of the same subfield, the same publication year and the same kind of venue, journal or conference. OAR keeps those scores and adds titles, authors, affiliations and the open-access copy.

A paper is scored only when it is in OAM's scope, peer-reviewed research in English, about 13% of OpenAlex. `count(*)` counts every work in the set, of every OpenAlex type, including datasets and software. `count(ncs)` counts the ones an impact average uses. For EPFL the two are 148,555 and 96,201, and a report should say which one it shows.

## Get started

Python 3.11 or newer.

```bash
pip install 'openalex-reporting[build]'
```

`oar.build` reads an OAM dataset. Install it once, on the machine that builds the database. One call fetches both Zenodo files: the scores, 12 GB, and the citation links published beside them, 9.9 GB.

```python
import oam
oam.download(edges=True)       # into ~/oam-data
```

`oam.download()` without `edges=True` skips the links, and `oar.build` then stops. From archives already on disk, give the folder that holds both `oam-<snapshot>.tar` and `edges-<snapshot>.tar`: `oam.download("path/to/dist", edges=True)`.

The institution id is the number in its OpenAlex URL. `https://openalex.org/I5124864` is EPFL, so the argument is `I5124864`. Set `OPENALEX_API_KEY` before building. A university is about ten thousand requests; without a key the daily limit is too low. Copy `.env.example` to `.env` to keep the key out of the shell history.

```python
import oar

oar.build(name="epfl", institution="I5124864")
```

The file lands in `./output` when Python imports this checkout, which it does when you run it from the repository directory, and in `~/oar-data` otherwise. `oar.set_data_dir(path)` or the environment variable `OAR_DATA_DIR` puts it somewhere else. `output/` is not committed.

For EPFL that is about 150,000 works, about 13,000 API requests, and a file of 8.0 GB. The build took about 30 minutes once the download had finished. A second call with the same selection does nothing if that snapshot was already built. The API responses are cached per work, so the next institution reuses the papers the two share.

The same call works for an author, an ORCID, a country, a funder or a list of DOIs. `world="all"` also copies authors, DOIs and ORCIDs, which a comparison against a researcher needs. A country the size of the United States is a few million API requests; build it with `details=False` and the counts come from the world tables alone. [Building](docs/building.md) has every option.

## What you get

Two files with the same stem, for example `epfl-2026-10-14.duckdb` and `epfl-2026-10-14.md`.

The database has two parts. The selection is this set of works, described by the API: title, abstract, authors, affiliations, funders, locations. The publication year, the subfield and the journal-or-conference flag come from the OAM snapshot, because those three are what a score was computed from. The world is every work's id, score and institutional affiliation, copied from OAM, about 8 GB. A comparison with another institution, a country or the world reads it. It holds ids and names. `world=None` keeps only the selection, and those comparisons then see only it.

The guide opens with one page for the people who will read the numbers: what the file holds, how to use it with an AI assistant, and what to say when quoting a figure. The rest describes every table and column, explains which papers are scored, and gives the queries. The text is [`oar/doc_template.md`](oar/doc_template.md), the same for every database. The build fills in the numbers, runs each query and writes the first rows of its result. `oar.doc(path)` writes the guide again after the template changes.

[An EPFL guide](docs/example-epfl.md) is a full example of that file.

## A query

Scored papers, the mean normalised citation score and the top-10% share. EPFL, 2021 to 2024, from the snapshot of 14 October 2026:

```sql
SELECT w.publication_year AS year,
       count(m.ncs) AS scored,
       avg(m.ncs) AS mncs,
       100 * avg(m.is_in_top_10_percent::INT) AS pp_top10
FROM works w
LEFT JOIN work_metrics m USING (work_id)
WHERE w.publication_year BETWEEN 2021 AND 2024
GROUP BY w.publication_year
ORDER BY year;
```

| year | scored | mncs | pp_top10 |
|---|---:|---:|---:|
| 2021 | 4,498 | 1.80 | 20.08 |
| 2022 | 4,349 | 1.89 | 20.74 |
| 2023 | 4,470 | 1.74 | 20.25 |
| 2024 | 4,457 | 1.83 | 21.11 |

`count(ncs)` is the scored papers. `mncs` is the mean of OAM's normalised citation score, and the world average is 1. `pp_top10` is the share OAM flagged in the top 10% of their cohort. The guide has the same figures together with collaboration, open access, a peer, a country and the world.

## An example

`examples/epfl.py` builds EPFL and prints it next to ETH Zurich and next to Switzerland.

## Data and licence

The descriptive fields come from the [OpenAlex API](https://openalex.org). The scores and the world tables come from OAM's snapshot, which is released under CC0. Say which snapshot you used. `build_info` in the file records it.

OAR is released under the MIT licence. See [LICENSE](LICENSE).
