Skip to content

BASE

bibliofabric.base is a Python client for the BASE HTTP interface, the BaseHttpSearchInterface.fcgi script at https://api.base-search.net. BASE indexes the metadata of scientific documents from institutional repositories and other content providers. The client covers the search route (func=PerformSearch) and the two repository routes (func=ListRepositories and func=ListProfile), and ships as an async class plus a generated sync twin.

Access is credential-gated. The interface answers only requests from a whitelisted IP or IP range, or requests that carry an apikey parameter; you register for either through the contact form on the BASE developer page. BaseClient reads the key from the BASE_API_KEY environment variable (or a .env file) and sends it as the apikey parameter with every request. The interface is available for non-commercial purposes only, as the BASE Interface Guide states.

The client is built from the published BASE Interface Guide. No live check ran while writing it, because this environment holds no whitelisted IP and no apikey; treat the response shapes as documented, not observed. The interface sets a limit of one request per second, and that is the pace the client defaults to.

Quick start

import asyncio

from bibliofabric.base import BaseClient


async def main() -> None:
    async with BaseClient() as client:
        page = await client.documents.search(
            query="dctitle:quantum AND dcyear:[2020 TO 2024]", page_size=5
        )
        print("total hits:", page.total)
        for record in page.results:
            print(record.id, record.title, record.year)

        record = await client.documents.get(page.results[0].id)
        print(record.creator, record.link)

        facets = await client.documents.search(
            query="quantum",
            page_size=1,
            params={"facets": "dcyear", "facet_limit": "10"},
        )
        print(facets.meta["facet_counts"]["facet_fields"]["f_dcyear"])


asyncio.run(main())

page.meta carries everything the answer holds besides the records: the responseHeader request echo, start, maxScore, and the facet_counts breakdown. With page_size=0 a search answers only the total and the facets, which the interface documents as a valid page size.

Sync quick start

BaseSyncClient is generated from the async source and offers the same methods without async and await. The page Async and sync clients explains when to use which.

from bibliofabric.base import BaseSyncClient

with BaseSyncClient() as client:
    page = client.documents.search(query="dctitle:quantum", page_size=5)
    for record in page.results:
        print(record.id, record.title)

What the client offers

Attribute Routes Methods
client.documents func=PerformSearch search, iterate, collect, first, count, get, exists; batch_get raises ConfigurationError
client.repositories func=ListRepositories, func=ListProfile list, profile

Search results are Document records with the Dublin Core fields of the BASE index (the wire names dcdocid, dctitle, dccreator, and so on become id, title, creator, and friends). get(id) resolves a dcdocid through a one-record search, because the interface has no per-record route. The shared behavior of search, iterate, collect, first, and count is described in Paging, and search(query=...) query strings in Search.

Search parameters

Keyword Goes out as Notes
query query SOLR query syntax, at most 1000 characters
filters f_<field> facet refinement; keys are facet fields such as dcsubject
select fields comma-joined field projection
sort sortby "dcyear desc", "dcyear:desc", or ["dcyear", "desc"]; the sortable fields are dchdate, dccreator, dctitle, dcoa, and dcyear
page offset offset 0 to 999
page_size hits 0 to 125 records per answer; the default is 10

The remaining PerformSearch parameters go through params=: {"coll": "ceu"} or {"target": "ftubbiepub"} scopes the query to a pre-defined collection or one repository, {"boost": "oa"} pushes open access records up, and {"facets": ...}, {"facet_limit": ...}, and {"facet_sort": ...} shape the facet breakdown.

repositories.list() returns every repository, or one collection's repositories; the internal_name of each entry scopes searches through params={"target": ...} and names the repository that repositories.profile() takes.

Examples

Runnable scripts live in packages/bibliofabric/examples/base/:

  • quickstart.py searches, looks up one record, counts, and iterates a few hits.
  • repositories.py lists the repositories of a collection and reads one profile.

Next