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
- 🐍 FFI Ready: JSON-based API perfect for Python/TypeScript bindings
- 🔧 Flexible Filtering: Filter by regions, services, and resources
Installation
Add this to your Cargo.toml:
[]
= "0.1.0"
Quick Start
Carbem provides two APIs to suit different use cases:
- FFI API: Simple JSON-based functions perfect for Python/TypeScript bindings
- Rust API: Type-safe, idiomatic Rust API for native applications
Python FFI Compatible API (Recommended for Language Bindings)
The library provides a simple 3-parameter function designed for easy Python integration:
use get_emissions;
async
Standalone Rust API
For standalone Rust applications, use the builder pattern with environment variables:
use ;
use ;
async
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
Azure Configuration (AzureConfig)
The Azure provider requires minimal configuration:
use AzureConfig;
let config = AzureConfig ;
Object-Oriented API (Advanced Usage)
use ;
use ;
async
Supported Providers
Microsoft Azure ✅
- Carbon Emission Reports API: Integrated with Azure's Carbon Emission Reports API
- Multiple Report Types: Support for Overall Summary and Monthly Summary reports
- Flexible Date Ranges: Query emissions for custom time periods
- Region Filtering: Filter results by specific Azure regions
- Comprehensive Testing: Full test suite ensuring reliability
Planned Providers
- Amazon Web Services (AWS)
- Google Cloud Platform (GCP)
- Additional providers planned
Roadmap
- Core library infrastructure
- Azure Carbon Emission Reports API integration
- AWS provider implementation
- Google Cloud Platform provider
Testing
The library includes a comprehensive test suite:
# Run all tests
# Run specific Azure provider tests
# Run with output
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
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.