In today's fast-paced market, staying ahead of the competition isn't just an advantage; it's a necessity. But tracking competitors—their size, financial health, and strategic positioning—is often a manual, time-consuming process that relies on fragmented and frequently outdated data. What if you could automate this process and feed your team real-time, verifiable business intelligence?
This is where the businesses.do API comes in. Our AI-powered service provides on-demand access to global business data, letting you query comprehensive company profiles with a simple API call.
In this step-by-step technical guide, we'll walk you through how to use the businesses.do business intelligence API to build a powerful competitor analysis dashboard. You'll learn how to fetch, process, and visualize critical data, empowering your team to make data-driven strategic decisions.
Before we dive into the code, let's look at why businesses.do is the perfect tool for this job:
To follow along, you'll need a few things:
pip install requests pandas
First, create a new project folder and a Python file, e.g., competitor_analyzer.py. For security, it's best practice to store your API key as an environment variable rather than hardcoding it.
Let's start by importing the necessary libraries and setting up our API key and a list of competitors we want to track.
import os
import requests
import pandas as pd
# Load API key from environment variables (recommended)
API_KEY = os.getenv("BUSINESSES_DO_API_KEY")
API_ENDPOINT = "https://api.businesses.do/v1/lookup" # Example endpoint
# List of competitor domains or names to analyze
competitors_to_track = ["examplecorp.com", "innovateinc.net", "globaltech.io"]
Now, let's write a function to query the businesses.do API for each competitor. This function will make a request to the endpoint, passing the company identifier (like a domain name) and our API key.
def get_company_data(company_identifier):
"""
Fetches company data from the businesses.do API.
"""
headers = {
"X-API-Key": API_KEY,
"Content-Type": "application/json"
}
params = {
"domain": company_identifier # You can also search by name or D-U-N-S
}
try:
response = requests.get(API_ENDPOINT, headers=headers, params=params)
response.raise_for_status() # Raises an HTTPError for bad responses (4xx or 5xx)
data = response.json()
if data.get("status") == "success":
return data.get("company")
else:
print(f"Failed to find data for {company_identifier}: {data.get('message')}")
return None
except requests.exceptions.RequestException as e:
print(f"An API request error occurred for {company_identifier}: {e}")
return None
# Example of fetching data for one company
print("Fetching data for the first competitor...")
first_competitor_data = get_company_data(competitors_to_track[0])
print(first_competitor_data)
Running this will return a structured JSON object for the first competitor, just like the example below. This rich data includes everything from their D-U-N-S lookup number to revenue and industry classification.
{
"status": "success",
"company": {
"name": "Example Corp",
"dunsNumber": "123-456-7890",
"legalStatus": "Active",
"address": {
"street": "123 Innovation Drive",
"city": "Palo Alto",
"state": "CA",
"zipCode": "94304",
"country": "USA"
},
...
}
}
A list of JSON objects is good, but a structured table is even better for analysis. We can use the pandas library to transform our collection of competitor data into a clean DataFrame.
Let's loop through our list of competitors and build a list of dictionaries containing only the key metrics we want to compare.
all_competitor_data = []
print("\nFetching data for all competitors...")
for company in competitors_to_track:
data = get_company_data(company)
if data:
# Extract the specific fields we want for our dashboard
structured_info = {
"Company Name": data.get("name"),
"D-U-N-S Number": data.get("dunsNumber"),
"Industry": data.get("industry", {}).get("description"),
"Employees": data.get("employeeCount"),
"Annual Revenue (USD)": data.get("annualRevenue", {}).get("value"),
"Year Founded": data.get("yearFounded"),
"Country": data.get("address", {}).get("country")
}
all_competitor_data.append(structured_info)
# Create a Pandas DataFrame
df = pd.DataFrame(all_competitor_data)
print("\nCompetitor Analysis Summary:")
print(df.to_string())
This script will now output a clean, organized table perfect for a quick overview:
Competitor Analysis Summary:
Company Name D-U-N-S Number Industry Employees Annual Revenue (USD) Year Founded Country
0 Example Corp 123-456-7890 Software Publishers 500 150000000.0 2010 USA
1 Innovate Inc 987-654-3210 Data Processing Services 250 75000000.0 2015 USA
2 Global Tech Solutions 555-123-4567 IT Consulting Services 1200 300000000.0 2008 DEU
A dashboard isn't complete without visualizations. While you could integrate this data into a web framework with libraries like Chart.js or D3.js, you can generate insightful charts directly from your script using libraries like matplotlib or seaborn.
Let's add a simple bar chart to compare employee counts. First, install matplotlib:
pip install matplotlib
Then, add this to your Python script:
import matplotlib.pyplot as plt
# Ensure the DataFrame is sorted for better visualization
df_sorted = df.sort_values(by="Employees", ascending=False)
plt.figure(figsize=(10, 6))
plt.bar(df_sorted["Company Name"], df_sorted["Employees"], color='skyblue')
plt.xlabel("Company")
plt.ylabel("Number of Employees")
plt.title("Competitor Size by Employee Count")
plt.xticks(rotation=45, ha="right")
plt.tight_layout()
# Save the chart as an image
plt.savefig("competitor_employee_comparison.png")
print("\nGenerated chart 'competitor_employee_comparison.png'")
This code generates a bar chart that instantly visualizes the relative size of your competitors, a key piece of strategic information. You can create similar charts for annual revenue, or even plot companies on a map based on their location.
This guide provides the foundation for a powerful competitor analysis tool. Here are a few ideas to expand on it:
By automating competitor intelligence with businesses.do, you free up your team to focus on what truly matters: making informed decisions that drive your business forward.
Ready to build your own data-driven insights? Sign up on businesses.do and get instant access to the global business data you need.