# Carbon Accounting Use Case Access emissions calculations and carbon footprint data for sustainability reporting. ## Overview 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 ## Carbon Data Flow ```mermaid graph LR A[Query Emissions] --> B[Retrieve Data] B --> C[Export CSV] B --> D[Get Chart Data] C --> E[External Reporting] D --> F[Dashboards] D --> G[Trend Analysis] ``` ## Quick Start ### Get Emissions Data ```bash curl -X GET https://developers-scranton.coolset.com/api/emission_calculations/emissions/ \ -H "Authorization: Bearer YOUR_API_TOKEN" ``` ### Export as CSV ```bash curl -X GET https://developers-scranton.coolset.com/api/emission_calculations/emissions/export/ \ -H "Authorization: Bearer YOUR_API_TOKEN" \ --output emissions.csv ``` ### Get Chart Data ```bash curl -X GET https://developers-scranton.coolset.com/api/emission_calculations/charts/ \ -H "Authorization: Bearer YOUR_API_TOKEN" ``` ## Complete Example: Monthly Reporting ```python 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}") ``` ## Data Structure **Emissions Response:** ```json { "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" } ``` ## Integration Examples ### Dashboard Integration ```javascript // 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 }] }); } ``` ### Automated Reporting ```python 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) ``` ## Best Practices ### 1. Cache Data Appropriately Emissions calculations are typically updated monthly: ```python 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) ``` ### 2. Track Trends Over Time Monitor progress towards reduction targets: ```python 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 } ``` ### 3. Export for External Reporting Prepare data for CSRD, CDP, and other frameworks: ```python 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_metrics ``` ## API Endpoints Used - `GET /emission_calculations/emissions/` - [Carbon API](/carbon-api#operation/emission_calculations_emissions_list) - `GET /emission_calculations/emissions/export/` - [Carbon API](/carbon-api#operation/emission_calculations_emissions_export_list) - `GET /emission_calculations/charts/` - [Carbon API](/carbon-api#operation/emission_calculations_charts_list) ## Next Steps - [EUDR Compliance →](/use-cases/eudr-compliance) - [Carbon API Reference →](/carbon-api) - [Getting Started →](/getting-started/quickstart)