-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathtest-sdk.py
More file actions
68 lines (57 loc) · 2.05 KB
/
test-sdk.py
File metadata and controls
68 lines (57 loc) · 2.05 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
"""
Test file for ZeroCarbon Python SDK
Usage:
1. Install SDK: pip install -e .
2. Set API key: $env:ZEROCARBON_API_KEY = "your_key_here" (PowerShell)
3. Run: python test-sdk.py
"""
import os
from zerocarbon import ZeroCarbon
API_KEY = os.environ.get('ZEROCARBON_API_KEY', 'YOUR_API_KEY_HERE')
client = ZeroCarbon(
api_key=API_KEY,
base_url='http://localhost:3000/api/v1', # Local development
test_mode=True # Set to False for production
)
def test_sdk():
print('🧪 Testing ZeroCarbon Python SDK...\n')
try:
# Test 1: Flight Emissions Calculation
print('1️⃣ Testing flight emissions calculation...')
flight_result = client.calculate.flight(
origin='DEL',
destination='BOM',
cabin_class='economy',
passengers=1,
round_trip=False
)
print('✅ Flight emissions:', flight_result)
print('')
# Test 2: Electricity Emissions Calculation
print('2️⃣ Testing electricity emissions calculation...')
electricity_result = client.calculate.electricity(
kwh=1000,
country_code='IN',
state='Maharashtra'
)
print('✅ Electricity emissions:', electricity_result)
print('')
# Test 3: Get Offset Recommendations
print('3️⃣ Testing offset recommendations...')
offsets_result = client.offsets.get_recommendations(
emissions_tonnes=5.0,
budget_usd=100,
location='India'
)
print('✅ Offset recommendations:', offsets_result)
print('')
print('🎉 All tests passed!')
except Exception as error:
print(f'❌ Error: {str(error)}')
print('\n💡 Make sure:')
print(' 1. Your API key is set correctly')
print(' 2. Your API endpoints are deployed and working')
print(' 3. You have proper network connection')
print(' 4. SDK is installed: pip install -e .')
if __name__ == '__main__':
test_sdk()