Tracarbon is a Python library that tracks your device's energy consumption and calculates your carbon emissions.
Project description
📌 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
Devices | Description |
---|---|
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 Provider | Description |
---|---|
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
Exporter | Description |
---|---|
Stdout | Print the metrics in Stdout. |
JSON | Write the metrics in a JSON file. |
Prometheus | Send the metrics to Prometheus. |
Datadog | Send the metrics to Datadog. |
🗺️ Locations
Location | Description | Source |
---|---|---|
Worldwide | Get 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 |
Europe | Static file created from the European Environment Agency Emission for the co2g/kwh in European countries. | EEA website |
AWS | Static file of the AWS Grid emissions factors. | cloud-carbon-coefficients |
⚙️ Configuration
The environment variables can be set from an environment file .env
.
Parameter | Description |
---|---|
TRACARBON_CO2SIGNAL_API_KEY | The api key received from CO2Signal or ElectricityMaps. |
TRACARBON_CO2SIGNAL_URL | The 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_NAME | The prefix to use in all the metrics name. |
TRACARBON_INTERVAL_IN_SECONDS | The interval in seconds to wait between the metrics evaluation. |
TRACARBON_LOG_LEVEL | The level to use for displaying the logs. |
🔎 Usage
Request your API key
- Go to CO2Signal and get your free API key for non-commercial use, or go to ElectricityMaps for commercial use.
- This API is used to retrieve the last known carbon intensity (in gCO2eq/kWh) of electricity consumed in your location.
- Set your API key in the environment variables, in the
.env
file or directly in the configuration. - If you would like to start without an API key, it's possible, the carbon intensity will be loaded statistically from a file.
- Launch Tracarbon 🚀
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
📚 Documentation
The documentation is hosted here: https://fvaleye.github.io/tracarbon/documentation
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
File details
Details for the file tracarbon-0.7.2.tar.gz
.
File metadata
- Download URL: tracarbon-0.7.2.tar.gz
- Upload date:
- Size: 48.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.8.18 Linux/6.5.0-1016-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 665b7f44724d609c6ad65c0e4c59c66c6db410150e2932c93a49043b01a5af19 |
|
MD5 | c06ea27e9090388039cade7fe6465f09 |
|
BLAKE2b-256 | b3bd9e05d809c424915130a95a5ddcd8d0a806c68aca803b1bc1f22d7fbae1c5 |
Provenance
File details
Details for the file tracarbon-0.7.2-py3-none-any.whl
.
File metadata
- Download URL: tracarbon-0.7.2-py3-none-any.whl
- Upload date:
- Size: 55.4 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: poetry/1.8.2 CPython/3.8.18 Linux/6.5.0-1016-azure
File hashes
Algorithm | Hash digest | |
---|---|---|
SHA256 | 51fa856c7a380aa540e3434a410bc71257736a064c04b0693fd8ad584e2e3898 |
|
MD5 | f7e0a40e709e258b7ad68e4e95a73ce3 |
|
BLAKE2b-256 | 4fc3e91490d1d74fe8ac74f94d65e70790ade3c8f4a41ad5dd05a6e2593069fd |