Access emissions calculations and carbon footprint data for sustainability reporting.
The Carbon API provides read-only access to GHG Scope 1-3 emissions calculations. Use this data for:
- Sustainability reporting (CSRD, GHG Protocol)
- Internal carbon tracking
- Scenario planning
- Stakeholder communications
curl -X GET https://developers-scranton.coolset.com/api/emission_calculations/emissions/ \
-H "Authorization: Bearer YOUR_API_TOKEN"curl -X GET https://developers-scranton.coolset.com/api/emission_calculations/emissions/export/ \
-H "Authorization: Bearer YOUR_API_TOKEN" \
--output emissions.csvcurl -X GET https://developers-scranton.coolset.com/api/emission_calculations/charts/ \
-H "Authorization: Bearer YOUR_API_TOKEN"import requests
import pandas as pd
from datetime import datetime, timedelta
class CarbonReporting:
def __init__(self, api_token):
self.base_url = "https://developers-scranton.coolset.com/api"
self.headers = {
"Authorization": f"Bearer {api_token}",
"Content-Type": "application/json"
}
def get_monthly_emissions(self, year, month):
"""Get emissions for a specific month"""
response = requests.get(
f"{self.base_url}/emission_calculations/emissions/",
headers=self.headers,
params={
"year": year,
"month": month
}
)
return response.json()
def export_annual_report(self, year):
"""Export full year emissions as CSV"""
response = requests.get(
f"{self.base_url}/emission_calculations/emissions/export/",
headers=self.headers,
params={"year": year}
)
# Save to file
filename = f"emissions_{year}.csv"
with open(filename, 'wb') as f:
f.write(response.content)
return filename
def get_visualization_data(self):
"""Get data for charts/dashboards"""
response = requests.get(
f"{self.base_url}/emission_calculations/charts/",
headers=self.headers
)
return response.json()
# Usage
reporter = CarbonReporting("YOUR_API_TOKEN")
# Get current month's emissions
now = datetime.now()
emissions = reporter.get_monthly_emissions(now.year, now.month)
print(f"Total Emissions: {emissions['total_co2e']} tCO2e")
print(f"Scope 1: {emissions['scope_1']} tCO2e")
print(f"Scope 2: {emissions['scope_2']} tCO2e")
print(f"Scope 3: {emissions['scope_3']} tCO2e")
# Export annual report
report_file = reporter.export_annual_report(2024)
print(f"Annual report saved to: {report_file}")Emissions Response:
{
"period": {
"year": 2024,
"month": 10
},
"total_co2e": 1250.5,
"scope_1": 450.2,
"scope_2": 300.8,
"scope_3": 499.5,
"by_category": {
"purchased_goods": 320.5,
"business_travel": 89.2,
"employee_commute": 45.8,
"waste": 22.5,
"other": 21.5
},
"calculation_date": "2024-11-01T00:00:00Z"
}// Fetch emissions data for dashboard
async function updateEmissionsDashboard() {
const response = await fetch(
'https://developers-scranton.coolset.com/api/emission_calculations/charts/',
{
headers: {
'Authorization': `Bearer ${API_TOKEN}`
}
}
);
const data = await response.json();
// Update chart
updateChart({
labels: data.months,
datasets: [{
label: 'Total Emissions (tCO2e)',
data: data.emissions
}]
});
}import schedule
def monthly_carbon_report():
"""Generate monthly carbon report"""
reporter = CarbonReporting(API_TOKEN)
# Get last month's data
last_month = datetime.now() - timedelta(days=30)
emissions = reporter.get_monthly_emissions(
last_month.year,
last_month.month
)
# Generate report
report = generate_report_pdf(emissions)
# Email to stakeholders
email_report(report, recipients=[
'sustainability@company.com',
'management@company.com'
])
# Run on 1st of each month
schedule.every().month.at("09:00").do(monthly_carbon_report)Emissions calculations are typically updated monthly:
from functools import lru_cache
from datetime import datetime
@lru_cache(maxsize=12) # Cache last 12 months
def get_cached_emissions(year, month):
"""Cache emissions data to reduce API calls"""
return reporter.get_monthly_emissions(year, month)Monitor progress towards reduction targets:
def calculate_reduction_progress(baseline_year, current_year):
"""Calculate emissions reduction vs baseline"""
baseline = reporter.get_monthly_emissions(baseline_year, 1)
current = reporter.get_monthly_emissions(current_year, 1)
reduction_pct = (
(baseline['total_co2e'] - current['total_co2e']) /
baseline['total_co2e'] * 100
)
return {
'baseline': baseline['total_co2e'],
'current': current['total_co2e'],
'reduction_percentage': reduction_pct,
'on_track': reduction_pct >= target_reduction_pct
}Prepare data for CSRD, CDP, and other frameworks:
def prepare_csrd_report(year):
"""Prepare emissions data for CSRD reporting"""
# Export annual data
filename = reporter.export_annual_report(year)
# Load and format
df = pd.read_csv(filename)
# Calculate required metrics
csrd_metrics = {
'total_ghg_emissions': df['total_co2e'].sum(),
'scope_1': df['scope_1'].sum(),
'scope_2': df['scope_2'].sum(),
'scope_3': df['scope_3'].sum(),
'intensity_per_revenue': df['total_co2e'].sum() / annual_revenue,
'intensity_per_employee': df['total_co2e'].sum() / employee_count
}
return csrd_metricsGET /emission_calculations/emissions/- Carbon APIGET /emission_calculations/emissions/export/- Carbon APIGET /emission_calculations/charts/- Carbon API