SDKs overview

Software Development Kits (SDKs) and libraries for Data.parliament.uk are designed to streamline the process of accessing and manipulating the public data provided by the UK Parliament. These tools abstract the underlying RESTful API interactions and data formats, such as RDF and JSON, allowing developers to focus on application logic rather than low-level data retrieval. The Data.parliament.uk documentation portal provides comprehensive guides on the API's structure and data models, which are particularly relevant for understanding the linked data principles employed.

While Data.parliament.uk is primarily a data provider, its official SDKs aim to reduce the boilerplate code typically required to consume web APIs. This includes handling authentication (where applicable, though Data.parliament.uk's primary API is open access), request formatting, response parsing, and error management. Community-contributed libraries further extend this ecosystem, offering support for additional programming languages and specialized use cases.

Official SDKs by language

Data.parliament.uk provides official SDKs to facilitate access to its parliamentary data, focusing on commonly used programming languages for data analysis and web development. These SDKs are maintained to ensure compatibility with the Data.parliament.uk API reference and data formats.

The official SDKs include:

  • Python Library: Designed for data scientists, researchers, and developers working with Python. It simplifies interaction with the API, allowing for programmatic queries and data retrieval for legislative, historical, and biographical information related to the UK Parliament. The official Python SDK documentation provides usage examples and API specifics.
  • .NET Library: Aimed at developers building applications within the Microsoft .NET ecosystem. This SDK provides a structured way to access parliamentary data, compatible with C# and other .NET languages. Further details on its capabilities are available in the official .NET SDK guide.

The following table summarizes the key details for the official SDKs:

Language Package Name Install Command Maturity
Python parliament-data pip install parliament-data Stable
.NET (C#) ParliamentData.Sdk dotnet add package ParliamentData.Sdk Stable

Installation

Installing Data.parliament.uk SDKs typically involves using standard package managers for the respective programming languages. Detailed instructions for each SDK are provided in the official documentation.

Python SDK Installation

To install the official Python SDK, use pip, Python's package installer. This command retrieves the latest version from the Python Package Index (PyPI).

pip install parliament-data

After installation, you can verify it by importing the library in a Python environment and checking its version or attempting a simple API call, as illustrated in the Python SDK quickstart guide.

.NET SDK Installation

For the .NET SDK, use the .NET CLI (Command-Line Interface) to add the package to your project. This command fetches the package from NuGet, the package manager for .NET.

dotnet add package ParliamentData.Sdk

Once installed, you can integrate the library into your C# or other .NET language projects by adding a using directive and instantiating the client classes. Refer to the .NET SDK examples for more specific usage patterns.

Quickstart example

This Python quickstart example demonstrates how to use the parliament-data SDK to retrieve information about Members of Parliament (MPs). It covers initializing the client and making a basic query to fetch data, demonstrating the abstraction provided by the SDK over direct HTTP requests to the Data.parliament.uk API.


from parliament_data import ParliamentDataClient

# Initialize the client
client = ParliamentDataClient()

# Get a list of current Members of Parliament
# The API call is handled by the SDK, returning parsed data
try:
    mps = client.get_members_of_parliament(current_only=True)
    print(f"Found {len(mps)} current Members of Parliament.")

    # Print details for the first 5 MPs as an example
    for i, mp in enumerate(mps[:5]):
        print(f"\nMP {i + 1}:")
        print(f"  Name: {mp.name}")
        print(f"  Party: {mp.party}")
        print(f"  Constituency: {mp.constituency}")
        print(f"  Member ID: {mp.member_id}")

except Exception as e:
    print(f"An error occurred: {e}")

This code snippet initializes the ParliamentDataClient and then calls the get_members_of_parliament method. The current_only=True parameter filters for active MPs. The SDK handles the API request, data parsing (from JSON or RDF depending on the endpoint and configuration), and returns a list of MP objects, each with attributes like name, party, and constituency. This simplifies data access compared to manually constructing URLs and parsing raw API responses.

Community libraries

Beyond the officially supported SDKs, the Data.parliament.uk ecosystem is augmented by various community-contributed libraries and tools. These resources often extend language support or provide specialized functions that cater to niche requirements not covered by the official offerings. While Data.parliament.uk does not directly maintain these, they can be valuable for developers seeking alternative approaches or additional capabilities.

Examples of community contributions often include:

  • R Packages: Developers in the R statistical environment may create packages for direct interaction with Data.parliament.uk, facilitating data ingestion into R for statistical analysis and visualization.
  • JavaScript/TypeScript Clients: For front-end or Node.js applications, community libraries might offer client-side abstractions or wrappers for specific API endpoints.
  • Data Connectors: Tools that integrate Data.parliament.uk with other platforms or databases, such as tools utilizing W3C Semantic Web standards for linked data, may also emerge from the community.

Developers interested in community libraries are encouraged to search public code repositories like GitHub or consult developer forums and communities focused on open government data. It is advisable to review the documentation and maintenance status of any third-party library before integrating it into production systems, as community projects may vary in their support and update frequency compared to official SDKs.

For discovering new and existing community-contributed tools, searching on platforms like GitHub for keywords such as data.parliament.uk, parliamentary data API, or UK Parliament SDK can yield relevant results. The Data.parliament.uk developer documentation sometimes features links to notable community projects, or provides guidelines for contributing your own.