🐍 The Python SDK — app6.5
Developer CourseModule 6: The Python SDKapp6.5
Hands-on20 min

Hands-on: Build a Carbon Dashboard in Python

🐍 Module 6: The Python SDK

Hands-on: Build a Carbon Dashboard in Python

Create a Python script that reads energy data, creates carbon attestations, and prints a summary dashboard.

Setup

export EAT_KEY="eat_test_YOUR_KEY_HERE"
pip3 install energyatit 2>/dev/null

The Script

Create carbon_dashboard.py:

import os
from energyatit import EnergyAtItClient
from datetime import datetime

client = EnergyAtItClient(api_key=os.environ["EAT_KEY"])

print("=== Carbon Dashboard ===")
print(f"Time: {datetime.now().isoformat()}")
print()

# 1. Read all sites
sites = client.sites.list()
print(f"Sites: {len(sites)}")

# 2. Read assets and meter data
for site in sites[:3]:  # First 3 sites
    print(f"\n--- {site['name']} (ID: {site['id']}) ---")
    assets = client.assets.list(site_id=site['id'])
    print(f"  Assets: {len(assets)}")

    readings = client.grid.get_meter_readings(grid_connection_id=site['id'])
    data = readings.get("readings", readings.get("data", {}))
    power = data.get("activePower_kW", 0)
    print(f"  Power: {power} kW")

# 3. Get carbon attestation
print("\n--- Carbon Attestation ---")
attestation = client.carbon.get_attestation(site_id=1)
print(f"  Records: {attestation.get('total_records', 'N/A')}")
print(f"  Total kWh: {attestation.get('total_kwh', 'N/A')}")

# 4. Verify hash chain
print("\n--- Hash Chain Integrity ---")
# Use the verify endpoint
chain = client.carbon.verify_chain(meter_id="meter-001")
print(f"  Valid: {chain.get('valid', 'unknown')}")
print(f"  Records checked: {chain.get('records_checked', 'N/A')}")

print("\n=== Dashboard Complete ===")
python3 carbon_dashboard.py

Verification

Lab complete if the script: lists sites, reads power data, gets carbon attestation info, and verifies hash chain integrity.

Open Hands-on Lab

Complete the exercise in the Developer Hub.

Launch

Log in to track your progress and earn certifications.