Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
90 commits
Select commit Hold shift + click to select a range
ae8b076
fix: update geolocation fallback API and use static country code mapping
ucodia Mar 16, 2026
d170ce6
build(deps): bump authlib
dependabot[bot] Mar 16, 2026
4bab1fc
Initial plan
Copilot Mar 17, 2026
09724bd
Add support for Apple M4 chip
Copilot Mar 17, 2026
8d362f0
Use a regexp
Mar 18, 2026
37d0795
Add tests
Mar 18, 2026
04bbe31
Add Nordic region emission factors and update emissions logic
Hinetziedacted Jan 24, 2026
3286583
Add comprehensive documentation for Nordic emission factors
Hinetziedacted Jan 26, 2026
cbc7c29
Fix syntax error: add missing closing parenthesis to logger.warning
Hinetziedacted Jan 27, 2026
7f73c58
Add caching for Nordic country energy mix data
Hinetziedacted Jan 27, 2026
264fffb
Refactor emissions.py to use cached Nordic energy mix data
Hinetziedacted Jan 27, 2026
b546a16
Add unit tests for Nordic emissions functionality
Hinetziedacted Jan 27, 2026
4287e43
Update path for Nordic emissions data file
Hinetziedacted Jan 27, 2026
87a8881
Remove leftover json.load code from line 187
Hinetziedacted Jan 27, 2026
28149f7
doc
Jan 30, 2026
94b09d2
lint
Jan 30, 2026
92f6c0e
refacto
Feb 1, 2026
0886040
Update codecarbon/data/private_infra/nordic_emissions.json
benoit-cty Mar 18, 2026
bed88ec
Add tests
Mar 18, 2026
0d0a27c
added amd-smi interface
IlyasMoutawwakil Jan 16, 2024
638883a
fix energy unit
IlyasMoutawwakil Jan 16, 2024
b53fd6a
use counter_resolution instead of hard coding it
IlyasMoutawwakil Jan 16, 2024
154422f
wip : handle AMD and Nvidia at the same time
Jan 26, 2024
8040ecd
added support for amd and nvidia at the same time
IlyasMoutawwakil Jan 29, 2024
067a25a
Fix merge conflict
Feb 18, 2026
a7809c7
Upgrade AMDSMI entries
Feb 18, 2026
5c53442
Breaking change : Watt
Mar 4, 2026
1730b4a
Adastra
Mar 4, 2026
92a34d2
Contributing to a PR
Mar 4, 2026
49580ed
fix merge errors
Mar 4, 2026
b648203
Warn about dual GCD
Mar 5, 2026
2890548
Fix GPU tests
Mar 5, 2026
d538783
Matrix multiplication across all devices
Mar 5, 2026
79ca5f4
Warn about dual GCD
Mar 5, 2026
18d086d
Docs on power estimation
Mar 5, 2026
60e7a8b
Adastra
Mar 5, 2026
18c064e
Docs on power estimation
Mar 5, 2026
ce0488f
Fix start()
Mar 5, 2026
8b04dd7
Fix too much call to _get_gpu_ids
Mar 5, 2026
e96bc7e
MI300
Mar 5, 2026
f730994
Fix _get_power_usage
Mar 5, 2026
cfe82d0
Handle SLURM CPU allocation for default TDP
Mar 5, 2026
c73370a
Exclude MI210 single GCD
Mar 5, 2026
9139444
Remove login sensitive informations
Mar 5, 2026
eb32d66
fix tests
Mar 5, 2026
11217d1
Add tests
Mar 5, 2026
8a2197c
wip: refacto GPU
Mar 7, 2026
4b2a282
fix test
Mar 7, 2026
5b68e7d
Docs and split GPU tests
Mar 7, 2026
855153f
Suggest OffLine mode in the CLI
benoit-cty Mar 8, 2026
2ed1b01
Debug log for PUE
benoit-cty Mar 8, 2026
2d3de44
pre-commit
benoit-cty Mar 8, 2026
94c0887
remove commented lines
benoit-cty Mar 8, 2026
6c4dd8e
review on emit_selection_warning
benoit-cty Mar 8, 2026
fe0e7f6
fix test cli
benoit-cty Mar 8, 2026
a34ddc8
doc
benoit-cty Mar 8, 2026
e0766f2
fix tests/test_gpu_amd.py
benoit-cty Mar 8, 2026
e136272
Add _normalize_gpu_ids
Mar 14, 2026
c03423c
Documentation
Mar 14, 2026
9c7ce5c
Potential fix for code scanning alert no. 44: Clear-text logging of s…
benoit-cty Mar 14, 2026
dae9416
lint
Mar 18, 2026
5124317
build(deps): bump the pip group across 2 directories with 1 update (#…
dependabot[bot] Mar 18, 2026
e67a4ec
build(deps): bump the uv group across 2 directories with 1 update
dependabot[bot] Mar 18, 2026
8a73ded
docs: restructure documentation using Diataxis framework
davidberenstein1957 Mar 18, 2026
eade4f2
docs: align content with Diataxis framework and improve narrative flow
davidberenstein1957 Mar 18, 2026
2a5401f
docs(why.md): add Python and CLI quick-start examples
davidberenstein1957 Mar 18, 2026
6ab27ef
test: add mktestdocs-based tests for documentation code examples
davidberenstein1957 Mar 18, 2026
cb816f6
docs: mark Prometheus/Logfire examples as non-testable and add missin…
davidberenstein1957 Mar 18, 2026
4559542
fix: remove unused import in test_docs_examples.py
davidberenstein1957 Mar 18, 2026
af6354a
fix: enable syntax highlighting in code examples
davidberenstein1957 Mar 19, 2026
95f1700
feat: add Comparing Model Efficiency tutorial with cross-links
davidberenstein1957 Mar 19, 2026
232a878
docs: restructure navigation and add CLI quickstart
davidberenstein1957 Mar 19, 2026
63b81cd
docs: improve Setup section readability and syntax highlighting
davidberenstein1957 Mar 19, 2026
492e4d4
fix: use proper code block formatting for syntax highlighting
davidberenstein1957 Mar 19, 2026
656d47e
fix: use correct code block format without space
davidberenstein1957 Mar 19, 2026
d4a04f6
fix: use comment-based skip marker for code blocks
davidberenstein1957 Mar 19, 2026
27e31a4
docs: add Logging group to How-to Guides
davidberenstein1957 Mar 19, 2026
3eda53a
test: expand documentation coverage with additional files
davidberenstein1957 Mar 19, 2026
4ff4055
feat: add framework-specific how-to guides and reorganize documentation
davidberenstein1957 Mar 19, 2026
fdef79b
docs: add consistent headers and step-by-step structure to all how-to…
davidberenstein1957 Mar 19, 2026
5385195
docs: extract RAPL configuration into how-to guide with clear value p…
davidberenstein1957 Mar 19, 2026
63016ad
docs: add Python section header to Quickstart tutorial for clarity
davidberenstein1957 Mar 19, 2026
3b535fd
docs: add Python section header to homepage quickstart
davidberenstein1957 Mar 19, 2026
ec987f0
docs: remove Python header from Quickstart Step 2
davidberenstein1957 Mar 19, 2026
4ef2df4
docs: move RAPL guide into Deployment group
davidberenstein1957 Mar 19, 2026
d41e700
bump
Mar 18, 2026
1bbf379
Fix workflow bug
Mar 18, 2026
83aa50b
chore: format Python code with black and update uv.lock
davidberenstein1957 Mar 19, 2026
3a5ac71
fix: regenerate uv.lock to resolve scikit-learn dependency
davidberenstein1957 Mar 19, 2026
761408c
chore: apply black formatting from pre-commit hook
davidberenstein1957 Mar 19, 2026
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
7 changes: 1 addition & 6 deletions .github/workflows/test-package.yml
Original file line number Diff line number Diff line change
Expand Up @@ -6,16 +6,11 @@ on:
pull_request:
paths:
- "codecarbon/**"
- "test/**"
- "tests/**"
- "pyproject.toml"
- "uv.lock"
push:
branches: [master]
paths:
- "codecarbon/**"
- "test/**"
- "pyproject.toml"
- "uv.lock"

jobs:
python-test:
Expand Down
14 changes: 13 additions & 1 deletion CONTRIBUTING.md
Original file line number Diff line number Diff line change
Expand Up @@ -258,7 +258,7 @@ flake8...................................................................Passed

If any of the linters/formatters fail, check the difference with `git diff`, add the differences if there is no behavior changes (isort and black might have change some coding style or import order, this is expected it is their job) with `git add` and finally try to commit again `git commit ...`.

You can also run `pre-commit` with `uv run pre-commit run -v` if you have some changes staged but you are not ready yet to commit.
You can also run `pre-commit` with `uv run pre-commit run --all-files` if you have some changes staged but you are not ready yet to commit.


<!-- TOC --><a name="dependencies-management"></a>
Expand Down Expand Up @@ -363,6 +363,18 @@ cp /data/tests/test_package_integrity.py .
pytest test_package_integrity.py
```

### Contribute to a fork branch

When a user open a PR from a fork, we are allowed to push to the fork branch.

If you want to do so, do the following:

```bash
git remote add <user_name> https://github.com/<user_name>/codecarbon.git
git fetch <user_name> <git_branch>
git checkout -b <git_branch> <user_name>/<git_branch>
```

<!-- TOC --><a name="api-and-dashboard"></a>
## API and Dashboard

Expand Down
196 changes: 79 additions & 117 deletions README.md
Original file line number Diff line number Diff line change
@@ -1,167 +1,129 @@
![banner](docs/images/banner.png)

Estimate and track carbon emissions from your computer, quantify and analyze their impact.

CodeCarbon websites:
- [Main website](https://codecarbon.io) to learn why we do this.
- [Dashboard](https://dashboard.codecarbon.io/) to see your emissions, [read the API doc](https://mlco2.github.io/codecarbon/api.html) before.
- [Documentation](https://mlco2.github.io/codecarbon) to learn how to use the package and our methodology.
- [GitHub](https://github.com/mlco2/codecarbon) to look at the source code and contribute.
- [Discord](https://discord.gg/GS9js2XkJR) to chat with us.

<!-- ![Discord Shield](https://discord.com/api/guilds/1090365182909350019/widget.png?style=shield) -->
# Track & reduce CO₂ emissions from your local computing

<br/>

[![](https://img.shields.io/pypi/v/codecarbon?color=024758)](https://pypi.org/project/codecarbon/)
[![DOI](https://zenodo.org/badge/263364731.svg)](https://zenodo.org/badge/latestdoi/263364731)
<!-- [![Downloads](https://static.pepy.tech/badge/codecarbon/month)](https://pepy.tech/project/codecarbon) -->
[![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/mlco2/codecarbon/badge)](https://scorecard.dev/viewer/?uri=github.com/mlco2/codecarbon)
[![codecov](https://codecov.io/gh/mlco2/codecarbon/graph/badge.svg)](https://codecov.io/gh/mlco2/codecarbon)
Estimate and track carbon emissions from your computer, quantify and analyze their impact.

[![](https://img.shields.io/pypi/v/codecarbon?color=024758)](https://pypi.org/project/codecarbon/) [![DOI](https://zenodo.org/badge/263364731.svg)](https://zenodo.org/badge/latestdoi/263364731) [![OpenSSF Scorecard](https://api.scorecard.dev/projects/github.com/mlco2/codecarbon/badge)](https://scorecard.dev/viewer/?uri=github.com/mlco2/codecarbon) [![codecov](https://codecov.io/gh/mlco2/codecarbon/graph/badge.svg)](https://codecov.io/gh/mlco2/codecarbon)

- [About CodeCarbon 💡](#about-codecarbon-)
- [Quickstart 🚀](#quickstart-)
- [Installation 🔧](#installation-)
- [Start to estimate your impact 📏](#start-to-estimate-your-impact-)
- [Without using the online dashboard](#without-using-the-online-dashboard)
- [With the online dashboard](#with-the-online-dashboard)
- [Monitoring your machine 💻](#monitoring-your-machine-)
- [Detecting your hardware 🔍](#detecting-your-hardware-)
- [In your Python code 🐍](#in-your-python-code-)
- [Visualize 📊](#visualize-)
- [Contributing 🤝](#contributing-)
- [How To Cite 📝](#how-to-cite-)
- [Contact 📝](#contact-)
- [Star History](#star-history)
- **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

# About CodeCarbon 💡
> **Tracking GenAI API calls?** CodeCarbon measures emissions from **local computing** (your hardware). To track emissions from remote GenAI API calls (OpenAI, Anthropic, Mistral, etc.), use [**EcoLogits**](https://ecologits.ai/). Both tools are complementary.

**CodeCarbon** started with a quite simple question:
## Installation

**What is the carbon emission impact of my computer program? :shrug:**
```bash
pip install codecarbon
```

We found some global data like "computing currently represents roughly 0.5% of the world’s energy consumption" but nothing on our individual/organisation level impact.
If you use Conda:

At **CodeCarbon**, we believe, along with Niels Bohr, that "Nothing exists until it is measured". So we found a way to estimate how much CO<sub>2</sub> we produce while running our code.
```bash
conda activate your_env
pip install codecarbon
```

*How?*
More installation options: [installation docs](https://docs.codecarbon.io/how-to/installation/).

We created a Python package that estimates your hardware electricity power consumption (GPU + CPU + RAM) and we apply to it the carbon intensity of the region where the computing is done.
## Quickstart (Python)

![calculation Summary](docs/images/calculation.png)
```python
from codecarbon import EmissionsTracker

We explain more about this calculation in the [**Methodology**](https://mlco2.github.io/codecarbon/methodology.html#) section of the documentation.
tracker = EmissionsTracker()
tracker.start()

Our hope is that this package will be used widely for estimating the carbon footprint of computing, and for establishing best practices with regards to the disclosure and reduction of this footprint.
# Your code here

**So ready to "change the world one run at a time"? Let's start with a very quick set up.**
emissions = tracker.stop()
print(f"Emissions: {emissions} kg CO₂")
```

# Quickstart 🚀
[**Learn more** →](https://docs.codecarbon.io/tutorials/first-tracking/)

## Installation 🔧
## Quickstart (CLI)

**From PyPI repository**
```python
pip install codecarbon
```
Track a command without changing your code:

**Using Conda environments**
If you're using Conda, you can install CodeCarbon with pip in your Conda environment:
```bash
conda activate your_env
pip install codecarbon
codecarbon monitor --no-api -- python train.py
```

To see more installation options please refer to the documentation: [**Installation**](https://mlco2.github.io/codecarbon/installation.html#)

## Start to estimate your impact 📏
Detect your hardware:

### Without using the online dashboard

```python
from codecarbon import track_emissions
@track_emissions()
def your_function_to_track():
# your code
```bash
codecarbon detect
```

After running your code, you will find an `emissions.csv` that you can visualize with `carbonboard --filepath="examples/emissions.csv"`.
Full CLI guide: [CLI tutorial](https://docs.codecarbon.io/tutorials/cli/).

### With the online dashboard
## Configuration

To use the online dashboard you need to create an account on [**CodeCarbon Dashboard**](https://dashboard.codecarbon.io/).
Once you have an account, you can create an experiment_id to track your emissions.
You can configure CodeCarbon using:

To get an experiment_id enter:
```python
! codecarbon login
```
You can now store it in a **.codecarbon.config** at the root of your project
```python
[codecarbon]
log_level = DEBUG
save_to_api = True
experiment_id = 2bcbcbb8-850d-4692-af0d-76f6f36d79b2 #the experiment_id you get with init
```
Now you have 2 main options:
- `~/.codecarbon.config` (global)
- `./.codecarbon.config` (project-local)
- `CODECARBON_*` environment variables
- Python arguments (`EmissionsTracker(...)`)

### Monitoring your machine 💻
Configuration precedence and examples: [configuration guide](https://docs.codecarbon.io/how-to/configuration/).

In your command prompt use:
```codecarbon monitor```
The package will track your emissions independently from your code.
## How it works

### Detecting your hardware 🔍
We created a Python package that estimates your hardware electricity power consumption (GPU + CPU + RAM) and we apply to it the carbon intensity of the region where the computing is done.

In your command prompt use:
```codecarbon detect```
The package will detect and print your hardware information (RAM, CPU, GPU).
![calculation Summary](docs/images/calculation.png)

### In your Python code 🐍
```python
from codecarbon import track_emissions
@track_emissions()
def your_function_to_track():
# your code
```
The package will track the emissions generated by the execution of your function.
We explain more about this calculation in the [**Methodology**](https://docs.codecarbon.io/explanation/methodology/) section of the documentation.

There is other ways to use **codecarbon** package, please refer to the documentation to learn more about it: [**Usage**](https://mlco2.github.io/codecarbon/usage.html#)
## Visualize

## Visualize 📊
You can visualize your experiment emissions on the [dashboard](https://dashboard.codecarbon.io/) or locally with [carbonboard](https://docs.codecarbon.io/how-to/visualize/).

You can now visualize your experiment emissions on the [dashboard](https://dashboard.codecarbon.io/).
![dashboard](docs/images/dashboard.png)

## Quick links

| Section | Description |
|---------|-------------|
| [Quickstart](https://docs.codecarbon.io/tutorials/first-tracking/) | Get started in 5 minutes |
| [Installation](https://docs.codecarbon.io/how-to/installation/) | Install CodeCarbon |
| [CLI Tutorial](https://docs.codecarbon.io/tutorials/cli/) | Track emissions from the command line |
| [Python API Tutorial](https://docs.codecarbon.io/tutorials/python-api/) | Track emissions in Python code |
| [Comparing Model Efficiency](https://docs.codecarbon.io/tutorials/comparing-model-efficiency/) | Measure carbon efficiency across ML models |
| [API Reference](https://docs.codecarbon.io/reference/api/) | Full parameter documentation |
| [Examples](https://docs.codecarbon.io/reference/examples/) | Example usage patterns |
| [Methodology](https://docs.codecarbon.io/explanation/methodology/) | How emissions are calculated |
| [EcoLogits](https://ecologits.ai/) | Track emissions from GenAI API calls |

> Hope you enjoy your first steps monitoring your carbon computing impact!
> Thanks to the incredible codecarbon community 💪🏼 a lot more options are available using *codecarbon* including:
> - offline mode
> - cloud mode
> - comet integration...
>
> Please explore the [**Documentation**](https://mlco2.github.io/codecarbon) to learn about it
> If ever what your are looking for is not yet implemented, let us know through the *issues* and even better become one of our 🦸🏼‍♀️🦸🏼‍♂️ contributors! more info 👇🏼
## Links

- [Main website](https://codecarbon.io) to learn why we do this.
- [Dashboard](https://dashboard.codecarbon.io/) to see your emissions.
- [Documentation](https://docs.codecarbon.io/) to learn how to use the package and our methodology.
- [EcoLogits](https://ecologits.ai/) to track emissions from GenAI API calls (OpenAI, Anthropic, etc.).
- [GitHub](https://github.com/mlco2/codecarbon) to look at the source code and contribute.
- [Discord](https://discord.gg/GS9js2XkJR) to chat with us.

# Contributing 🤝
## Contributing

We are hoping that the open-source community will help us edit the code and make it better!

You are welcome to open issues, even suggest solutions and better still contribute the fix/improvement! We can guide you if you're not sure where to start but want to help us out 🥇

In order to contribute a change to our code base, please submit a pull request (PR) via GitHub and someone from our team will go over it and accept it.
You are welcome to open issues, even suggest solutions and better still contribute the fix/improvement! We can guide you if you're not sure where to start but want to help us out.

Check out our [contribution guidelines :arrow_upper_right:](https://github.com/mlco2/codecarbon/blob/master/CONTRIBUTING.md)
Check out our [contribution guidelines](https://github.com/mlco2/codecarbon/blob/master/CONTRIBUTING.md).

Feel free to chat with us on [Discord](https://discord.gg/GS9js2XkJR).

# How To Cite 📝
## Citation

If you find CodeCarbon useful for your research, you can find a citation under a variety of formats on [Zenodo](https://zenodo.org/records/11171501).

Here is a sample for BibTeX:
<details>
<summary>BibTeX</summary>

```tex
@software{benoit_courty_2024_11171501,
author = {Benoit Courty and
Expand Down Expand Up @@ -189,7 +151,7 @@ Here is a sample for BibTeX:
Ziyao Wang and
Armin Catovic and
Marc Alencon and
Michał Stęchły and
Michał Stęchły and
Christian Bauer and
Lucas Otávio N. de Araújo and
JPW and
Expand All @@ -204,16 +166,16 @@ Here is a sample for BibTeX:
}
```

# Contact 📝
</details>

## Contact

Feel free to chat with us on [Discord](https://discord.gg/GS9js2XkJR).

Codecarbon was formerly developed by volunteers from [**Mila**](http://mila.quebec) and the [**DataForGoodFR**](https://twitter.com/dataforgood_fr) community alongside donated professional time of engineers at [**Comet.ml**](https://comet.ml) and [**BCG GAMMA**](https://www.bcg.com/en-nl/beyond-consulting/bcg-gamma/default).

Now CodeCarbon is supported by [**Code Carbon**](https://www.helloasso.com/associations/code-carbon), a French non-profit organization whose mission is to accelerate the development and adoption of CodeCarbon.

## Star History
### Star History

Comparison of the number of stars accumulated by the different Python CO2 emissions projects:
[![Star History Chart](https://api.star-history.com/svg?repos=mlco2/codecarbon,lfwa/carbontracker,sb-ai-lab/Eco2AI,fvaleye/tracarbon,Breakend/experiment-impact-tracker&type=Date)](https://star-history.com/#mlco2/codecarbon&lfwa/carbontracker&sb-ai-lab/Eco2AI&fvaleye/tracarbon&Breakend/experiment-impact-tracker&Date)

Loading