API reference
Generated from the source with mkdocstrings.
Client
bibliofabric.clinicaltrials.ClinicalTrialsClient
Client for the ClinicalTrials.gov Data API v2.
The API needs no credentials and its data is United States public
domain. The client sends Accept: application/json on every request
and paces itself at one request every 2 seconds by default, inside the
API's budget of about 50 requests per minute per IP address. mailto
sets the contact address in the User-Agent; an explicit argument
wins over the settings value.
studies: StudiesResource
cached
property
The studies resource client.
stats: StatsResource
cached
property
The statistics resource client.
version() -> Version
async
Return the API version and the data timestamp of the registry.
The sync twin ClinicalTrialsSyncClient mirrors the client method for
method and exports from the same module:
from bibliofabric.clinicaltrials import ClinicalTrialsSyncClient.
Settings
bibliofabric.clinicaltrials.ClinicalTrialsSettings
ClinicalTrials.gov-specific client settings.
Inherits timeout, max_retries, max_retry_wait,
max_requests_per_second, max_concurrency, rate_limits,
user_agent and mailto from
:class:bibliofabric.config.BaseApiSettings and sets defaults of 0.5
requests per second (one request every 2 seconds) and concurrency 2, so
the client stays inside the API's budget of about 50 requests per minute
per IP address. The API needs no credentials; the data is United States
public domain.
Resources
Each resource inherits the generic operations from bibliofabric.Resource
(get, search, iterate, collect, first, count, exists,
batch_get). Only the members the client changes or adds are shown here.
bibliofabric.clinicaltrials.StudiesResource
Client for the /studies endpoints of ClinicalTrials.gov.
search(), iterate(), count(), collect(), first(),
and batch_get() read GET /studies; get() and exists()
read GET /studies/{nctId}. metadata(), search_areas(), and
enums() read the sibling metadata routes. query= maps to the
query.term basic search area; the other query.* and
filter.* parameters travel in :class:StudyFilters.
metadata(*, include_indexed_only: bool = False, include_historic_only: bool = False) -> list[FieldNode]
async
Return the study data model fields.
include_indexed_only adds fields that only answer searches, and
include_historic_only adds fields that only historic records
carry; both default to False upstream.
search_areas() -> list[SearchDocument]
async
Return the search documents and their search areas.
enums() -> list[EnumInfo]
async
Return the enumeration types of the data model and their values.
download_csv(dest: Path | str, *, filters: BaseModel | Mapping[str, Any] | None = None, query: str | None = None, sort: str | Sequence[str] | None = None, page_size: int | None = None, params: Mapping[str, Any] | None = None) -> Path
async
Download a search result as CSV, walking every page.
GET /studies?format=csv answers text/csv whose first page
starts with a header row and whose further pages carry an
x-next-page-token header; the method fetches page after page and
appends the rows until the header names no next token. With no
filters or query that is the whole registry, hundreds of megabytes.
fields does not apply: the CSV columns are a fixed set with
human names (NCT Number, Study Title, ...), not the JSON
field names. Search-only options work: filters, query,
sort, and extra params (for example
{"markupFormat": "legacy"} is ignored by the CSV columns but
accepted upstream).
Rows are written to a temporary file next to dest and moved into
place after the last page, so an interrupted download leaves no
partial file under the requested name.
bibliofabric.clinicaltrials.StatsResource
Statistics endpoints of the ClinicalTrials.gov API.
sizes() -> GzipStats
async
Return statistics of study JSON sizes.
field_values(*, fields: Sequence[str] | None = None, types: Sequence[str] | None = None) -> list[FieldValuesStats]
async
Return value statistics of leaf fields.
fields selects fields by piece name or field path (for example
"Phase" or
"protocolSection.designModule.phases"), types restricts the
answer to field types out of ENUM, STRING, DATE,
INTEGER, NUMBER, and BOOLEAN. Without arguments every
field's statistics come back.
field_sizes(*, fields: Sequence[str] | None = None) -> list[ListSizes]
async
Return size statistics of list fields.
fields selects fields by piece name or field path; without it
every list field's statistics come back.
Models
The record models users receive: Study (with its nested section and
module models under bibliofabric.clinicaltrials.models), FieldNode,
SearchDocument, EnumInfo, GzipStats, FieldValuesStats, ListSizes,
and Version. The study data model mirrors the upstream OpenAPI document,
including the typed DateStruct and PartialDateStruct structures.
Filters
bibliofabric.clinicaltrials.StudyFilters
Query and filter parameters of GET /studies.
filter.* and postFilter.* parameters have the same effect
upstream (neither affects ranking); both exist so callers can pass
through the parameters of a website search request unchanged.
geoDecay only applies together with filter.geo.