Skip to content

CORE

The Core client (bibliofabric.core) reads the CORE API v3: works, outputs, journals, and data providers harvested from the open access repositories CORE aggregates. It searches the shared search route, reads single records and their stats, downloads full text files, and calls the discovery and recommendation endpoints. Calls return typed Pydantic models through an async client and a generated sync twin.

This client was built and tested against the published OpenAPI document of the API. No call against the live CORE service ran while building it, so every route is unverified against live responses; see upstream quirks for the consequences.

Credentials

CORE serves unauthenticated requests at a small quota (the token table of the CORE API documentation lists 100 tokens per day and 10 requests per minute without a key). Register at core.ac.uk/services/api for a key with a larger quota. The client reads the key from CORE_API_KEY, or the api_key= constructor argument, and sends it as an Authorization: Bearer header. Without a key it sends none.

The client paces itself to 0.15 requests per second (one request every 6.7 seconds), which stays inside the tightest per-minute cap the documentation lists, with one request at a time. Tune both with CORE_MAX_REQUESTS_PER_SECOND and CORE_MAX_CONCURRENCY; see the settings guide.

Quick start

import asyncio

from bibliofabric.core import CoreClient


async def main() -> None:
    async with CoreClient() as client:
        page = await client.works.search(query='title:"attention is all you need"')
        print(page.total, "matches")
        work = page.results[0]
        print(work.id, work.title, work.year_published)

        work = await client.works.get("8848131")
        print(work.doi, work.download_url)
        print(await client.works.stats("8848131"))

        journals = await client.journals.search(query="issn:1234-5678")
        print(journals.results[0].title)


asyncio.run(main())

The output shapes follow the payloads the published document describes; the figures above are illustrative, because no live check ran.

Search over POST

The GET search and the POST search route are equivalent upstream. The POST variant carries the parameters as a JSON body with native types, which helps for long or complex queries:

page = await client.works.search_post(
    query='yearPublished>2020 AND fullText:"graph neural network"',
    offset=10,
    page_size=20,
    stats=True,
)

search_post takes the raw route offset, not a page number. Pagination on both routes runs over offset and limit; the simple search tops out at 10,000 results, and the client raises ConfigurationError past that ceiling.

Query language

CORE has no filter parameter on the search routes. Scoping happens inside the q string, in the CORE query language:

Clause Matches
title:"machine learning" the phrase in the title
doi:10.1038/nature12373 the exact DOI
yearPublished>2018 published after 2018
a AND b, a OR b both, either
_exists_:fullText records with a full text

That is why the resources take no filters= on search(): pass the whole expression as query.

Data providers, discovery, and recommendations

stats = await client.data_providers.stats("121")
outputs = await client.data_providers.outputs("121", query="climate")

found = await client.discovery.find(doi="10.1234/example.2018")
print(found.full_text_link, found.source)

recommendation = await client.recommendations.find(
    text="Attention is all you need", limit=5
)

See reference for the full operation list.

Full text

works.download(id, dest) and outputs.download(id, dest) stream the file of a record to a path. outputs.raw(id, dest) saves the raw harvested XML record, outputs.history(id) lists the harvested OAI-PMH versions, and works.tei(id) parses the TEI XML of a work. Full text needs a key: the published document answers keyless full text requests with a "Not available for public API users" placeholder.

Sync quick start

from bibliofabric.core import CoreSyncClient

with CoreSyncClient() as client:
    page = client.works.search(query="quantum dots")
    for work in page.results[:5]:
        print(work.id, work.title)