| name | parameterised-query |
| description | Use the UK Parliament parameterised query browser (api.parliament.uk/query/) — a catalogue of pre-canned SPARQL queries that return JSON without you having to write the SPARQL yourself. Each template has a fixed name and a fixed parameter signature, e.g. person_by_id?person_id=… or constituency_lookup_by_postcode?postcode=…. Use when you want a specific, pre-vetted answer about a Parliament resource and do not want to author SPARQL. |
| license | Open Parliament Licence v3.0 (Crown copyright; Parliament-operated) |
| metadata | {"provenance":{"tier":1,"operator":"UK Parliament","service":"api.parliament.uk/query","citation-short":"via api.parliament.uk/query","citation-formal":"UK Parliament parameterised-query browser, retrieved {date}","confidence":"authoritative"}} |
UK Parliament parameterised query browser
Endpoint: https://api.parliament.uk/query/
This is the public face of an internal Parliament service that wraps
common SPARQL questions as named, parameterised templates. It is
read-only and HTTP-GET-only. The root path returns a list of every
template; calling a template with the right query-string parameters
runs the underlying query and returns JSON (or HTML in the browser).
What it covers
124 named templates as of 2026-04-30 (see
_specs/discovered/query-templates.txt).
Examples (the full list is the file above):
person_index — every person URI in the store.
person_by_id?person_id=TyNGhslR
person_by_initial?initial=A
person_by_substring?substring=ee
person_lookup?property=mnisId&value=3299
person_constituencies?person_id=TyNGhslR
person_current_constituency?person_id=TyNGhslR
person_committees_memberships_index?person_id=TyNGhslR
person_mps
member_current
constituency_lookup?property=onsCode&value=E14000699
constituency_lookup_by_postcode?postcode=SW1P%203JA
constituency_current_member?constituency_id=AEyWGYaP
find_your_constituency — useful pre-canned postcode → MP lookup.
party_index
Common entry points
| Use case | Template |
|---|
| Postcode → constituency → current MP | constituency_lookup_by_postcode?postcode=... |
| ONS code → constituency | constituency_lookup?property=onsCode&value=E14000699 |
| MNIS ID → person URI | person_lookup?property=mnisId&value=3299 |
| All current MPs | person_mps or member_current |
| Person → committees they have been on | person_committees_memberships_index?person_id=... |
Worked example
curl -s 'https://api.parliament.uk/query/constituency_lookup_by_postcode?postcode=SW1P%203JA' \
| jq '.[0]'
Relationship to the sparql skill
api.parliament.uk/query is a named-query layer over the same DDP
store that api.parliament.uk/sparql exposes directly. Same graph,
same URIs, same coverage:
- Anything the templates can answer, you can also answer in SPARQL.
- Anything the SPARQL endpoint can't answer (Bills, Hansard
contributions, divisions, RMFI, elections, EDMs, Erskine May, APPGs —
see
sparql/SKILL.md)
the templates also can't, because the underlying data isn't there.
Pick this skill when there's a named template that fits the question;
drop down to sparql for arbitrary joins, schema discovery, classes
outside the templated set, or any of the ~194 classes in the parl:
schema that don't have a pre-canned template.
The IDs are the same opaque 8-character id.parliament.uk shortIds
as in the SPARQL store and as in some REST APIs (treaties, e-petitions),
so results from one skill compose directly with the others.
Notes
- Each template returns JSON when called with the standard
Accept:
default. The HTML browser lets you click through to inspect.
- Templates are stable but the canonical record of the set is the
service itself; we cache the list under
_specs/discovered/query-templates.txt and a re-fetch is captured
by scripts/probe-endpoints.sh (extension TODO — currently we only
record the count and the root URL).
Using the CLI
See ../parl/SKILL.md for the CLI-wide conventions (output modes, flag rules, idiomatic chains).
This skill ships with a Node CLI alongside the documentation. From the
repo root:
node bin/parl.mjs pq --help
Or after npm link (one-time install):
parl pq --help
Wraps the parameterised-query browser. 124 named templates returning JSON; covers the most common joins without writing SPARQL.
Examples
parl pq postcode "SW1P 3JA"
Postcode → constituency → current MP.
parl pq mps
All current MPs.
parl pq person-by-mnis 4514
Person by MNIS ID.
parl pq run constituency_lookup --property=onsCode --value=E14000647
Arbitrary template invocation.
Library use (Node + browser)
Same surface as a JS module:
import * as fac from '../../lib/facilities/parameterised-query.mjs';
The library uses only fetch / URL / AbortController, so the
same source runs in Node 18+ and in modern browsers.
Provenance to cite
Tier 1 — first-party UK Parliament. Authoritative.
- Inline cite: "(via api.parliament.uk/query)" — once per paragraph in
user-facing answers.
- On request, give the URL
--raw printed.
- See
docs/provenance.md for the
cross-skill rules.