Skip to main content

Tracarbon tracks your device's power consumption and calculates your carbon emissions.

Project description

Alt text

doc pypi example workflow

📌 Overview

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

📦 Where to get it

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

🔌 Devices: energy consumption

Device Description
Mac Battery energy consumption (must be plugged).
Linux Not yet implemented.
Windows Not yet implemented.

📡 Exporters

Exporter Description
Stdout Print the metrics in Stdout.
Datadog Publish the metrics on Datadog.

🗺️ Locations

Location Description Source
European Environment Agency European Emission co2g/kwh for European countries. EEA website
France RTE energy consumption API in real-time. RTE API

🔎 Usage

API

import asyncio

from tracarbon import CarbonEmission, EnergyConsumption, Country
from tracarbon.exporters import Metric, StdoutExporter
from tracarbon.hardwares import HardwareInfo

exporter = StdoutExporter()
metrics = list()
location = asyncio.run(Country.get_location())
energy_consumption = EnergyConsumption.from_platform()
platform = HardwareInfo.get_platform()
metrics.append(
    Metric(
        name="energy_consumption",
        value=energy_consumption.run,
        tags=[f"platform:{platform}", f"location:{location}"]
    )
)
metrics.append(
    Metric(
        name="co2_emission",
        value=CarbonEmission(energy_consumption=energy_consumption, location=location).run,
        tags=[f"platform:{platform}", f"location:{location}"]
    )
)
metrics.append(
    Metric(
        name="hardware_cpu_usage",
        value=HardwareInfo().get_cpu_usage,
        tags=[f"platform:{platform}", f"location:{location}"]
    )
)
metrics.append(
    Metric(
        name="hardware_memory_usage",
        value=HardwareInfo().get_memory_usage,
        tags=[f"platform:{platform}", f"location:{location}"]
    )
)
asyncio.run(exporter.launch_all(metrics=metrics))

CLI

tracarbon run Stdout

🛡️ Licence

https://raw.githubusercontent.com/fvaleye/tracarbon/main/LICENSE.txt[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.1.0.tar.gz (13.7 kB view hashes)

Uploaded Source

Built Distribution

tracarbon-0.1.0-py3-none-any.whl (16.7 kB view hashes)

Uploaded Python 3

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