Skip to main content

Explorer API

The Explorer API is how you query and purchase data from Carbon Arc. It provides a complete workflow for building data requests, checking prices, making purchases, and retrieving your data.


Overview

The Explorer API follows a four-step workflow:

StepMethodDescription
1. Buildbuild_framework()Define what data you want
2. Pricecheck_framework_price()See how much it costs
3. Buybuy_frameworks()Purchase the data
4. Getget_framework_data()Retrieve your purchased data

Setup

from carbonarc import CarbonArcClient
import pandas as pd

# Initialize client
client = CarbonArcClient(
host="https://api.carbonarc.co",
token="YOUR_API_TOKEN"
)

Core Concepts

What is a Framework?

A Framework is a data query that defines:

  • Entities — Who/what you want data for (companies, products, apps, tickers)
  • Insight — What metric you want (revenue, users, transactions, etc.)
  • Filters — How to slice the data (date range, location, resolution)
  • Aggregate — How to aggregate the values (sum, mean, count, etc.)

Key IDs You'll Need

ID TypeDescriptionExample
carc_idEntity identifier64719 (Tesla)
insightMetric/KPI identifier347
representationEntity type"company", "ticker", "app"
Finding IDs

Use the Ontology API to discover entity IDs and insights, or the ID Reference for a complete catalog. To verify compatibility, use get_entities_for_insight(insight_id) to find valid entities for an insight, or get_insights_for_entity(entity_id, entity_representation) to find valid insights for an entity.


API Methods

1. Build Framework

Verify Entity-Insight Compatibility

Before building a framework, confirm that your entity and insight are compatible. Not every entity has data for every insight. Use get_insights_for_entity(entity_id, entity_representation) or get_entities_for_insight(insight_id) from the Ontology API to check.

Create a framework that defines your data query.

framework = client.explorer.build_framework(
entities=[
{"carc_id": 64719, "representation": "company"}
],
insight=347,
filters={
"location_resolution": "us",
"date_resolution": "month",
"date_range": {
"start_date": "2024-01-01",
"end_date": "2024-12-31"
}
},
aggregate="sum"
)

Parameters

ParameterTypeRequiredDescription
entitieslistYesList of entity objects with carc_id and representation
insightintYesThe insight ID (metric) you want
filtersdictYesFilter configuration (see below)
aggregatestrNoAggregation method ("sum", "mean", or "count_distinct", default: None)

Filter Options

FilterOptionsDescription
date_resolutionday, week, month, quarterTime granularity
location_resolutionus, state, dma, cbsa, country, zip, wwGeographic granularity
date_range{start_date, end_date}Date range in YYYY-MM-DD format

Aggregation Options

AggregateDescription
sumSum of values
meanAverage of values
count_distinctCount of unique values

2. Explore Available Filters

Some data assets have custom filters (e.g., diagnosis categories, product types). Use these methods to discover them.

Get Filter Keys

filters = client.explorer.collect_framework_filters(framework)
print(filters)
# ['location_resolution', 'date_resolution', 'diagnosis_category', ...]

Get Filter Options

options = client.explorer.collect_framework_filter_options(
framework,
"diagnosis_category"
)
print(options)
# ['respiratory', 'cardiovascular', 'neurological', ...]

3. Check Framework Price

Before purchasing, check how much the data will cost.

price = client.explorer.check_framework_price(framework)
print(f"Price: ${price:.2f}")

Understanding Pricing

PriceMeaning
$X.XXCost to purchase this data
$0.00Data is free, already purchased, or included in your subscription

4. Buy Framework

Purchase the framework to access the data.

warning

This will charge your account! Always check the price first.

order = client.explorer.buy_frameworks([framework])
framework_id = order['frameworks'][0]

print(f"Framework ID: {framework_id}")
# Framework ID: abc123-def456-...

Save your Framework ID — you'll need it to retrieve data!

Buying Multiple Frameworks

You can purchase multiple frameworks in a single call:

frameworks = [framework1, framework2, framework3]
order = client.explorer.buy_frameworks(frameworks)

# Get all framework IDs
framework_ids = order['frameworks']

5. Get Framework Metadata

After purchasing, get metadata about your framework.

metadata = client.explorer.get_framework_metadata(framework_id="YOUR_FRAMEWORK_ID")
print(metadata)

6. Get Framework Data

Retrieve the data you purchased. By default, fetch_all=True returns all data in a single call.

# Returns all data at once (default)
data = client.explorer.get_framework_data(framework_id="YOUR_FRAMEWORK_ID")

# Convert to DataFrame
df = pd.DataFrame(data['data'])
print(df.head())

Parameters

ParameterTypeRequiredDefaultDescription
framework_idstrYesThe framework ID from your purchase
data_typestrNoNoneReturn format: "dataframe" (returns a DataFrame directly) or "timeseries"
pageintNoNonePage number (only used when fetch_all=False)
sizeintNoNonePage size (only used when fetch_all=False)
fetch_allboolNoTrueFetch all data in one call. Set to False for paginated retrieval

Return as DataFrame Directly

df = client.explorer.get_framework_data(
framework_id="YOUR_FRAMEWORK_ID",
data_type="dataframe"
)
print(df.head())

Paginated Retrieval

For large datasets, set fetch_all=False and paginate through results:

all_records = []
page = 1
page_size = 1000

while True:
response = client.explorer.get_framework_data(
framework_id="YOUR_FRAMEWORK_ID",
fetch_all=False,
page=page,
size=page_size
)

records = response.get('data', [])
total = response.get('total', 0)

if not records:
break

all_records.extend(records)

if len(all_records) >= total:
break

page += 1

df = pd.DataFrame(all_records)
print(f"Total records: {len(df)}")

Complete Examples

Example 1: Basic Workflow

Query monthly revenue data for Tesla:

from carbonarc import CarbonArcClient
import pandas as pd

client = CarbonArcClient(host="https://api.carbonarc.co", token="YOUR_TOKEN")

# Step 1: Build framework
framework = client.explorer.build_framework(
entities=[{"carc_id": 64719, "representation": "company"}],
insight=347,
filters={
"location_resolution": "us",
"date_resolution": "month",
"date_range": {"start_date": "2024-01-01", "end_date": "2024-06-30"}
},
aggregate="sum"
)

# Step 2: Check price
price = client.explorer.check_framework_price(framework)
print(f"Price: ${price:.2f}")

# Step 3: Purchase
order = client.explorer.buy_frameworks([framework])
framework_id = order['frameworks'][0]

# Step 4: Get data
data = client.explorer.get_framework_data(framework_id=framework_id)
df = pd.DataFrame(data['data'])
print(df)

Example 2: Multiple Entities

Compare metrics across multiple companies:

framework = client.explorer.build_framework(
entities=[
{"carc_id": 64719, "representation": "company"}, # Tesla
{"carc_id": 64781, "representation": "company"}, # Apple
{"carc_id": 64823, "representation": "company"}, # Amazon
],
insight=347,
filters={
"location_resolution": "us",
"date_resolution": "month",
"date_range": {"start_date": "2024-01-01", "end_date": "2024-12-31"}
},
aggregate="sum"
)

# Check price
price = client.explorer.check_framework_price(framework)
print(f"Price for 3 companies: ${price:.2f}")

# Purchase and retrieve
order = client.explorer.buy_frameworks([framework])
framework_id = order['frameworks'][0]

data = client.explorer.get_framework_data(framework_id=framework_id)
df = pd.DataFrame(data['data'])
print(df)

Example 3: State-Level Data

Get data broken down by state:

framework = client.explorer.build_framework(
entities=[{"carc_id": 64719, "representation": "company"}],
insight=347,
filters={
"location_resolution": "state", # State-level granularity
"date_resolution": "month",
"date_range": {"start_date": "2024-01-01", "end_date": "2024-03-31"}
},
aggregate="sum"
)

# Check price (state-level data may cost more)
price = client.explorer.check_framework_price(framework)
print(f"State-level price: ${price:.2f}")

Example 4: Daily Resolution

Get daily-level data:

framework = client.explorer.build_framework(
entities=[{"carc_id": 64719, "representation": "company"}],
insight=347,
filters={
"location_resolution": "us",
"date_resolution": "day", # Daily granularity
"date_range": {"start_date": "2024-01-01", "end_date": "2024-01-31"}
},
aggregate="sum"
)

# Daily data for a month
price = client.explorer.check_framework_price(framework)
print(f"Daily data price: ${price:.2f}")

Example 5: Custom Filters

Work with dataset-specific filters:

# First, discover available filters
framework = client.explorer.build_framework(
entities=[{"carc_id": 12345, "representation": "company"}],
insight=789,
filters={
"location_resolution": "us",
"date_resolution": "month",
"date_range": {"start_date": "2024-01-01", "end_date": "2024-12-31"}
},
aggregate="sum"
)

# Get available filter keys
filter_keys = client.explorer.collect_framework_filters(framework)
print(f"Available filters: {filter_keys}")

# Get options for a specific filter
if "diagnosis_category" in filter_keys:
options = client.explorer.collect_framework_filter_options(
framework,
"diagnosis_category"
)
print(f"Diagnosis categories: {options}")

# Rebuild framework with custom filter
framework = client.explorer.build_framework(
entities=[{"carc_id": 12345, "representation": "company"}],
insight=789,
filters={
"location_resolution": "us",
"date_resolution": "month",
"date_range": {"start_date": "2024-01-01", "end_date": "2024-12-31"},
"diagnosis_category": "respiratory" # Apply custom filter
},
aggregate="sum"
)

Method Reference

MethodSignatureReturns
build_framework()(entities, insight, filters, aggregate)Framework object
collect_framework_filters()(framework)List of filter keys
collect_framework_filter_options()(framework, filter_key)List of options
check_framework_price()(framework)Price (float)
buy_frameworks()([frameworks])Order object with framework IDs
get_framework_metadata()(framework_id)Metadata dict
get_framework_data()(framework_id, data_type?, page?, size?, fetch_all?)DataFrame, timeseries, or dict

Quick Reference

┌─────────────────────────────────────────────────────────────┐
│ EXPLORER API WORKFLOW │
├─────────────────────────────────────────────────────────────┤
│ │
│ 1. build_framework() → Define your query │
│ │
│ 2. collect_framework_filters() → (Optional) Discover │
│ collect_framework_filter_options() available filters │
│ │
│ 3. check_framework_price() → Verify cost before buying │
│ │
│ 4. buy_frameworks() → Purchase (charges account!) │
│ │
│ 5. get_framework_data() → Retrieve your data │
│ │
└─────────────────────────────────────────────────────────────┘

Troubleshooting

Common Issues

IssueCauseSolution
Empty data returnedFramework not purchasedCall buy_frameworks() first
Invalid entityWrong carc_idUse Ontology API to find correct ID
Invalid insightWrong insight IDCheck ID Reference for valid insights
Invalid entity/insight combinationEntity doesn't have data for the insightUse get_insights_for_entity() or get_entities_for_insight() to verify compatibility
Price is $0Already purchased or free tierData should be available
Timeout on large queriesToo much data requestedReduce date range or use pagination

Debugging Tips

Inspect raw API responses:

import json

# Check framework structure
print(json.dumps(framework, indent=2))

# Check data response structure
data = client.explorer.get_framework_data(framework_id=framework_id)
print(f"Keys: {data.keys()}")
print(f"Records: {len(data.get('data', []))}")
print(f"Total available: {data.get('total', 'N/A')}")

Error Handling

try:
framework = client.explorer.build_framework(
entities=[{"carc_id": 64719, "representation": "company"}],
insight=347,
filters={...},
aggregate="sum"
)

price = client.explorer.check_framework_price(framework)
print(f"Price: ${price:.2f}")

if price > 0:
confirm = input("Proceed with purchase? (y/n): ")
if confirm.lower() != 'y':
print("Purchase cancelled.")
exit()

order = client.explorer.buy_frameworks([framework])
framework_id = order['frameworks'][0]

data = client.explorer.get_framework_data(framework_id=framework_id)
df = pd.DataFrame(data['data'])

except Exception as e:
print(f"Error: {e}")

Next Steps