Track & reduce CO₂ emissions from your local computing¶
AI can benefit society in many ways, but given the energy needed to support the computing behind AI, these benefits can come at a high environmental price. Use CodeCarbon to track and reduce your CO₂ output from code running on your own hardware. For tracking emissions from remote GenAI API calls (OpenAI, Anthropic, etc.), see EcoLogits.
What we are¶
- A lightweight, easy to use Python library – Simple API to track emissions
- Open source, free & community driven – Built by and for the community
- Effective visual outputs – Put emissions in context with real-world equivalents
Quickstart¶
Python¶
Install CodeCarbon:
pip install codecarbon
Track your code with a context manager:
from codecarbon import EmissionsTracker
tracker = EmissionsTracker()
tracker.start()
# Your code here
emissions = tracker.stop()
print(f"Emissions: {emissions} kg CO₂")
CLI¶
Track any command without changing your code:
codecarbon monitor --no-api -- python train.py
Or detect your hardware:
codecarbon detect
Computer emits CO₂. We started measuring how much¶
A single datacenter can consume large amounts of energy to run computing code. An innovative new tracking tool is designed to measure the climate impact of artificial intelligence.
Kana Lottick, Silvia Susai, Sorelle Friedler, and Jonathan Wilson. Energy Usage Reports: Environmental awareness as part of algorithmic accountability. NeurIPS Workshop on Tackling Climate Change with Machine Learning, 2019.
Quick links¶
| Section | Description |
|---|---|
| Quickstart | Get started in 5 minutes |
| Installation | Install CodeCarbon |
| CLI Tutorial | Track emissions from the command line |
| Python API Tutorial | Track emissions in Python code |
| Comparing Model Efficiency | Measure carbon efficiency across ML models |
| API Reference | Full parameter documentation |
| Framework Examples | Example usage patterns |
| Methodology | How emissions are calculated |
| EcoLogits | Track emissions from GenAI API calls |