Skip to content

bibliofabric.europepmc

The EuropePmc client (bibliofabric.europepmc) is a Python client for the Europe PMC REST web services, the annotations API, and the grants API. It types the article search (cursor paging, sorting, resultType=lite|core|idlist), the per-article routes, annotations, grants, profiles, and the preprint subset with Pydantic models. It ships an async client and a generated sync twin with the same API. The APIs need no credentials.

Install

uv add bibliofabric

Requires Python 3.12 or newer.

The EuropePmc client ships in bibliofabric 0.9.0 and newer.

Quick start

import asyncio
from bibliofabric.europepmc import EuropePmcClient


async def main():
    async with EuropePmcClient() as client:
        page = await client.search.search(
            query="DOI:10.1038/nature12373", result_type="core", page_size=1
        )
        article = page.results[0]
        print(article.title, article.cited_by_count)

        references = await client.articles.references(
            "MED:23903748", page=1, page_size=5
        )
        print(references.total, [ref.title for ref in references.results])

        annotations = await client.annotations.by_article_ids(
            "MED:23903748", type="Chemicals"
        )
        print(annotations[0].annotations[0].exact)

        async for record in client.search.iterate(query="nanodiamond", page_size=100):
            print(record.id, record.source)


asyncio.run(main())

Sync usage

The generated EuropePmcSyncClient has the same methods without async and await:

from bibliofabric.europepmc import EuropePmcSyncClient

with EuropePmcSyncClient() as client:
    page = client.search.search(query="DOI:10.1038/nature12373", result_type="core")
    print(page.results[0].title)

    for record in client.search.iterate(query="nanodiamond", page_size=100):
        print(record.id, record.source)

Settings

EuropePmcSettings loads from environment variables prefixed with EUROPEPMC_ and from a .env file in the working directory. EUROPEPMC_MAX_REQUESTS_PER_SECOND (default 3) and EUROPEPMC_MAX_CONCURRENCY (default 2) set the request pace. Europe PMC publishes no rate limit, so these defaults are a courtesy. The shared fields of bibliofabric.config.BaseApiSettings also apply, such as EUROPEPMC_TIMEOUT, EUROPEPMC_MAX_RETRIES, EUROPEPMC_MAX_RETRY_WAIT, and EUROPEPMC_USER_AGENT.

A search can take about ten seconds. The shared timeout default of 30 seconds covers that.

Examples

Runnable scripts live in packages/bibliofabric/examples/europepmc/: a quickstart (search, one record, bounded iteration), citations and references of one article, and a sync full-text XML fetch.

Where to go next