Skip to main content

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

Project description

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

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 CO2 Signal API. See here for the list of available zones. CO2Signal API
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 CO2 Signal.
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 https://www.co2signal.com/ and get your free API key (for non-commercial use only) for getting the latest carbon intensity from your location in near-real time.
  • 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

💻 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

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

tracarbon-0.5.1.tar.gz (47.8 kB view details)

Uploaded Source

Built Distribution

tracarbon-0.5.1-py3-none-any.whl (53.8 kB view details)

Uploaded Python 3

File details

Details for the file tracarbon-0.5.1.tar.gz.

File metadata

  • Download URL: tracarbon-0.5.1.tar.gz
  • Upload date:
  • Size: 47.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.8.16 Linux/5.15.0-1031-azure

File hashes

Hashes for tracarbon-0.5.1.tar.gz
Algorithm Hash digest
SHA256 887b16c8fe22bfce976c5191b610390c542713ffcc79e0166c7ec8f763e9341f
MD5 aa7961e164c952e33789a24569630b54
BLAKE2b-256 f9fe24ba0e3f204f44d3fa5db919b6251102fbc56c34131de7ca9f0f49e40f18

See more details on using hashes here.

Provenance

File details

Details for the file tracarbon-0.5.1-py3-none-any.whl.

File metadata

  • Download URL: tracarbon-0.5.1-py3-none-any.whl
  • Upload date:
  • Size: 53.8 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.2 CPython/3.8.16 Linux/5.15.0-1031-azure

File hashes

Hashes for tracarbon-0.5.1-py3-none-any.whl
Algorithm Hash digest
SHA256 233cbd145c18e5941693683272d8a5a58e2711a68a0d17b247f85700c8801280
MD5 765d3fc318b3599a0c62f7b726d6e11c
BLAKE2b-256 db9ee93b4112b604b1e2ae794b11e909ca2e2079a5de0f26cfac28defa29303c

See more details on using hashes here.

Provenance

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page