Category: Python

  • Companies House Stream API

    The Companies House streaming API gives you access to realtime data changes of the information held at Companies House. It pushes data changes to your client . You need API credentials to use Companies House Stream API.

    UPDATE: 10/06/2023 We look into persons with significant control API. To access streaming data using Python.

    End points

    Companies House Stream API provides the following:

    • Company Information – https://stream.companieshouse.gov.uk/companies
    • Filing history – https://stream.companieshouse.gov.uk/filings
    • Insolvency cases – https://stream.companieshouse.gov.uk/insolvency-cases
    • Charges – https://stream.companieshouse.gov.uk/charges
    • Officers – https://stream.companieshouse.gov.uk/officers
    • Persons with significant control – https://stream.companieshouse.gov.uk/persons-with-significant-control
    • Disqualified officers – https://stream.companieshouse.gov.uk/disqualified-officers
    • Company exemptions – https://stream.companieshouse.gov.uk/company-exemptions

    pscStream resource

    {
        "data": {
            "address": {
                "address_line_1": "string",
                "address_line_2": "string",
                "care_of": "string",
                "country": "string",
                "locality": "string",
                "po_box": "string",
                "postal_code": "string",
                "premises": "string",
                "region": "string"
            },
            "ceased": "boolean",
            "ceased_on": "date",
            "country_of_residence": "string",
            "date_of_birth": {
                "day": "integer",
                "month": "integer",
                "year": "integer"
            },
            "description": "string",
            "etag": "string",
            "identification": {
                "country_registered": "string",
                "legal_authority": "string",
                "legal_form": "string",
                "place_registered": "string",
                "registration_number": "string"
            },
            "is_sanctioned": "boolean",
            "kind": "string",
            "links": {
                "self": "string",
                "statement": "string"
            },
            "name": "string",
            "name_elements": {
                "forename": "string",
                "other_forenames": "string",
                "surname": "string",
                "title": "string"
            },
            "nationality": "string",
            "natures_of_control": [
                "string"
            ],
            "notified_on": "date",
            "principal_office_address": {
                "address_line_1": "string",
                "address_line_2": "string",
                "care_of": "string",
                "country": "string",
                "locality": "string",
                "po_box": "string",
                "postal_code": "string",
                "premises": "string",
                "region": "string"
            }
        },
        "event": {
            "fields_changed": [
                "string"
            ],
            "published_at": "date-time",
            "timepoint": "integer",
            "type": "string"
        },
        "resource_id": "string",
        "resource_kind": "string",
        "resource_uri": "string"
    }

    Code snippets

    import requests
    api_key = 'your stream api key'
    url = 'https://stream.companieshouse.gov.uk/filings'
    stream_timeout = 600   # time out ten mins just as example, no need if not wanted
    """
    begin streaming, can drop the timeout if not required, maybe use try: except: too
    """
    print('Streaming URL', url)
    r = requests.get(url, auth=(api_key, ''), stream=True, timeout=stream_timeout)
    print(r.status_code, r.headers)
    """
    check for good requests status (200 = ok) and process the stream
    """
    if r.status_code == 200:
        for json_line in r.iter_lines():     # stream should give a continuous iterable
            if json_line:
                print(json_line)
            else:
                print('Empty pulse')
    
    else:
        input('Not 200, best check what to do')
    Output from Companiies House Stream API
    Companies House Stream – filings
    Streaming URL https://stream.companieshouse.gov.uk/persons-with-significant-control
    200 {'Date': 'Sat, 10 Jun 2023 10:43:02 GMT', 'Content-Type': 'text/plain; charset=utf-8', 'Transfer-Encoding': 'chunked', 'Connection': 'keep-alive', 'Access-Control-Allow-Credentials': 'true', 'Access-Control-Allow-Headers': 'origin, content-type, content-length, user-agent, host, accept, authorization', 'Access-Control-Expose-Headers': 'Location, www-authenticate, cache-control, pragma, content-type, expires, last-modified', 'Access-Control-Max-Age': '3600', 'Server': 'nginx/1.14.2'}
    b'{"resource_kind":"company-psc-individual","resource_uri":"/company/14349975/persons-with-significant-control/individual/Bciqzh6CEWTbpA-hlVZjcmJFgiE","resource_id":"Bciqzh6CEWTbpA-hlVZjcmJFgiE","data":{"address":{"address_line_1":"Hillary Road","address_line_2":"Penenden Heath","country":"England","locality":"Maidstone","postal_code":"ME14 2JX","premises":"84"},"country_of_residence":"England","date_of_birth":{"month":8,"year":1993},"etag":"108363bbe861c6dd2434db8d39d524ca0551aee4","kind":"individual-person-with-significant-control","links":{"self":"/company/14349975/persons-with-significant-control/individual/Bciqzh6CEWTbpA-hlVZjcmJFgiE"},"name":"Mr Ehsan Hosseini","name_elements":{"forename":"Ehsan","surname":"Hosseini","title":"Mr"},"nationality":"British","natures_of_control":["ownership-of-shares-25-to-50-percent","voting-rights-50-to-75-percent","right-to-appoint-and-remove-directors"],"notified_on":"2022-09-11"},"event":{"timepoint":8123242,"published_at":"2023-06-10T11:43:01","type":"changed"}}'
    b'{"resource_kind":"company-psc-individual","resource_uri":"/company/14235641/persons-with-significant-control/individual/ThQ4_0TLwesMaFERku0Nm1Gonj8","resource_id":"ThQ4_0TLwesMaFERku0Nm1Gonj8","data":{"address":{"address_line_1":"Hillary Road","address_line_2":"Penenden Heath","country":"England","locality":"Maidstone","postal_code":"ME14 2JX","premises":"84"},"country_of_residence":"England","date_of_birth":{"month":8,"year":1993},"etag":"e8ed671a23a3d7f6f98d8dabba101c427a6a8744","kind":"individual-person-with-significant-control","links":{"self":"/company/14235641/persons-with-significant-control/individual/ThQ4_0TLwesMaFERku0Nm1Gonj8"},"name":"Mr Ehsan Hosseini","name_elements":{"forename":"Ehsan","surname":"Hosseini","title":"Mr"},"nationality":"British","natures_of_control":["ownership-of-shares-75-to-100-percent","voting-rights-75-to-100-percent","right-to-appoint-and-remove-directors"],"notified_on":"2022-07-14"},"event":{"timepoint":8123243,"published_at":"2023-06-10T11:43:01","type":"changed"}}'
    b'{"resource_kind":"company-psc-individual","resource_uri":"/company/14069614/persons-with-significant-control/individual/tnj0-jvgFsP6zLJJfxTm-PR_dTE","resource_id":"tnj0-jvgFsP6zLJJfxTm-PR_dTE","data":{"address":{"address_line_1":"New Tythe Street","address_line_2":"Long Eaton","country":"England","locality":"Nottingham","postal_code":"NG10 2DL","premises":"Unit C, 34-42"},"country_of_residence":"England","date_of_birth":{"month":1,"year":1983},"etag":"9c067321b307dc8742c131c8d7d7f50ccb713f17","kind":"individual-person-with-significant-control","links":{"self":"/company/14069614/persons-with-significant-control/individual/tnj0-jvgFsP6zLJJfxTm-PR_dTE"},"name":"Mr Ryan Craig Beales","name_elements":{"forename":"Ryan","surname":"Beales","title":"Mr"},"nationality":"British","natures_of_control":["ownership-of-shares-75-to-100-percent","voting-rights-75-to-100-percent","right-to-appoint-and-remove-directors"],"notified_on":"2022-04-26"},"event":{"timepoint":8123244,"published_at":"2023-06-10T11:43:01","type":"changed"}}'
    Empty pulse
    Empty pulse
    b'{"resource_kind":"company-psc-individual","resource_uri":"/company/14525916/persons-with-significant-control/individual/in5jEfX9W84hwv8uOE54_SwG3wM","resource_id":"in5jEfX9W84hwv8uOE54_SwG3wM","data":{"address":{"address_line_1":"Shelton Street","address_line_2":"Covent Garden","country":"United Kingdom","locality":"London","postal_code":"WC2H 9JQ","premises":"71-75"},"ceased_on":"2023-05-30","country_of_residence":"United Kingdom","date_of_birth":{"month":7,"year":1982},"etag":"c7682c26410071560eeddaec9f2d3f1f79caf965","kind":"individual-person-with-significant-control","links":{"self":"/company/14525916/persons-with-significant-control/individual/in5jEfX9W84hwv8uOE54_SwG3wM"},"name":"Riana Azam","name_elements":{"forename":"Riana","surname":"Azam"},"nationality":"British","natures_of_control":["ownership-of-shares-25-to-50-percent","voting-rights-25-to-50-percent"],"notified_on":"2022-12-06"},"event":{"timepoint":8123245,"published_at":"2023-06-10T11:44:03","type":"changed"}}'
    Empty pulse
    b'{"resource_kind":"company-psc-individual","resource_uri":"/company/10796018/persons-with-significant-control/individual/Gg8i7lYOHQFNzrqghawXCUqjc0I","resource_id":"Gg8i7lYOHQFNzrqghawXCUqjc0I","data":{"address":{"address_line_1":"Hawkchurch Road","country":"England","locality":"Reading","postal_code":"RG2 8NE","premises":"13"},"country_of_residence":"United Kingdom","date_of_birth":{"month":2,"year":1982},"etag":"23f852f2f4d9a8ae0147475c31033c14d36b8e67","kind":"individual-person-with-significant-control","links":{"self":"/company/10796018/persons-with-significant-control/individual/Gg8i7lYOHQFNzrqghawXCUqjc0I"},"name":"Mr Emmanuel Penn-Timity","name_elements":{"forename":"Emmanuel","surname":"Penn-Timity","title":"Mr"},"nationality":"British","natures_of_control":["ownership-of-shares-50-to-75-percent","voting-rights-50-to-75-percent"],"notified_on":"2017-05-31"},"event":{"timepoint":8123246,"published_at":"2023-06-10T11:45:02","type":"changed"}}'
    b'{"resource_kind":"company-psc-individual","resource_uri":"/company/10796018/persons-with-significant-control/individual/Gg8i7lYOHQFNzrqghawXCUqjc0I","resource_id":"Gg8i7lYOHQFNzrqghawXCUqjc0I","data":{"address":{"address_line_1":"Hawkchurch Road","country":"England","locality":"Reading","postal_code":"RG2 8NE","premises":"13"},"country_of_residence":"United Kingdom","date_of_birth":{"month":2,"year":1982},"etag":"23f852f2f4d9a8ae0147475c31033c14d36b8e67","kind":"individual-person-with-significant-control","links":{"self":"/company/10796018/persons-with-significant-control/individual/Gg8i7lYOHQFNzrqghawXCUqjc0I"},"name":"Mr Emmanuel Penn-Timity","name_elements":{"forename":"Emmanuel","surname":"Penn-Timity","title":"Mr"},"nationality":"British","natures_of_control":["ownership-of-shares-50-to-75-percent","voting-rights-50-to-75-percent"],"notified_on":"2017-05-31"},"event":{"timepoint":8123247,"published_at":"2023-06-10T11:45:02","type":"changed"}}'
    b'{"resource_kind":"company-psc-individual","resource_uri":"/company/SC772259/persons-with-significant-control/individual/yVFK_0mQOG3ZznL-4yRX9QLu_oQ","resource_id":"yVFK_0mQOG3ZznL-4yRX9QLu_oQ","data":{"address":{"address_line_1":"High Glencairn Street","country":"United Kingdom","locality":"Kilmarnock","postal_code":"KA1 4AE","premises":"33"},"country_of_residence":"United Kingdom","date_of_birth":{"month":11,"year":1997},"etag":"f78ab67914d30efc36a4a27cdd3d249d4bbaf14a","kind":"individual-person-with-significant-control","links":{"self":"/company/SC772259/persons-with-significant-control/individual/yVFK_0mQOG3ZznL-4yRX9QLu_oQ"},"name":"Mr Abhijeet Singh Bajwa","name_elements":{"forename":"Abhijeet","surname":"Bajwa","title":"Mr"},"nationality":"Italian","natures_of_control":["ownership-of-shares-75-to-100-percent","voting-rights-75-to-100-percent","right-to-appoint-and-remove-directors"],"notified_on":"2023-06-10"},"event":{"timepoint":8123248,"published_at":"2023-06-10T11:45:02","type":"changed"}}'
    Empty pulse