This document describes the field validation capabilities added to the QueryBuilder module.
The QueryBuilder now includes comprehensive field validation that automatically checks if all Europe PMC API fields are properly defined in the FieldType literal. This ensures that the query builder stays up-to-date with the latest API changes.
The FieldType literal now includes all 142 fields from the Europe PMC API (as of 2025-11-05), plus:
author/auth, affiliation/aff)mesh, pmid, subset)from pyeuropepmc.query_builder import get_available_fields
# Fetch current fields from Europe PMC API
fields = get_available_fields()
print(f"Available fields: {len(fields)}")
from pyeuropepmc.query_builder import validate_field_coverage
# Check if all API fields are covered
result = validate_field_coverage(verbose=True)
if result['up_to_date']:
print("✅ All API fields are covered!")
else:
print(f"❌ Missing {len(result['missing_in_code'])} fields")
# Check field coverage from command line
python scripts/check_fields.py
title, abstract, author (auth), journal, issn, doi, pmid, pmcidpub_year, pub_type, volume, issuee_pdate, first_pdate, p_pdatecreation_date, update_date, index_date, embargo_dateauthor / auth, affiliation / aff, investigatorauthorid, authorid_type, auth_first, auth_lastmesh (not in API but works)chemical / chem, chebiterm, chebiterm_iddisease, gene_protein, organism, gotermexperimental_method, experimental_method_idgrant_agency, grant_agency_id, grant_id, funder_initiativehas_abstract, has_pdf, has_fulltext, has_reflisthas_tm (text-mined), has_suppl, has_dataopen_access, in_pmc, in_epmchas_uniprot, uniprot_pubshas_embl, embl_pubshas_pdb, pdb_pubshas_intact, intact_pubshas_chebi, has_chemblcites, cited, reffed_by, citation_counttitle_abs, intro, methods, results, discuss, conclfig, table, suppl, ref, appendix, ack_fundEurope PMC supports both full and abbreviated field names:
| Full Name | Abbreviated | Usage |
|---|---|---|
author |
auth |
Author names |
affiliation |
aff |
Author affiliations |
language |
lang |
Publication language |
keyword |
kw |
Keywords |
chemical |
chem |
Chemical substances |
source |
src |
Data source (MED, PMC, etc.) |
editor |
ed |
Book editors |
Both forms are accepted by the API and included in FieldType.
from pyeuropepmc import QueryBuilder
# Use full field names
qb = QueryBuilder()
query = qb.keyword("Smith", field="author").build()
# Result: Smith:AUTHOR
# Or use abbreviations
qb = QueryBuilder()
query = qb.keyword("Smith", field="auth").build()
# Result: Smith:AUTH
# Add to your CI pipeline to ensure fields stay up-to-date
python scripts/check_fields.py || exit 1
from pyeuropepmc.query_builder import validate_field_coverage
result = validate_field_coverage(verbose=False)
if not result['up_to_date']:
print("⚠️ Field definitions need updating!")
print(f"Missing fields: {result['missing_in_code']}")
The field list is validated against the Europe PMC API:
https://www.ebi.ac.uk/europepmc/webservices/rest/fields?format=jsonWhen the Europe PMC API adds new fields:
python scripts/check_fields.py
If new fields are found, add them to FieldType in src/pyeuropepmc/query_builder.py
Update the “Last Updated” comment in the code
get_available_fields(api_url=None) -> list[str]Fetches the current list of searchable fields from Europe PMC API.
Returns: List of field names (lowercase, sorted)
Raises:
ImportError if requests is not installedRuntimeError if API request failsvalidate_field_coverage(verbose=False) -> dictValidates that FieldType includes all API fields.
Returns: Dictionary with:
api_fields: Fields from APIdefined_fields: Fields in FieldTypemissing_in_code: API fields not in FieldTypeextra_in_code: FieldType fields not in APIcoverage_percent: Coverage percentageup_to_date: True if 100% coveragetotal_api_fields: Count of API fieldstotal_defined_fields: Count of defined fieldsParameters:
verbose (bool): Print detailed comparisonSome fields are documented in the Europe PMC reference guide but don’t appear in the /fields API endpoint:
mesh - MeSH terms (works in queries)pmid - PubMed ID (works in queries)subset - Content set filterspage_info - Page numberscrd_links, has_crd - Clinical trialsembargoed_man - Embargoed manuscriptsThese are intentionally kept in FieldType as they’re documented and functional.
Some fields are for internal use and rarely needed in queries:
_version_, shard, qn1, qn2text_hl, text_synonymsThese are included for completeness but typically not used in user queries.