The .gov website hosts companies house and the companies house API. This is a comprehensive list of businesses across the UK, new and old, big and small, and their filings and info. You can interact with this information via code such as Python.

The following blog post series will show you how to perform an advanced search of companies – using multiple different filters to get specific businesses – and then looping through these results to get the company profile and details. This approach will produce a list of companies which may be useful business leads, or even competitors. This will be minimal info such as business name, address and size approximation but can be expanded on to include location, distance, company score and more.

Prerequisites

API Key

You will need an API key to authenticate your requests. This can be found in your .gov One Login account that you set up for use of the .gov website. To do so, go here: Create your GOV.UK One Login or sign in – GOV.UK One Login

Once signed up/signed in, move to the developer pages(Application overview) for companies house to set up an application. This is not external so can be named however you wish but it must be a live application. Once created, click into the application and copy the value for ‘API Key’.

Necessary Libraries:

Pandas: this is to effectively store the results of the API. This needs to be in your environment before importing – this may be Fabric notebooks, Jupyter Notebooks, Visual Studio etc. If not already done, you will need to search how to do this unique to whether you are using any of the above – i.e. ‘How to install Pandas in Python for Visual Studio Code’

Requests: powerful tool for making HTTP requests in Python. This will be used for the get requests of the API

datetime: permits the use of datetime data types and used for comparing dates, moving forward and backwards in time and getting todays date. This may be useful in understanding filing history and recency to determine a company score.

Optional libraries:

Math: used for calculations and math functions – only necessary if you wish to calculate distances to companies

Re: for working with regular expressions (regex), which are patterns used to match and manipulate strings. Further to the above, if considering calculating distances to businesses, this can be applied to post codes, which vary in structure.

API Limitations

Call rate: you can only trigger up to 600 requests in a 5 minute period but this is only a problem if getting the company profiles and details as you may need to loop through a list of 1000+ companies – however, this is quite easily overcome but prolongs any code runtime.

Filings and accounts: you can get the PDF filings from the API but the complexity increases from here to be able to interrogate the resulting PDFs via code.

 

The Code

The code will follow the structure below:

  • Import libraries
  • Set up key variables, values, filters
  • Get list of companies using advanced search API
  • Loop through these companies to get more detail
  • Save the results to a dataset
  • Export this to a CSV

 

See Part 2 for more!

Tags: , ,