Skip to content

Search and filter

A resource's search() takes a free-text query, typed filters, and the common knobs select=, sort=, and page_size=. Everything here uses OpenAlex in an async context; see Async and sync clients for scripts and notebooks. Errors and retries are covered in Errors and retries.

Search with a free-text query

from bibliofabric.openalex import OpenAlexClient

client = OpenAlexClient()

Later blocks reuse this client.

page = await client.works.search(
    query="crispr",
    page_size=3,
    select=["id", "title", "publication_year"],
)

print("total:", page.total)
for work in page.results:
    print(work.publication_year, "|", work.title)
total: 420426
2016 | The Heroes of CRISPR
2010 | The Small, Slow and Specialized CRISPR and Anti-CRISPR of Escherichia and Salmonella
2015 | CRISPR, the disruptor

The query string follows the API's own search syntax. OpenAlex, Europe PMC, and ORCID each have their field syntax (DISPLAY_NAME.search:crispr, TITLE:"crispr", and similar); the client page shows it.

Filter with a typed model or a dict

The filters argument takes a filter model such as WorksFilters, or a plain dict. Both produce the same query parameters; the model gives you autocomplete and handles field aliases such as topics.id:

from bibliofabric.openalex import WorksFilters

filtered = await client.works.search(
    WorksFilters(is_oa=True, publication_year=2024),
    query="crispr",
    page_size=3,
    select=["id", "title", "publication_year"],
)

print("filtered total:", filtered.total)
for work in filtered.results:
    print(work.publication_year, "|", work.title)
filtered total: 47231
2024 | Role of CRISPR-Cas systems and anti-CRISPR proteins in bacterial antibiotic resistance
2024 | CRISPR Advancements for Human Health.
2024 | Past, present, and future of CRISPR genome editing technologies
same = await client.works.search(
    {"is_oa": True, "publication_year": 2024},
    query="crispr",
    page_size=1,
)

print("dict filters total:", same.total)
dict filters total: 47231

Filter fields are client-specific, so each client page lists the fields its filter models declare.

Pick fields, sorting, and page size

select= asks the API to send only the named fields, which cuts transfer and parsing time. sort= orders the results with the API's sort syntax, and page_size= sets the page length up to the API's maximum; a larger value is capped at that maximum:

page = await client.works.search(
    query="crispr",
    sort="cited_by_count:desc",
    select=["id", "title", "publication_year"],
    page_size=3,
)

for work in page.results:
    print(work.publication_year, "|", work.title)
2014 | Moderated estimation of fold change and dispersion for RNA-seq data with DESeq2
2015 | limma powers differential expression analyses for RNA-sequencing and microarray studies
2012 | A Programmable Dual-RNA–Guided DNA Endonuclease in Adaptive Bacterial Immunity

The keyword is always select=, but the API parameter behind it differs: OpenAlex calls it select, and Semantic Scholar calls it fields. Sort syntax is also per API, so check the client page.

Calls that fail before any request

The client checks a call against the resource's declared capabilities and raises ConfigurationError before it sends anything. Passing search text as the first argument is the most common mistake, because the message tells you the fix:

from bibliofabric import ConfigurationError
from bibliofabric.crossref import CrossrefClient
from bibliofabric.orcid import OrcidClient

try:
    await client.works.search("crispr")
except ConfigurationError as exc:
    print("string as filters:", exc)

async with CrossrefClient() as crossref:
    try:
        await crossref.types.search(query="journal")
    except ConfigurationError as exc:
        print("no query support:", exc)

async with OrcidClient() as orcid:
    try:
        await orcid.person.search(query="smith")
    except ConfigurationError as exc:
        print("no search route:", exc)
string as filters: Got a string as filters ('crispr'). Pass search text as query='crispr'; filters takes a filter model or a mapping.
no query support: TypesResource does not support free-text query (dialect.query_param is None and _search_path is not overridden).
no search route: PersonResource does not support search(): the upstream API has no route for it. Use client.person.get() instead.

The same guard rejects cursor=, page=, select=, or sort= on a resource whose API lacks the feature, and a page_size below 1.

Where each client takes its query

The table comes from the source code of every client. Every client that supports free-text search takes the text as the query= keyword; four clients have no free-text search at all.

Client Where to call How the query text is passed
arxiv client.query.search(...) query= keyword, arXiv syntax
crossref client.works.search(...) and the other list resources query= keyword
datacite client.dois.search(...) and the other list resources query= keyword
doaj client.articles.search(...), client.journals.search(...) query= keyword; the text goes into the path, and an empty query raises ConfigurationError
doi No search The client resolves and describes one DOI at a time
europepmc client.articles.search(...) and the other list resources query= keyword, Europe PMC syntax
issn client.records.search(...) query= keyword, mirroring the portal's search form
openaire client.research_products.search(...) and the other graph resources query= keyword
openalex client.works.search(...) and the other resources query= keyword
opencitations No search client.index.citations(id) and similar look up one id
orcid client.records.search(...) query= keyword, Solr syntax
ror client.organizations.search(...) query= keyword
rxiv No free-text search Date-window routes such as client.details.search(start, end, server=...)
semanticscholar client.papers.search(...) query= keyword
wikidata client.entities.search(...), plus client.items.search(...) and client.properties.search(...) query= keyword
zenodo client.records.search(...) query= keyword

A resource not listed for search, such as crossref.types or orcid.person, raises ConfigurationError when you pass a query, as shown above.