ClinicalTrials.gov
The ClinicalTrials.gov client (bibliofabric.clinicaltrials) reads the
ClinicalTrials.gov Data API v2:
study records with their protocol and results sections, the study data model
metadata, search areas, enum types, and corpus statistics. Calls return
typed Pydantic models through an async client and a generated sync twin.
Credentials
The API needs no credentials, and the data is United States public domain.
The client paces itself at one request every 2 seconds with 2 concurrent
requests, inside the API's budget of about 50 requests per minute per IP
address. Tune both with CLINICALTRIALS_MAX_REQUESTS_PER_SECOND and
CLINICALTRIALS_MAX_CONCURRENCY; see the
settings guide. The constructor also takes a
keyword-only mailto= contact address; it overrides CLINICALTRIALS_MAILTO
and appears in the User-Agent the client sends.
Quick start
import asyncio
from bibliofabric.clinicaltrials import ClinicalTrialsClient
async def main() -> None:
async with ClinicalTrialsClient() as client:
record = await client.studies.get("NCT00841061")
identification = record.protocol_section.identification_module
print(identification.nct_id, identification.brief_title)
page = await client.studies.search(query="cancer", page_size=25)
print(page.total, "matches")
for study in page.results[:3]:
print(
" ",
study.protocol_section.identification_module.nct_id,
study.protocol_section.status_module.overall_status,
)
version = await client.version()
print(version.api_version, version.data_timestamp)
asyncio.run(main())
NCT00841061 Cereals as a Source of Iron for Breastfed Infants
146489 matches
NCT03856515 COMPLETED
NCT04931615 COMPLETED
NCT03183115 RECRUITING
2.0.5 2026-11-30T10:00:04
Sync quick start
from bibliofabric.clinicaltrials import ClinicalTrialsSyncClient
with ClinicalTrialsSyncClient() as client:
page = client.studies.search(filters={"query.cond": "lung cancer"})
print(page.total, "lung cancer studies")
for study in client.studies.iterate(page_size=1000, limit=2000):
print(study.protocol_section.identification_module.nct_id)
14767 lung cancer studies
NCT02546635
NCT01491035
NCT04215835
NCT01250535
What the client covers
client.studies: search (GET /studies) with thequery.*andfilter.*parameters throughStudyFilters,get()andexists()onGET /studies/{nctId},batch_get()throughfilter.ids, and the metadata routesstudies.metadata(),studies.search_areas(), andstudies.enums().client.stats:sizes(),field_values(), andfield_sizes()for the/statsroutes.client.version(): the API version and data timestamp.studies.download_csv(): a whole search result as one CSV file.
Structured search
The query= argument of search() is the basic query.term area. Every
other query.* and filter.* parameter travels in StudyFilters, whose
fields carry the upstream parameter names as aliases:
from bibliofabric.clinicaltrials import StudyFilters
filters = StudyFilters(
query_cond="lung cancer",
filter_advanced="AREA[StudyType]INTERVENTIONAL AND AREA[Phase]PHASE3",
filter_overall_status="RECRUITING",
)
page = await client.studies.search(filters, sort="LastUpdatePostDate:desc")
print(page.total, page.next_cursor)
Query strings use the
Essie expression syntax.
select= projects fields (select=["NCTId", "BriefTitle"]), and
countTotal=true is sent on every search so page.total and count()
carry a total; the API ignores the parameter on continuation pages.