SDKs overview

Software Development Kits (SDKs) and libraries for the UK Companies House API streamline the process of integrating company data into various applications. These tools provide pre-built functions and classes that encapsulate the complexities of making HTTP requests, handling authentication, and parsing JSON responses from the Companies House API specification. By using an SDK, developers can interact with the API using familiar programming language constructs, reducing development time and potential errors compared to constructing raw API calls.

The Companies House API provides extensive public data on UK companies, including company profiles, filing history, officer details, and insolvency information. The official SDKs are designed to facilitate access to these datasets, supporting common operations such as searching for companies, retrieving detailed company information, and monitoring changes in company filings. These SDKs typically manage API key authentication, which is a standard method for securing access to the OAuth 2.0-protected resources provided by Companies House.

The availability of SDKs across multiple programming languages ensures that a broad range of development environments can connect to the Companies House data. This includes popular server-side languages often used for backend services and data processing. The SDKs aim to provide a consistent interface across different languages, abstracting away the underlying RESTful API interactions. This consistency helps developers who work across polyglot environments or who need to maintain applications written in different languages that consume Companies House data.

Official SDKs by language

Companies House provides official SDKs for several popular programming languages, designed to offer a direct and supported method for interacting with their API. These SDKs are maintained to reflect the current API version and ensure compatibility with the services offered. Each SDK typically includes modules for authentication, data retrieval, and error handling, tailored to the conventions of its respective language.

The official SDKs are developed to follow the Companies House API documentation standards, providing a reliable foundation for building applications. They are generally the recommended approach for new integrations due to their direct support from Companies House and adherence to API best practices. Developers can expect comprehensive functionality covering the core API endpoints for company search, profile retrieval, and other data services.

Language Package/Module Name Install Command (Example) Maturity
Python companies-house-api-python pip install companies-house-api-python Stable
Java uk.gov.companieshouse.api-sdk-java Maven: <dependency>...</dependency> Stable
Ruby companies_house_api gem install companies_house_api Stable
PHP companieshouse/api-client composer require companieshouse/api-client Stable
Node.js @companieshouse/api-sdk-node npm install @companieshouse/api-sdk-node Stable

For each language, the SDK typically handles the necessary HTTP requests, serializes request bodies, and deserializes response data, abstracting these details from the application logic. This allows developers to focus on how to use the company data rather than the mechanics of API communication. The official SDKs are usually versioned to align with API changes, ensuring that applications remain functional as the API evolves. Developers should consult the official Companies House developer specifications for specific versioning details and update procedures.

Installation

Installing a Companies House SDK typically follows the standard package management practices for each programming language. The process involves using a command-line tool to fetch and install the library from a public repository. For example, Python developers use pip, Java developers use Maven or Gradle, Ruby developers use gem, PHP developers use Composer, and Node.js developers use npm or yarn.

Python

To install the Python SDK, use pip:

pip install companies-house-api-python

This command retrieves the latest stable version of the Python SDK from the Python Package Index (PyPI) and installs it into your Python environment. Ensure you are using a virtual environment to manage dependencies effectively for your project.

Java

For Java projects, you typically add the SDK as a dependency in your pom.xml (Maven) or build.gradle (Gradle) file. For Maven, add:

<dependency>
    <groupId>uk.gov.companieshouse</groupId>
    <artifactId>api-sdk-java</artifactId>
    <version>[LATEST_VERSION]</version>
</dependency>

Replace [LATEST_VERSION] with the current version specified in the Companies House Java SDK documentation. After adding the dependency, your build tool will download the necessary JAR files.

Ruby

Install the Ruby gem:

gem install companies_house_api

This command adds the companies_house_api gem to your Ruby environment, making it available for use in your Ruby applications. You can then require it in your Ruby scripts.

PHP

For PHP projects, use Composer:

composer require companieshouse/api-client

Composer will add the companieshouse/api-client package to your project's vendor/ directory and update your composer.json and composer.lock files. Ensure Composer is installed on your system.

Node.js

Install the Node.js SDK using npm:

npm install @companieshouse/api-sdk-node

This command installs the Node.js package into your project's node_modules directory and adds it to your package.json dependencies. You can then import the modules into your JavaScript or TypeScript files.

After installation, the next step is to configure the SDK with your API key. This key is obtained from the Companies House developer portal and is essential for authenticating your requests to the API.

Quickstart example

This Python example demonstrates how to use the official Companies House Python SDK to retrieve a company profile. This quickstart assumes you have installed the companies-house-api-python package and have a valid API key.

from companies_house.api import CompaniesHouseAPI

# Replace with your actual API key obtained from Companies House
API_KEY = "YOUR_API_KEY"

# Initialize the API client
ch_api = CompaniesHouseAPI(api_key=API_KEY)

# Define the company number you want to retrieve
company_number = "00000006"  # Example: 'The Royal Bank of Scotland plc'

try:
    # Retrieve the company profile
    company_profile = ch_api.get_company_profile(company_number)

    # Print some key details from the profile
    print(f"Company Name: {company_profile['company_name']}")
    print(f"Company Status: {company_profile['company_status']}")
    print(f"Registered Office Address: {company_profile['registered_office_address']['address_line_1']}, "
          f"{company_profile['registered_office_address']['locality']}, "
          f"{company_profile['registered_office_address']['postal_code']}")
    print(f"Date of Creation: {company_profile['date_of_creation']}")

except Exception as e:
    print(f"An error occurred: {e}")
    # More detailed error handling would be implemented here

This example demonstrates the basic workflow:

  1. Import the necessary class: CompaniesHouseAPI from the installed SDK.
  2. Initialize the API client: Pass your API key during instantiation. This key authenticates your requests.
  3. Call an API method: Use ch_api.get_company_profile() with the target company number. The SDK handles the underlying HTTP GET request to the Companies House Company Profile API endpoint.
  4. Process the response: The method returns a Python dictionary (or similar data structure) containing the parsed JSON response from the API. You can then access specific fields like company_name or company_status.
  5. Error Handling: A basic try-except block is included to catch potential API errors or network issues. In a production application, more granular error handling would be essential, potentially checking HTTP status codes or specific error messages from the API.

Similar quickstart patterns apply to other languages, where you would import the respective SDK class, initialize it with your API key, and call the appropriate methods to interact with different Companies House API endpoints, such as searching for companies or retrieving filing history details. The core principle remains consistent: the SDK abstracts the HTTP communication, allowing developers to work with native language objects.

Community libraries

Beyond the official SDKs, the developer community has created various libraries and wrappers for the Companies House API. These community-driven projects often emerge to fill gaps, provide alternative implementations, or offer specialized features not present in the official SDKs. They can range from simple HTTP clients with built-in API key handling to more comprehensive frameworks that integrate with specific application architectures or provide higher-level abstractions.

Community libraries are typically found on package repositories like PyPI for Python, npm for Node.js, or GitHub. Before adopting a community library, it is advisable to assess its maintenance status, community support, and alignment with the latest Companies House API versions and guidelines. Factors to consider include:

  • Active Maintenance: Is the library regularly updated to address bugs and new API features?
  • Documentation: Is there clear and comprehensive documentation for usage and configuration?
  • Test Coverage: Does the project have a robust suite of tests to ensure reliability?
  • Community Support: Is there an active community or maintainer available to answer questions or provide assistance?
  • License: What open-source license is the library distributed under, and does it align with your project's requirements?

While official SDKs offer direct support and guaranteed compatibility from Companies House, community libraries can sometimes provide innovative solutions or cater to niche requirements. For example, a community library might offer a more opinionated ORM-like interface for company data, integrate with a specific web framework, or provide enhanced data caching mechanisms. Developers often evaluate both official and community options to determine the best fit for their project's technical stack and development preferences. One example of a widely used approach for integrating with various APIs, including those like Companies House, is through general-purpose HTTP client libraries, such as requests in Python or axios in JavaScript, which form the basis for many community wrappers. These tools provide the fundamental capabilities for making web requests, upon which more specific API client logic can be built, as detailed in general HTTP protocol specifications.

It's important to note that community libraries are not officially supported by Companies House, meaning that any issues or questions related to their use would need to be directed to the library's maintainers rather than Companies House support channels. Therefore, due diligence is crucial when selecting a community-contributed solution for production environments.