Skip to content

HAL

bibliofabric.hal is a Python client for the HAL search and referential API, the Solr service of the French open archive run by the CCSD. It covers document search with offset and cursor paging, document lookups by HAL identifier, DOI, docid, or record URL, and the referential tables (structures, journals, authors, domains, portal instances, funding projects, metadata values, and document types). Every call returns typed Pydantic models, and each client ships as an async class plus a generated sync twin.

The API needs no credentials. The metadata is published under the CC0 1.0 license; the deposited full texts carry the license of each author.

Quick start

import asyncio

from bibliofabric.hal import DocumentFilters, HalClient


async def main() -> None:
    async with HalClient() as client:
        document = await client.documents.get("hal-03923934")
        print(document.main_title, f"({document.produced_year})")
        print("doi:", document.doi, "main file:", document.file_main)

        page = await client.documents.search(
            query="microbiology",
            filters=DocumentFilters(doc_type="ART", has_doi=True),
            page_size=5,
            select=["docid", "halId_s", "title_s", "doiId_s"],
        )
        print("total hits:", page.total)
        for record in page.results:
            print(record.hal_id, record.main_title[:60])


asyncio.run(main())
Gastro-Intestinal Microbiota in Equines and Its Role in Health and Disease: The Black Box Opens (2022)
doi: 10.3390/microorganisms10122517 main file: https://hal.science/hal-03923934/document
total hits: 21357
hal-05856849 Bacterial Contamination of Surfaces and Antibiotic Susceptib
hal-00579486 The need for European professional standards and the challen

Sync quick start

HalSyncClient 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.hal import HalSyncClient

with HalSyncClient() as client:
    document = client.documents.get("10.3390/microorganisms10122517")
    print(document.main_title)

What the client offers

Attribute Resource Common methods Client-specific methods
client.documents /search/ search, iterate, collect, first, count, batch_get get (docid, HAL identifier, DOI, or record URL), exists, by_doi
client.in_portal(code) /search/{code} (lowercase) same as documents none
client.in_collection(code) /search/{code} (uppercase) same as documents none
client.structures /ref/structure search, iterate, collect, first, count, batch_get get and exists by docid
client.journals /ref/journal same as structures same as structures
client.authors /ref/author same as structures same as structures
client.domains /ref/domain same as structures same as structures
client.instances /ref/instance same as structures get and exists by id
client.anr_projects /ref/anrproject same as structures same as structures
client.european_projects /ref/europeanproject same as structures same as structures
client.metadata /ref/metadatalist same as structures same as structures
client.document_types /ref/doctype none of the common methods list_types

Search results are HalDocument records; select= picks the returned fields and the resource sends its full field set by default. iterate() walks the result set with Solr cursorMark tokens and sorts on docid asc unless you sort otherwise. Facet answers come back through Page.meta. The shared behavior of search, iterate, collect, first, and count is described in Paging, and search(query=...) query strings in Search.

Examples

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

Next