Skip to main content

companies-house-codegen

PyPI Version mkdocs ruff mypy

A simple but powerful toolkit for downloading, compressing and formatting Companies House OpenAPI (Swagger 2.0) specifications.

Introduction

Companies House is an executive agency of the Department for Business and Trade, a department of the British Government. This official UK agency is responsible for incorperating and dissolving companies, and maintaining a register of information of limited companies (and some other companies) under the Companies Act and related legislation to be made available for public access.

Companies House hosts a JSON REST API called the Companies House API, which makes it possible for software developers to create application to retrieve information from Companies House's database (e.g. searching and retrieving public company data), as well as, interact with Companies House's database (e.g. manipulating company information, givem you have authority to do so). The full documentation for Companies House API can be found at the Companies House Developer Hub.

Unfortunately, the Companies House API does not come with an official SDK. Fortunately, the API is documented fully defined in OpenAPI (specifically Swagger 2.0) specifications - an open source standard for defining APIs. Since OpenAPI is industry standard there are many tools that exist that produce high quality SDKs from OpenAPI definitions. For example, Cloudflare, OpenAI, Anthropic and many define their SDKs in OpenAPI3 and generate them using Stainless. Unfortunately, these definitions are distributed amongst many files (i.e. the API is broken down into several smaller API products, with the Companies House Public Data API product by itself being distributed over 22 files!). Moreover, these definitions contain various errors that make them unusable.

This small, configurable and simple tool fetches the OpenAPI for Companies House API, formats them to fix errors found in them.

Getting Started

Requirements

companies-house-codegen requires Python 3.8+ and typing-extensions. You may also, optionally, install pydantic for additional typesafety.

Installation

pip is the default package installer for Python, enabling easy installation and management of packages from the Python Package Index (PyPI) and from Version Control System (VCS) sources via the command line.

[!TIP] The methods described work for other package manegers like uv and poetry

Install From PyPI

To this package from PyPI, run:

pip install companies-house-codegen

Install From Github (Using VCS Support)

To install from latest version of this Github repo use:

pip install git+https://github.com/MMurape/companies-house-codegen.git@main

[!TIP] See pip's documentation VCS Support for more infomation. Note, that most modern package managers also come with VCS support similar to pip.

Install From A Git Clone (Using a clone of this repo)

To install this repository from a git clone, perform the following steps:

  1. Clone this repository.

  2. After clone this repository, the run the following command:

    cd companies-house-codegen # change directory to this repository
    
  3. Install the package using package manager of your choice:

    pip install .
    

Usage

This toolkit can either be used as a command-line interface - companies-house-codegen - or as a python module - companies_house_codegen.

For more information on command-line interface see: API Reference.

For more information on command-line interface see: CLI Reference.

Example: Download Companies House Public Data API and convert it to OpenAPI 3.0.1

As a simple example of usage, here is how you could download the OpenAPI (Swagger 2.0) specification for Companies House Public Data API and convert it to OpenAPI 3.0.1.

Using the CLI

# Download Companies House Public Data API and convert it to OpenAPI 3.0.1
companies-house-codegen -i https://developer-specs.company-information.service.gov.uk/api.ch.gov.uk-specifications/swagger-2.0/spec/swagger.json --zip public_data_api_openapi.yml --openapi

Using the library

from companies_house_codegen.codegen import download_openapi
from companies_house_codegen.utils import mapping_representer
import yaml
from yaml import CDumper

public_data_api_openapi = download_openapi('https://developer-specs.company-information.service.gov.uk/api.ch.gov.uk-specifications/swagger-2.0/spec/swagger.json')
with open('public_data_api_openapi.yml', 'w') as f:
    # yaml does not know how to dump special an Mappings like OrderedDict.
    CDumper.add_representer(OrderedDict, mapping_representer)
    yaml.dump(m, f, indent=2, sort_keys=False, Dumper=CDumper) # save yaml

Metadata

Release files for companies-house-codegen 0.2.1

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for companies-house-codegen 0.2.1
File Size Uploaded
companies_house_codegen-0.2.1.tar.gz 112.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for companies-house-codegen 0.2.1
File Interpreter ABI Platform
companies_house_codegen-0.2.1-py3-none-any.whl Python 3 none any Details

Total release size: 139.3 kB

Release files / companies_house_codegen-0.2.1.tar.gz

Download URL companies_house_codegen-0.2.1.tar.gz
Size 112.9 kB
Tags Source
SHA-256 checksum
How to use checksums
bb4e04feb1b38639c9fee7d6f4eed8c28edbb2e5197688bcc6994c0463f54934
BLAKE2b-256 checksum
How to use checksums
9eb7d2143524395df386560c6d908e36569d24739fb280ca1275199bf308118c
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.7.17

Release files / companies_house_codegen-0.2.1-py3-none-any.whl

Download URL companies_house_codegen-0.2.1-py3-none-any.whl
Size 26.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
87c74c3649bd514b7588a593038d613f1799aac4c7dc54191c91677520bb1fbd
BLAKE2b-256 checksum
How to use checksums
72a39b9b12f1c52d1bb6bda9d718344b6c5a82c5c60aaca2c5aeb6c37dbfa920
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
Yes
Uploaded via uv/0.7.17

Release history Release notifications | RSS feed

This release

0.2.1 This release

2 release files

0.2.0

2 release files

0.1.2

2 release files

0.1.1

2 release files

0.1.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page