carboncue_sdk¶
carboncue_sdk ¶
CarbonCue SDK - Core library for carbon-aware computing.
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 |
Source code in packages/sdk/src/carboncue_sdk/client.py
close
async
¶
CarbonConfig ¶
Bases: BaseSettings
Configuration for CarbonCue SDK.
All settings can be provided via environment variables with CARBONCUE_ prefix. Example: CARBONCUE_ELECTRICITY_MAPS_API_KEY=your_key
APIError ¶
Bases: CarbonCueError
Error communicating with external API.
CarbonCueError ¶
Bases: Exception
Base exception for all CarbonCue errors.
InvalidProviderError ¶
Bases: CarbonCueError
Invalid cloud provider specified.
InvalidRegionError ¶
Bases: CarbonCueError
Invalid cloud region specified.
CarbonIntensity ¶
Bases: BaseModel
Carbon intensity data for a specific region and time.
Region ¶
Bases: BaseModel
Cloud region information.
SCIScore ¶
Bases: BaseModel
Software Carbon Intensity (SCI) score per GSF specification.
SCI = (O + M) / R Where: O = Operational emissions (energy × carbon intensity) M = Embodied emissions (manufacturing impact) R = Functional unit (requests, users, etc.)
RegionMapper ¶
Maps cloud provider regions to Electricity Maps zone identifiers.
get_zone_id
staticmethod
¶
Get Electricity Maps zone ID for a cloud region.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
region
|
str
|
Cloud provider region code (e.g., us-west-2, eastus) |
required |
provider
|
str
|
Cloud provider name (aws, azure, gcp, digitalocean) |
'aws'
|
Returns:
| Type | Description |
|---|---|
str
|
Electricity Maps zone ID (e.g., US-CAL-CISO) |
Raises:
| Type | Description |
|---|---|
ValueError
|
If region or provider is not supported |
Source code in packages/sdk/src/carboncue_sdk/region_mapper.py
get_supported_regions
staticmethod
¶
Get list of supported regions for a cloud provider.
Parameters:
| Name | Type | Description | Default |
|---|---|---|---|
provider
|
str
|
Cloud provider name |
'aws'
|
Returns:
| Type | Description |
|---|---|
list[str]
|
List of supported region codes |
Raises:
| Type | Description |
|---|---|
ValueError
|
If provider is not supported |
Source code in packages/sdk/src/carboncue_sdk/region_mapper.py
get_supported_providers
staticmethod
¶
Get list of all supported cloud providers.
Returns:
| Type | Description |
|---|---|
list[str]
|
List of supported provider names |