carboncue_sdk.client¶
client ¶
Main client for CarbonCue SDK.
CarbonClient ¶
Client for accessing carbon intensity data and calculating SCI scores.
Example
client = CarbonClient() intensity = await client.get_current_intensity(region="us-west-2") sci = client.calculate_sci( ... operations=100.0, ... materials=50.0, ... functional_unit=1000, ... region="us-west-2" ... )
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
config
|
CarbonConfig | None
|
Optional configuration. If not provided, loads from environment. |
None
|
Source code in packages/sdk/src/carboncue_sdk/client.py
__aenter__
async
¶
Async context manager entry.
Source code in packages/sdk/src/carboncue_sdk/client.py
__aexit__
async
¶
get_current_intensity
async
¶
Get current carbon intensity for a region.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
region
|
str
|
Region code (e.g., us-west-2) |
required |
provider
|
str
|
Cloud provider (aws, azure, gcp, etc.) |
'aws'
|
Returns:
| Type | Description |
|---|---|
CarbonIntensity
|
Current carbon intensity data |
Raises:
| Type | Description |
|---|---|
InvalidRegionError
|
If region is not supported |
InvalidProviderError
|
If provider is not supported |
AuthenticationError
|
If API key is missing or invalid |
RateLimitError
|
If API rate limit exceeded |
DataNotAvailableError
|
If data not available for region |
APIError
|
If API request fails |
Source code in packages/sdk/src/carboncue_sdk/client.py
calculate_sci ¶
calculate_sci(operational_emissions: float, embodied_emissions: float, functional_unit: float, functional_unit_type: str = 'requests', region: str = 'us-west-2') -> SCIScore
Calculate Software Carbon Intensity (SCI) score.
Implements GSF SCI specification: SCI = (O + M) / R
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
operational_emissions
|
float
|
O - Operational emissions in gCO2eq |
required |
embodied_emissions
|
float
|
M - Embodied emissions in gCO2eq |
required |
functional_unit
|
float
|
R - Number of functional units |
required |
functional_unit_type
|
str
|
Type of functional unit (requests, users, etc.) |
'requests'
|
region
|
str
|
Region where computation occurred |
'us-west-2'
|
Returns:
| Type | Description |
|---|---|
SCIScore
|
Calculated SCI score |
Raises:
| Type | Description |
|---|---|
ValueError
|
If functional_unit is <= 0 |