Carbem
A Rust library for retrieving carbon emission values from cloud providers.
Overview
Carbem provides a unified interface for querying carbon emission data from various cloud service providers. This library helps developers build more environmentally conscious applications by making it easy to access and analyze the carbon footprint of cloud infrastructure.
Features
- 🌍 Multi-provider support: Unified API for different cloud providers
- ⚡ Async/await: Built with modern async Rust for high performance
- 🔒 Type-safe: Leverages Rust's type system for reliable carbon data handling
- 🚀 Easy to use: Simple and intuitive API design
- 🐍 Python Bindings: Native Python integration via PyO3
- 🔧 Flexible Filtering: Filter by regions, services, and resources
Installation
Rust Library
Add this to your Cargo.toml:
[dependencies]
carbem = "0.2.0"
Python Package
Install from PyPI:
pip install carbem-python
For development setup with maturin:
pip install maturin
maturin develop
Quick Start
Using Rust
For standalone Rust applications, use the builder pattern with environment variables:
use carbem::{CarbemClient, EmissionQuery, TimePeriod};
use chrono::{Utc, Duration};
#[tokio::main]
async fn main() -> carbem::Result<()> {
// Configure client from environment variables
let client = CarbemClient::new()
.with_azure_from_env()?;
// Create a query
let query = EmissionQuery {
provider: "azure".to_string(),
regions: vec!["subscription-id".to_string()],
time_period: TimePeriod {
start: Utc::now() - Duration::days(30),
end: Utc::now(),
},
services: Some(vec!["compute".to_string(), "storage".to_string()]),
resources: None,
};
let emissions = client.query_emissions(&query).await?;
for emission in emissions {
println!("Service: {}, Emissions: {} kg CO2eq",
emission.service.unwrap_or_default(),
emission.emissions_kg_co2eq);
}
Ok(())
}
Using Python
For Python applications, use the get_emissions_py function:
import carbem
import json
from datetime import datetime, timedelta
# Azure configuration
config = json.dumps({
"access_token": "your-azure-bearer-token"
})
# Query for last 30 days
end_date = datetime.utcnow()
start_date = end_date - timedelta(days=30)
query = json.dumps({
"start_date": start_date.strftime("%Y-%m-%dT%H:%M:%SZ"),
"end_date": end_date.strftime("%Y-%m-%dT%H:%M:%SZ"),
"regions": ["your-subscription-id"],
})
# Get emissions data
result = carbem.get_emissions_py("azure", config, query)
emissions = json.loads(result)
print(f"Found {len(emissions)} emission records")
Create a .env file in your project root:
# Azure Carbon Emissions Configuration
CARBEM_AZURE_ACCESS_TOKEN=your_azure_bearer_token_here
# OR alternatively use:
# AZURE_TOKEN=your_azure_bearer_token_here
Configuration Parameters
Environment Variables (for Standalone Rust)
CARBEM_AZURE_ACCESS_TOKEN: Azure access tokenAZURE_TOKEN: Alternative Azure access token variable
Python Configuration
For Python applications, configuration is passed as JSON strings to the get_emissions_py function. See the Python API Documentation for detailed configuration examples and usage patterns.
Azure Configuration (AzureConfig)
The Azure provider requires minimal configuration:
use carbem::AzureConfig;
let config = AzureConfig {
access_token: "your-bearer-token".to_string(),
};
Object-Oriented API (Advanced Usage)
use carbem::{CarbemClient, AzureConfig, EmissionQuery, TimePeriod};
use chrono::{Utc, Duration};
#[tokio::main]
async fn main() -> carbem::Result<()> {
// Create a client and configure Azure provider
let config = AzureConfig {
access_token: "your-bearer-token".to_string(),
};
let client = CarbemClient::new()
.with_azure(config)?;
// Query carbon emissions for the last 30 days
let query = EmissionQuery {
provider: "azure".to_string(),
regions: vec!["subscription-id".to_string()], // Use your subscription IDs
time_period: TimePeriod {
start: Utc::now() - Duration::days(30),
end: Utc::now(),
},
services: None,
resources: None,
};
let emissions = client.query_emissions(&query).await?;
for emission in emissions {
println!("Date: {}, Region: {}, Emissions: {} kg CO2eq",
emission.time_period.start.format("%Y-%m-%d"),
emission.region,
emission.emissions_kg_co2eq);
}
Ok(())
}
Supported Providers
Microsoft Azure ✅
- Report Types: All report type from the API are supported.
- Queries: All query parameters are supported.
Google Cloud Platform
Google Cloud Platform is not supported at the moment (October 11th 2025). Data are available only after exporting them to BigQuery as discussed in this page. Thus, one will need to make a query to the BigQuery API, which makes a standard implementation not possible at the moment.
Amazon Web Services (AWS)
AWS is not supported at the moment (October 11th 2025). Data are available in S3 buckets as discussed in this page. An endpoint existed but was discontinued on July 23rd 2025 (ref).
Roadmap
- Core library infrastructure
- Azure Carbon Emission Reports API
- IBM Cloud Carbon Calculator
- Amazon Web Services (AWS)
- Google Cloud Platform (GCP)
- Additional providers planned
Testing
The library includes a comprehensive test suite:
# Run all tests
cargo test
# Run specific Azure provider tests
cargo test providers::azure
# Run with output
cargo test -- --nocapture
Test coverage includes:
- Provider creation and configuration
- Query conversion and validation
- Date parsing and time period handling
- Data conversion from Azure API responses
- Error handling for invalid configurations
Documentation
Rust Documentation
- API Documentation: Available on docs.rs
Python Documentation
- Python API Reference - Detailed function documentation and usage patterns
Contributing
We welcome contributions! Please see our Contributing Guide for details.
License
This project is licensed under Apache License, Version 2.0, (LICENSE-APACHE or http://www.apache.org/licenses/LICENSE-2.0)
Acknowledgments
This project aims to support sustainability efforts in cloud computing by making carbon emission data more accessible to developers and organizations.
Metadata
Release files for carbem-python 0.5.0
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | |
|---|---|---|---|
| carbem_python-0.5.0.tar.gz | 45.1 kB | Details |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Reset |
|---|---|---|---|---|
| carbem_python-0.5.0-cp313-cp313-manylinux_2_34_x86_64.whl | CPython 3.13 | CPython 3.13 | Linux glibc 2.34+ x86-64 | Details |
Total release size: 3.8 MB
Release files / carbem_python-0.5.0.tar.gz
| Download URL | carbem_python-0.5.0.tar.gz |
|---|---|
| Size | 45.1 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
a27e52f275735b861b528fb0b001a2706796d286df3473dc91342959123df532
|
|
BLAKE2b-256 checksum How to use checksums |
efd794e43cfae89c751ee6d70ceff8148f5399dfff577d773afbf78250ec52cf
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.9.6
|
Release files / carbem_python-0.5.0-cp313-cp313-manylinux_2_34_x86_64.whl
| Download URL | carbem_python-0.5.0-cp313-cp313-manylinux_2_34_x86_64.whl |
|---|---|
| Size | 3.8 MB |
| Tags | CPython 3.13 Linux glibc 2.34+ x86-64 |
|
SHA-256 checksum How to use checksums |
6d2be03830cc8d5998e8f9e83e8e57e3ac47957c6676e677ee99f43427374fb8
|
|
BLAKE2b-256 checksum How to use checksums |
dbcee76e788b036c77312bf05a2fd8ecdf98086c84822785b032b35a9399fae9
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
maturin/1.9.6
|