Home

Awesome

Tracarbon Logo

example workflow pypi doc licence

πŸ“Œ Overview

Tracarbon is a Python library that tracks your device's energy consumption and calculates your carbon emissions.

It detects your location and your device automatically before starting to export measurements to an exporter. It could be used as a CLI with already defined metrics or programmatically with the API by defining the metrics that you want to have.

Read more in this article.

πŸ“¦ Where to get it

# Install Tracarbon
pip install tracarbon
# Install one or more exporters from the list
pip install 'tracarbon[datadog,prometheus,kubernetes]'

πŸ”Œ Devices: energy consumption

DevicesDescription
Macβœ… Global energy consumption of your Mac (must be plugged into a wall adapter).
Linux⚠️ Only with RAPL. See #1. It works with containers on Kubernetes using the Metric API if available.
Windows❌ Not yet implemented. See #184.
Cloud ProviderDescription
AWSβœ… Use the hardware's usage with the EC2 instances carbon emissions datasets of cloud-carbon-coefficients.
GCP❌ Not yet implemented.
Azure❌ Not yet implemented.

πŸ“‘ Exporters

ExporterDescription
StdoutPrint the metrics in Stdout.
JSONWrite the metrics in a JSON file.
PrometheusSend the metrics to Prometheus.
DatadogSend the metrics to Datadog.

πŸ—ΊοΈ Locations

LocationDescriptionSource
WorldwideGet the latest co2g/kwh in near real-time using the CO2Signal or ElectricityMaps APIs. See here for the list of available zones.CO2Signal API or ElectricityMaps
EuropeStatic file created from the European Environment Agency Emission for the co2g/kwh in European countries.EEA website
AWSStatic file of the AWS Grid emissions factors.cloud-carbon-coefficients

βš™οΈ Configuration

The environment variables can be set from an environment file .env.

ParameterDescription
TRACARBON_CO2SIGNAL_API_KEYThe api key received from CO2Signal or ElectricityMaps.
TRACARBON_CO2SIGNAL_URLThe url of CO2Signal is the default endpoint to retrieve the last known state of the zone, but it could be changed to ElectricityMaps.
TRACARBON_METRIC_PREFIX_NAMEThe prefix to use in all the metrics name.
TRACARBON_INTERVAL_IN_SECONDSThe interval in seconds to wait between the metrics evaluation.
TRACARBON_LOG_LEVELThe level to use for displaying the logs.

πŸ”Ž Usage

Request your API key

Command Line

tracarbon run

API

from tracarbon import TracarbonBuilder, TracarbonConfiguration

configuration = TracarbonConfiguration() # Your configuration
tracarbon = TracarbonBuilder(configuration=configuration).build()
tracarbon.start()
# Your code
tracarbon.stop()

with tracarbon:
    # Your code

report = tracarbon.report() # Get the report

πŸ’» Development

Local: using Poetry

make init
make test-unit

πŸ›‘οΈ Licence

Apache License 2.0

πŸ“š Documentation

The documentation is hosted here: https://fvaleye.github.io/tracarbon/documentation