Search
client.search talks to /search. Every method sends format=json and
returns :class:Page objects whose records are SearchResult models.
One page
page = await client.search.search(
query="nanodiamond AND OPEN_ACCESS:Y", result_type="core", page_size=25
)
print(page.total) # hitCount
print(page.next_cursor) # nextCursorMark
print(page.results[0].title)
queryis a Europe PMC query string: free text, field queries (DOI:,PMCID:,AUTH:,SRC:PMC), boolean operators, and parentheses.result_typeis"idlist"(ids only),"lite"(scalar metadata), or"core"(adds abstract, keywords, MeSH headings, grants, chemicals, full text URLs, and more).format=jsonis a separate parameter the client always sends. The route answers an invalidresultTypewith HTTP 200 and an XMLerrorBeanbody; the client raises that answer asAPIErrorinstead of returning an empty page.synonym=Trueexpands query terms with MeSH synonyms.sortis an expression such as"CITED desc","P_PDATE_D asc", or"PDATE desc"; a sequence such as["CITED", "desc"]is joined with a space. The client rejects expressions whose field is not one ofCITED,P_PDATE_D,PDATE,AUTHOR_ID, orRELEVANCE.page_sizeis capped at 1000, the maximum the API accepts.
Iterate everything
The search pages with cursorMark tokens. nextCursorMark repeats unchanged
once the result list is exhausted, and the framework stops on that.
async for record in client.search.iterate(
query="cancer", result_type="lite", page_size=1000
):
print(record.id, record.source)
# resume later from a saved cursor
async for record in client.search.iterate(query="cancer", cursor=saved_cursor):
...
A search can take several seconds. The client default timeout is 30 seconds.
Count without fetching
total = await client.search.count(query="SRC:PPR AND TITLE:nanodiamond")
Search over POST
POST /searchPOST is the same search with the parameters in a form-encoded
body. search_post() mirrors search(), and cursor paging works on the
route, so iterate_post() mirrors iterate() with the same limit,
cursor, on_error, on_page, and failures parameters. limit=0
sends no request, and a negative limit raises ConfigurationError.
Europe PMC serves no single-record route under /search, so
client.search.get() and client.search.exists() raise
ConfigurationError; fetch one record through client.articles.get()
instead, which serves GET /article/{source}/{id} for preprints too
(PPR:PPR324115).
page = await client.search.search_post(query="cancer", result_type="core")
async for record in client.search.iterate_post(query="cancer", page_size=1000):
print(record.id)
Index terms
fields = await client.search.fields()
# ["ACCESSION_ID", "ABSTRACT", ...]
client.profiles.fields() returns the same list as a typed
FieldsResponse model.