Skip to content

Upstream quirks

Behavior of the live MeSH RDF API that shapes how the client works, with the SPARQL and URI requests page and the Swagger document at https://id.nlm.nih.gov/mesh/swagger/swagger.json as the references. Where a quirk affects bibliofabric.mesh, the behavior of the client is noted.

Missing ids answer HTTP 200 with an empty document

The /{id}.json record route answers 200 with the JSON-LD document { } for an id that carries no data in the queried graph (an unknown id, or a retired qualifier such as Q000006). The same empty answer comes back for a well-formed id that no longer exists, and HEAD cannot decide existence because it also answers 200. bibliofabric.mesh raises NotFoundError for an empty document, and records.exists() probes with one GET.

SPARQL subjects carry versioned graph URIs

The endpoint stores one graph per MeSH year, and the resource URIs of the yearly graphs carry the year as a path segment (http://id.nlm.nih.gov/mesh/2015/D018021). A SELECT over ?d a vocab#TopicalDescriptor matches the descriptor in every yearly graph, so the first rows come back with 2015 URIs even when the request sends year=current (verified live; the parameter does not prune the class matches). Filter or strip the year segment to reach the current record: records.get() and the lookup descriptor parameters accept the bare id, which always resolves to the current vocabulary. To keep only the current copy in SPARQL, filter the subject: FILTER(REGEX(STR(?d), '^http://id.nlm.nih.gov/mesh/[A-Z]')) (a STRSTARTS prefix check alone also matches every yearly graph).

Record routes serve RDF serializations, not plain JSON

mesh/D000001.json answers application/rdf+json: a JSON-LD document with @id, @type, @context, and one key per RDF predicate, whose values mix plain strings, booleans, {"@language": ..., "@value": ...} literals, and lists of resource URIs. @type names the vocabulary class (vocab#TopicalDescriptor, vocab#Qualifier, vocab#Term, vocab#SCR_Chemical). bibliofabric.mesh models @id, @type, identifier, and label/prefLabel and keeps every other predicate through extra="allow"; read record.label_text for the label of any record family (term records carry prefLabel instead of label).

Lookup route names differ from older documentation

/lookup/qualifier and /lookup/synonym do not exist; both answer the site's HTML 404 page with status 404. The live routes are /lookup/qualifiers (allowed qualifiers of one descriptor) and, for synonyms, the /lookup/term entry-term search. Four more lookup routes exist beyond the label searches: /lookup/pair, /lookup/details, /lookup/years, and /lookup/label. bibliofabric.mesh wraps exactly the routes the Swagger document lists.

Lookup answers

Observation Behavior
Empty result 200 with []; the client returns an empty list.
match exact (default), contains, startswith; the label match is case-insensitive.
limit 1 to 50; a larger value answers 400 with {"error": {"limit": ["must be less than or equal to 50"]}}. bibliofabric.mesh rejects values outside 1 to 50 before sending.
Missing required parameter 400 with {"error": {"resource": ["must not be empty"]}}.
descriptor parameter Accepts the bare id and the full URI, and answers the same hits for both; bibliofabric.mesh sends the full URI.
Pair hits The resource id joins both ids (D001249Q000188) and the label joins both labels (Asthma/drug therapy).
year on /lookup/descriptor current (default), 2026, 2025, 2024; client.lookup.years() reads the live list.

SPARQL endpoint limits

Observation Behavior
SELECT rows At most 1000 per request (limit parameter, default 1000); page further rows with offset. bibliofabric.mesh rejects a limit outside 1 to 1000 and walks offset in sparql.iterate().
Malformed query 500 with a plain-text parser message, not 400; it raises APIError.
Format selection The format parameter (not the Accept header) decides the representation; the client sends both, with a matching Accept value. format=HTML answers an error; only the browser query editor accepts it.
ASK queries Answer {"head": ..., "boolean": true}; sparql.query() parses both answer shapes.
CONSTRUCT queries Answer at most 10,000 triples and ignore limit; read them through sparql.query_text().

Records and rate limits

The API updates nightly; a record can change between one day and the next. The acceptable use policy caps the SPARQL endpoint at 500 requests per minute per IP address and pauses service to an address for 30 seconds once the client exceeds the cap; bibliofabric.mesh defaults to 2 requests per second, well under the cap.

The service sometimes answers empty or drops the connection

Under repeated identical requests the service intermittently answers HTTP 200 with a zero-byte body, truncates the connection, or serves a partial answer (observed once on /lookup/details: valid JSON with empty terms and qualifiers lists). A zero-byte body raises APIError; a truncated connection raises NetworkError after the configured max_retries. Rerun the call; a repeat usually answers with the full data.