Repository that contains an up to date lookup of MPs, their constituencies, and their party affiliations.
This is a quick stop-gap, long term this will hopefully be made available from a database within DfE for analysts to access.
Full credit to @rmbielby for the logo involving our mascot Frederick!
The look up file is available as a CSV file you can view and download from the repository. There's a user guide available as a webpage, and a user guide as a downloadable PDF to assist you in getting what you need from the lookup file.
If you want to use this lookup programmatically (e.g. R or Python), you can use the raw URL:
https://raw.githubusercontent.com/dfe-analytical-services/mp-lookup/refs/heads/main/mp_lookup.csv
Though given the concatenated format of the location codes, we'd suggest anyone using code looks through R/data_update.R and the source packages. Particularly if you are wanting a location hierarchy, you should use the dfeR package directly.
All packages used in this repo are based on the latest versions available, currently there is no package management in place.
To install the packages needed to run the code in this repository, run the commands that are used in the .github/workflows/run_data_update.yaml file.
The MP data is sourced from the UK Parliament API and the Open Geography Portal using the following R packages:
The election results data is sourced from the 'candidate-level general election result data' CSV file from the UK Parliament election results page.
Lookup files and boundary information over time can be found on the Open Geography Portal.
dfeR also provides a number of curated lookups for DfE analysts using R, including a get_ons_api_data() API wrapper for programmatically accessing static files from the the Open Geography Portal.
If you need anything else from the Open Geography Portal, or a direct connection to the latest data look at using the boundr package.
Updates about MPs are done automatically every morning using GitHub Actions, these check for any changes in the MP data, and will overwrite the file with a newer version if there are.
Location updates will come through the dfeR package, as new boundaries are released on the Open Geography Portal. This lookup is currently intended as a latest view only, therefore legacy boundaries should only be kept for as long as they are needed e.g. currently 2024 codes are still widely in use across the DfE / systems haven't updated to 2025 codes, and therefore we don't have 2025 versions of the 3 digit LA codes yet, so we keep those legacy 2024 columns until we have 2025 versions of the 3 digit codes, after that point those columns should be removed and only the latest codes kept.
Election results data is updated manually from the Parliament website.
The documentation is maintained in this README (largely aimed at maintainers) and user-guide.qmd (aimed at end users).
The user guide is kept as both a pdf and html version, with the html version being published to GitHub pages via an automated workflow.
If a manual deploy of the user guide to GitHub pages is ever required, this can be done using the following command in the Bash terminal:
quarto publish gh-pages user-guide.qmd
Updating the pdf is performed manually using the command:
quarto::quarto_render(
"user-guide.qmd",
output_format = "pdf",
metadata = list(
papersize = "A4",
format = list(
pdf = list(
toc = TRUE,
`number-sections` = TRUE,
mainfont = "Arial"
)
)
)
)
If you have any questions, or requests for additional data or changes to the existing data, please raise an issue on this repository.
