Skip to content
Steve Peters edited this page Dec 31, 2020 · 7 revisions

Hello, and welcome

You've found some notes on my personal experiments and prototypes developed using OpenData and APIs from the UK Parliament site.

I've started by building a new 'Know Your Member (KYM) ' prototype.

I'm not trying here to compete with other excellent tools that help us explore and understand the work of our UK Parliament. For example, TheyWorkForYou.com does a brilliant job helping the lay person to find out about Parliament's work of and people.

I'm no professional programmer (more an armchair enthusiast) and liken my code to my waistline: bloated but functional. Look at my scripts, and you'll quickly see they aren't especially elegant, don't employ the latest methods and techniques (I'm still learning!) and certainly wouldn't pass the production-ready/standards and best practices compliance sniff tests. My motivation is to quickly build tools which help me:

  • better understand how others have developed, documented and published good quality open APIs to serve timely reliable data.
  • as a democracy and open data fan, see what I could do to build some (hopefully) useful insights from these rich resources.

I hope this provides some useful tips and insights for you too. Thanks for reading.

KYM design and data sources

My main idea for the KYM prototype was to pull together - on a single page - multiple facts about individual members of the house of commons, and house of lords. You'll see I've chosen to focus on:

  • the individual's registered interests
  • does the individual currently sit on any Commons or Lords Committees?
  • What questions has the person asked (in writing, and orally) in the Commons or Lords?
  • The individual's current or previous Government, Opposition and Parliamentary roles

To get there, I needed to figure out how to discover and interact with the various APIs serving the underlying data, and technical challenges around blending and combining this information into useful intelligence.

Before outlining what I've found and done, I wanted to say a big thank you to the UK Parliament data team for their excellent work in making significant and important data openly accessible and re-usable. I've generally found the APIs to be very well documented, with nice features to check and test my requests for data before implementing them in my code. There is nice documentation on the underlying data models too.

Parliament UK APIs - what I've found and done

I think I've found 3 complimentary high-level APIs, each providing ways to query and retrieve UK Parliament's data sources.

  1. Members' Names Data Platform - defined as "A set of services to gain access to Members' information via a RESTful API that returns an XML or JSON dataset".
  2. The Developer hub - defined as "Resources for developers, including a directory of open data APIs which allow Parliamentary data to be shared publicly"; and
  3. data.parliament.uk - appears to provide tailored views in to Linked data published via the UK Parliament Sparql endpoint.

To get going quickly, I've mainly used the Member query engine API, which I found provides powerful and convenient methods to return multiple facts about people (MPs and Lords) in a single request.

However, I am more excited by the Linked data offering. As the name suggests, it offers the potential to directly join and combine facts published by Parliament UK about say a parliamentary constituency, with other facts about the same constituency published elsewhere by third parties.

For instance, imagine a world where I could write one query which blends official statistics from ONS and MHCLG about Housing in Parliamentary Constituencies, with questions asked about Housing by MPs for these constituencies. That's one query, using the internet to blend on-demand three separate sources published in three separate data services, with each service providing data to common standards. Yes, this is still probably some way off...but no harm in dreaming, and hats off to the UK Parliament Data people for their work on their Linked Data endpoint. More experiments to follow.

Using the member query engine - some examples

I'm a Javascript 'kiddie' and regular user of the brilliant JQuery libraries, with a preference for working with data in JSON.

My general approach is to use JQuery AJAX requests to retrieve data, as per this working JSFiddle example.

Note this example pulls data from Parliament UK's 'Parties' reference data source. when using the query engine API, I can retrieve multiple facts about MPs or Lords in one pass. For instance, replace the URL in the example with:

https://data.parliament.uk/membersdataplatform/services/mnis/members/query/House=Commons%7CIsEligible=true/ParliamentaryPosts%7CGovernmentPosts%7COppositionPosts/

This will retrieve a full list of all current MPs, with additional data on their current and previous roles in Parliamentary, Government and/or Opposition posts. For further information about how to query the API for multiple datasets, please see the outputs documentation.