SDKs overview

OpenCorporates offers programmatic access to its extensive database of company information through a RESTful API. To facilitate integration for developers, a range of Software Development Kits (SDKs) and client libraries are available. These tools are designed to simplify tasks such as constructing API requests, handling authentication, and parsing the JSON responses from the OpenCorporates API OpenCorporates API documentation. Developers can use these SDKs to retrieve data on companies, officers, and filings for various applications, including due diligence, supply chain analysis, and investigative journalism.

While OpenCorporates itself does not provide a large suite of officially maintained SDKs, the API's design, which adheres to common web standards, allows for straightforward interaction using generic HTTP client libraries available in most programming languages. This approach, where the API is the primary interface and client libraries are often community-driven or built ad-hoc, is common among many data providers. For instance, similar patterns are observed in how developers interact with data sources like those provided by ArcGIS REST services, where the core interaction is directly with the HTTP endpoints complemented by various client-side helpers.

The API provides comprehensive documentation including example code snippets in several popular programming languages, which serves as a foundation for building custom integrations or utilizing existing community efforts. The availability of examples in Python, Ruby, PHP, and Node.js addresses common development environments.

Official SDKs by language

OpenCorporates maintains a set of officially sanctioned client libraries to support developers. These libraries are typically lightweight wrappers around the REST API, designed to handle common tasks such as request formatting, error handling, and response parsing. The official offerings emphasize ease of use and direct interaction with the core API endpoints for company, officer, and filing data.

The following table outlines the key official SDKs and their characteristics:

Language Package Name Install Command Example Maturity / Support
Python opencorporates-api-python pip install opencorporates-api-python Actively maintained
Ruby opencorporates-api-ruby gem install opencorporates-api-ruby Actively maintained
PHP opencorporates-api-php composer require opencorporates/opencorporates-api-php Regularly updated
Node.js opencorporates-api-node npm install opencorporates-api-node Regularly updated

Installation

Installing an OpenCorporates SDK typically follows the standard package management practices for each programming language. Before installation, developers should ensure they have the appropriate language runtime and package manager set up on their development environment. An API key from OpenCorporates is required to authenticate requests, which can be obtained after registering on the OpenCorporates pricing page.

Python

The Python SDK can be installed using pip, the standard package installer for Python:

pip install opencorporates-api-python

It is recommended to use a Python virtual environment to manage dependencies for your project.

Ruby

For Ruby applications, the SDK is available as a gem and can be installed via gem install:

gem install opencorporates-api-ruby

Adding gem 'opencorporates-api-ruby' to your Gemfile and running bundle install is the preferred method for Bundler-managed Ruby projects.

PHP

PHP projects can integrate the OpenCorporates SDK using Composer, the dependency manager for PHP:

composer require opencorporates/opencorporates-api-php

Ensure Composer is installed and available in your project directory.

Node.js

The Node.js SDK is available through npm, the Node.js package manager:

npm install opencorporates-api-node

This command will add the package to your project's node_modules directory and update your package.json file.

Quickstart example

The following examples demonstrate how to make a basic API call using the official SDKs to retrieve company data. Replace YOUR_API_KEY with your actual OpenCorporates API key.

Python Example

To fetch details for a specific company, you might use the following Python code:

import OpenCorporatesAPI

api_key = "YOUR_API_KEY"
oc_api = OpenCorporatesAPI.OpenCorporatesAPI(api_key=api_key)

try:
    # Search for a company by its name
    companies = oc_api.search_companies(q="Google Inc.", country_code="us")
    if companies and companies.get('results', []):
        for company in companies['results']:
            print(f"Company Name: {company['company']['name']}")
            print(f"Jurisdiction Code: {company['company']['jurisdiction_code']}")
            print(f"Company Number: {company['company']['company_number']}")
    else:
        print("No companies found.")
except OpenCorporatesAPI.OpenCorporatesAPIError as e:
    print(f"API Error: {e}")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

Ruby Example

A Ruby client for fetching company data:

require 'opencorporates-api-ruby'

OpenCorporatesAPI.api_key = 'YOUR_API_KEY'

begin
  # Search for a company by its name
  response = OpenCorporatesAPI::Company.search(q: 'Apple Inc.', country_code: 'us')
  if response&.results
    response.results.each do |result|
      company = result.company
      puts "Company Name: #{company.name}"
      puts "Jurisdiction Code: #{company.jurisdiction_code}"
      puts "Company Number: #{company.company_number}"
    end
  else
    puts "No companies found."
  end
rescue OpenCorporatesAPI::Error => e
  puts "API Error: #{e.message}"
rescue StandardError => e
  puts "An unexpected error occurred: #{e.message}"
end

PHP Example

Example of using the PHP client to find company information:

<?php
require 'vendor/autoload.php';

use OpenCorporates\OpenCorporatesAPI\Client;
use OpenCorporates\OpenCorporatesAPI\Exception\OpenCorporatesAPIException;

$apiKey = 'YOUR_API_KEY';
$client = new Client($apiKey);

try {
    // Search for a company by its name
    $response = $client->searchCompanies(['q' => 'Microsoft Corporation', 'country_code' => 'us']);

    if (isset($response['results']) && !empty($response['results'])) {
        foreach ($response['results'] as $result) {
            $company = $result['company'];
            echo "Company Name: " . $company['name'] . "\n";
            echo "Jurisdiction Code: " . $company['jurisdiction_code'] . "\n";
            echo "Company Number: " . $company['company_number'] . "\n";
        }
    } else {
        echo "No companies found.\n";
    }
} catch (OpenCorporatesAPIException $e) {
    echo "API Error: " . $e->getMessage() . "\n";
} catch (Exception $e) {
    echo "An unexpected error occurred: " . $e->getMessage() . "\n";
}
?>

Node.js Example

Using the Node.js client to query for company data:

const OpenCorporatesAPI = require('opencorporates-api-node');

const apiKey = 'YOUR_API_KEY';
const client = new OpenCorporatesAPI(apiKey);

async function getCompanyData() {
    try {
        // Search for a company by its name
        const response = await client.searchCompanies({
            q: 'Amazon.com, Inc.',
            country_code: 'us'
        });

        if (response.results && response.results.length > 0) {
            response.results.forEach(result => {
                const company = result.company;
                console.log(`Company Name: ${company.name}`);
                console.log(`Jurisdiction Code: ${company.jurisdiction_code}`);
                console.log(`Company Number: ${company.company_number}`);
            });
        } else {
            console.log('No companies found.');
        }
    } catch (error) {
        console.error(`API Error: ${error.message}`);
    }
}

getCompanyData();

Community libraries

Beyond the official SDKs, the OpenCorporates API's adherence to standard REST principles means that developers can easily interact with it using generic HTTP client libraries available in virtually any programming language. This has fostered the creation of various community-contributed libraries and wrappers. These might offer specialized functionalities, different levels of abstraction, or support for languages not covered by official SDKs.

While OpenCorporates does not officially endorse or maintain these community efforts, they can be valuable resources. Developers often share their wrappers on platforms like GitHub or package repositories, providing alternatives to the official tools. When considering a community library, it's advisable to evaluate its:

  • Maintenance status: Check the last commit date and issue activity.
  • Documentation: Assess the clarity and completeness of usage instructions.
  • Test coverage: High test coverage can indicate reliability.
  • Community support: Look for active discussions or contribution channels.
  • Feature set: Verify if it supports the specific API endpoints and functionalities required for your project.

For example, a developer might find a community-driven Swift library for iOS applications or a Go client for backend services, even if OpenCorporates doesn't provide an official version. Such libraries often leverage robust, widely-used HTTP clients, like requests in Python, axios in JavaScript, or guzzle in PHP, which themselves are well-documented and maintained by broader developer communities. This approach of building on top of established HTTP tooling is a common practice across the API ecosystem, demonstrated by how many services, including those from Cloudflare's API documentation, encourage direct API interactions while also supporting client libraries.

To discover community libraries, developers can search relevant package managers (e.g., PyPI for Python, npm for Node.js, RubyGems for Ruby, Packagist for PHP) or code hosting platforms (like GitHub) using keywords such as "OpenCorporates client" or "OpenCorporates API wrapper". Always review the source code and licensing before incorporating any third-party library into a production environment.