codecarbon 3.2.6__tar.gz → 3.2.7__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (127) hide show
  1. codecarbon-3.2.7/PKG-INFO +232 -0
  2. codecarbon-3.2.7/README.md +184 -0
  3. codecarbon-3.2.7/codecarbon/_version.py +1 -0
  4. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/cli/main.py +1 -1
  5. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/core/emissions.py +14 -0
  6. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/core/powermetrics.py +1 -1
  7. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/data/hardware/cpu_power.csv +1 -0
  8. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/emissions_tracker.py +43 -3
  9. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/external/ram.py +1 -1
  10. codecarbon-3.2.7/codecarbon.egg-info/PKG-INFO +232 -0
  11. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon.egg-info/SOURCES.txt +1 -0
  12. {codecarbon-3.2.6 → codecarbon-3.2.7}/pyproject.toml +9 -3
  13. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_config.py +102 -1
  14. codecarbon-3.2.7/tests/test_docs_examples.py +53 -0
  15. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_emissions.py +26 -0
  16. codecarbon-3.2.6/PKG-INFO +0 -267
  17. codecarbon-3.2.6/README.md +0 -219
  18. codecarbon-3.2.6/codecarbon/_version.py +0 -1
  19. codecarbon-3.2.6/codecarbon.egg-info/PKG-INFO +0 -267
  20. {codecarbon-3.2.6 → codecarbon-3.2.7}/LICENSE +0 -0
  21. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/__init__.py +0 -0
  22. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/cli/__init__.py +0 -0
  23. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/cli/auth.py +0 -0
  24. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/cli/cli_utils.py +0 -0
  25. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/cli/monitor.py +0 -0
  26. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/core/__init__.py +0 -0
  27. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/core/api_client.py +0 -0
  28. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/core/cloud.py +0 -0
  29. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/core/config.py +0 -0
  30. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/core/cpu.py +0 -0
  31. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/core/electricitymaps_api.py +0 -0
  32. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/core/gpu.py +0 -0
  33. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/core/gpu_amd.py +0 -0
  34. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/core/gpu_device.py +0 -0
  35. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/core/gpu_nvidia.py +0 -0
  36. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/core/measure.py +0 -0
  37. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/core/rapl.py +0 -0
  38. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/core/resource_tracker.py +0 -0
  39. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/core/schemas.py +0 -0
  40. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/core/units.py +0 -0
  41. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/core/util.py +0 -0
  42. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/data/canada_provinces.geojson +0 -0
  43. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/data/cloud/impact.csv +0 -0
  44. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/data/hardware/cpu_dataset_builder/amd_cpu_scrapper.py +0 -0
  45. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/data/hardware/cpu_dataset_builder/intel_cpu_scrapper.py +0 -0
  46. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/data/hardware/cpu_dataset_builder/merge_scrapped_cpu_power.py +0 -0
  47. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/data/private_infra/2016/usa_emissions.json +0 -0
  48. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/data/private_infra/2023/canada_energy_mix.json +0 -0
  49. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/data/private_infra/carbon_intensity_per_source.json +0 -0
  50. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/data/private_infra/global_energy_mix.json +0 -0
  51. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/data/private_infra/nordic_emissions.json +0 -0
  52. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/external/__init__.py +0 -0
  53. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/external/geography.py +0 -0
  54. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/external/hardware.py +0 -0
  55. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/external/logger.py +0 -0
  56. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/external/scheduler.py +0 -0
  57. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/external/task.py +0 -0
  58. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/input.py +0 -0
  59. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/lock.py +0 -0
  60. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/output.py +0 -0
  61. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/output_methods/__init__.py +0 -0
  62. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/output_methods/base_output.py +0 -0
  63. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/output_methods/boamps/__init__.py +0 -0
  64. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/output_methods/boamps/mapper.py +0 -0
  65. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/output_methods/boamps/models.py +0 -0
  66. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/output_methods/boamps/output.py +0 -0
  67. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/output_methods/emissions_data.py +0 -0
  68. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/output_methods/file.py +0 -0
  69. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/output_methods/http.py +0 -0
  70. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/output_methods/logger.py +0 -0
  71. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/output_methods/metrics/__init__.py +0 -0
  72. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/output_methods/metrics/logfire.py +0 -0
  73. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/output_methods/metrics/metric_docs.py +0 -0
  74. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/output_methods/metrics/prometheus.py +0 -0
  75. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/py.typed +0 -0
  76. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/viz/__init__.py +0 -0
  77. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/viz/assets/__init__.py +0 -0
  78. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/viz/assets/car_icon.png +0 -0
  79. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/viz/assets/house_icon.png +0 -0
  80. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/viz/assets/tv_icon.png +0 -0
  81. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/viz/carbonboard.py +0 -0
  82. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/viz/carbonboard_on_api.py +0 -0
  83. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/viz/components.py +0 -0
  84. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/viz/data.py +0 -0
  85. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon/viz/units.py +0 -0
  86. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon.egg-info/dependency_links.txt +0 -0
  87. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon.egg-info/entry_points.txt +0 -0
  88. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon.egg-info/requires.txt +0 -0
  89. {codecarbon-3.2.6 → codecarbon-3.2.7}/codecarbon.egg-info/top_level.txt +0 -0
  90. {codecarbon-3.2.6 → codecarbon-3.2.7}/setup.cfg +0 -0
  91. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_api_call.py +0 -0
  92. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_boamps_output.py +0 -0
  93. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_cloud.py +0 -0
  94. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_core_util.py +0 -0
  95. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_cpu.py +0 -0
  96. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_cpu_load.py +0 -0
  97. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_custom_handler.py +0 -0
  98. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_electricitymaps_api.py +0 -0
  99. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_electricitymaps_backward_compatibility.py +0 -0
  100. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_electricitymaps_config_backward_compatibility.py +0 -0
  101. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_emissions_tracker.py +0 -0
  102. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_emissions_tracker_constant.py +0 -0
  103. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_emissions_tracker_flush.py +0 -0
  104. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_energy.py +0 -0
  105. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_geography.py +0 -0
  106. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_gpu.py +0 -0
  107. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_gpu_amd.py +0 -0
  108. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_gpu_nvidia.py +0 -0
  109. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_input.py +0 -0
  110. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_lock.py +0 -0
  111. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_logger.py +0 -0
  112. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_logging_output.py +0 -0
  113. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_offline_emissions_tracker.py +0 -0
  114. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_package_integrity.py +0 -0
  115. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_powermetrics.py +0 -0
  116. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_ram.py +0 -0
  117. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_rapl_mmio_scanning.py +0 -0
  118. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_rapl_parameters.py +0 -0
  119. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_rapl_permissions.py +0 -0
  120. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_resource_tracker.py +0 -0
  121. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_tracking_inference.py +0 -0
  122. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_unsupported_gpu.py +0 -0
  123. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_utilization_tracking.py +0 -0
  124. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_viz_data.py +0 -0
  125. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/test_viz_units.py +0 -0
  126. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/testdata.py +0 -0
  127. {codecarbon-3.2.6 → codecarbon-3.2.7}/tests/testutils.py +0 -0
@@ -0,0 +1,232 @@
1
+ Metadata-Version: 2.4
2
+ Name: codecarbon
3
+ Version: 3.2.7
4
+ Author: Mila, DataForGood, BCG GAMMA, Comet.ml, Haverford College
5
+ License-Expression: MIT
6
+ Project-URL: Homepage, https://codecarbon.io/
7
+ Project-URL: Repository, https://github.com/mlco2/codecarbon
8
+ Project-URL: Dashboard, http://dashboard.codecarbon.io/
9
+ Project-URL: Documentation, https://docs.codecarbon.io/
10
+ Project-URL: Issues, https://github.com/mlco2/codecarbon/issues
11
+ Project-URL: Changelog, https://github.com/mlco2/codecarbon/releases
12
+ Classifier: Natural Language :: English
13
+ Classifier: Programming Language :: Python :: 3.10
14
+ Classifier: Programming Language :: Python :: 3.11
15
+ Classifier: Programming Language :: Python :: 3.12
16
+ Classifier: Programming Language :: Python :: 3.13
17
+ Classifier: Programming Language :: Python :: 3.14
18
+ Requires-Python: >=3.10
19
+ Description-Content-Type: text/markdown
20
+ License-File: LICENSE
21
+ Requires-Dist: arrow
22
+ Requires-Dist: authlib>=1.2.1
23
+ Requires-Dist: click
24
+ Requires-Dist: pandas>=2.3.3; python_version >= "3.14"
25
+ Requires-Dist: pandas; python_version < "3.14"
26
+ Requires-Dist: prometheus_client
27
+ Requires-Dist: psutil>=6.0.0
28
+ Requires-Dist: py-cpuinfo
29
+ Requires-Dist: pydantic
30
+ Requires-Dist: nvidia-ml-py
31
+ Requires-Dist: rapidfuzz
32
+ Requires-Dist: requests
33
+ Requires-Dist: questionary
34
+ Requires-Dist: rich
35
+ Requires-Dist: typer
36
+ Requires-Dist: pycountry
37
+ Provides-Extra: carbonboard
38
+ Requires-Dist: dash; extra == "carbonboard"
39
+ Requires-Dist: dash_bootstrap_components>1.0.0; extra == "carbonboard"
40
+ Requires-Dist: fire; extra == "carbonboard"
41
+ Provides-Extra: viz-legacy
42
+ Requires-Dist: dash; extra == "viz-legacy"
43
+ Requires-Dist: dash_bootstrap_components>1.0.0; extra == "viz-legacy"
44
+ Requires-Dist: fire; extra == "viz-legacy"
45
+ Provides-Extra: amdsmi
46
+ Requires-Dist: amdsmi>=6.0.0; extra == "amdsmi"
47
+ Dynamic: license-file
48
+
49
+ ![banner](docs/images/banner.png)
50
+
51
+ # Track & reduce CO₂ emissions from your local computing
52
+
53
+ Estimate and track carbon emissions from your computer, quantify and analyze their impact.
54
+
55
+ [![](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) [![Discord](https://img.shields.io/badge/Discord-Join%20Community-7289da?logo=discord&logoColor=white)](https://discord.gg/GS9js2XkJR)
56
+
57
+ - **A lightweight, easy to use Python library** – Simple API to track emissions
58
+ - **Open source, free & community driven** – Built by and for the community
59
+ - **Effective visual outputs** – Put emissions in context with real-world equivalents
60
+
61
+ > **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.
62
+
63
+ > **Join the community!** Have questions, want to share your work, or contribute? Join us on [**Discord**](https://discord.gg/GS9js2XkJR) – we're here to help and excited to hear from you!
64
+
65
+ ## Installation
66
+
67
+ ```bash
68
+ pip install codecarbon
69
+ ```
70
+
71
+ If you use Conda:
72
+
73
+ ```bash
74
+ conda activate your_env
75
+ pip install codecarbon
76
+ ```
77
+
78
+ More installation options: [installation docs](https://docs.codecarbon.io/latest/how-to/installation/).
79
+
80
+ ## Quickstart (Python)
81
+
82
+ ```python
83
+ from codecarbon import EmissionsTracker
84
+
85
+ tracker = EmissionsTracker()
86
+ tracker.start()
87
+
88
+ # Your code here
89
+
90
+ emissions = tracker.stop()
91
+ print(f"Emissions: {emissions} kg CO₂")
92
+ ```
93
+
94
+ [**Learn more** →](https://docs.codecarbon.io/latest/tutorials/first-tracking/)
95
+
96
+ ## Quickstart (CLI)
97
+
98
+ Track a command without changing your code:
99
+
100
+ ```bash
101
+ codecarbon monitor --no-api -- python train.py
102
+ ```
103
+
104
+ Detect your hardware:
105
+
106
+ ```bash
107
+ codecarbon detect
108
+ ```
109
+
110
+ Full CLI guide: [CLI tutorial](https://docs.codecarbon.io/latest/tutorials/cli/).
111
+
112
+ ## Configuration
113
+
114
+ You can configure CodeCarbon using:
115
+
116
+ - `~/.codecarbon.config` (global)
117
+ - `./.codecarbon.config` (project-local)
118
+ - `CODECARBON_*` environment variables
119
+ - Python arguments (`EmissionsTracker(...)`)
120
+
121
+ Configuration precedence and examples: [configuration guide](https://docs.codecarbon.io/latest/how-to/configuration/).
122
+
123
+ ## How it works
124
+
125
+ 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.
126
+
127
+ ![calculation Summary](docs/images/calculation.png)
128
+
129
+ We explain more about this calculation in the [**Methodology**](https://docs.codecarbon.io/latest/explanation/methodology/) section of the documentation.
130
+
131
+ ## Visualize
132
+
133
+ You can visualize your experiment emissions on the [dashboard](https://dashboard.codecarbon.io/) or locally with [carbonboard](https://docs.codecarbon.io/latest/how-to/visualize/).
134
+
135
+ ![dashboard](docs/images/dashboard.png)
136
+
137
+ ## Quick links
138
+
139
+ | Section | Description |
140
+ |---------|-------------|
141
+ | [Quickstart](https://docs.codecarbon.io/latest/tutorials/first-tracking/) | Get started in 5 minutes |
142
+ | [Installation](https://docs.codecarbon.io/latest/how-to/installation/) | Install CodeCarbon |
143
+ | [CLI Tutorial](https://docs.codecarbon.io/latest/tutorials/cli/) | Track emissions from the command line |
144
+ | [Python API Tutorial](https://docs.codecarbon.io/latest/tutorials/python-api/) | Track emissions in Python code |
145
+ | [Comparing Model Efficiency](https://docs.codecarbon.io/latest/tutorials/comparing-model-efficiency/) | Measure carbon efficiency across ML models |
146
+ | [API Reference](https://docs.codecarbon.io/latest/reference/api/) | Full parameter documentation |
147
+ | [Framework examples (scikit-learn)](https://docs.codecarbon.io/latest/how-to/scikit-learn/) | Task-oriented ML framework examples |
148
+ | [Methodology](https://docs.codecarbon.io/latest/explanation/methodology/) | How emissions are calculated |
149
+ | [EcoLogits](https://ecologits.ai/) | Track emissions from GenAI API calls |
150
+ | [Discord Community](https://discord.gg/GS9js2XkJR) | Chat with us and the community |
151
+
152
+ ## Links
153
+
154
+ - [Main website](https://codecarbon.io) to learn why we do this.
155
+ - [Dashboard](https://dashboard.codecarbon.io/) to see your emissions.
156
+ - [Documentation](https://docs.codecarbon.io/) to learn how to use the package and our methodology.
157
+ - [EcoLogits](https://ecologits.ai/) to track emissions from GenAI API calls (OpenAI, Anthropic, etc.).
158
+ - [GitHub](https://github.com/mlco2/codecarbon) to look at the source code and contribute.
159
+ - [Discord](https://discord.gg/GS9js2XkJR) to chat with us.
160
+
161
+ ## Contributing
162
+
163
+ We are hoping that the open-source community will help us edit the code and make it better!
164
+
165
+ 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.
166
+
167
+ Check out our [contribution guidelines](https://github.com/mlco2/codecarbon/blob/master/CONTRIBUTING.md).
168
+
169
+ Feel free to chat with us on [Discord](https://discord.gg/GS9js2XkJR).
170
+
171
+ ## Citation
172
+
173
+ 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).
174
+
175
+ <details>
176
+ <summary>BibTeX</summary>
177
+
178
+ ```tex
179
+ @software{benoit_courty_2024_11171501,
180
+ author = {Benoit Courty and
181
+ Victor Schmidt and
182
+ Sasha Luccioni and
183
+ Goyal-Kamal and
184
+ MarionCoutarel and
185
+ Boris Feld and
186
+ Jérémy Lecourt and
187
+ LiamConnell and
188
+ Amine Saboni and
189
+ Inimaz and
190
+ supatomic and
191
+ Mathilde Léval and
192
+ Luis Blanche and
193
+ Alexis Cruveiller and
194
+ ouminasara and
195
+ Franklin Zhao and
196
+ Aditya Joshi and
197
+ Alexis Bogroff and
198
+ Hugues de Lavoreille and
199
+ Niko Laskaris and
200
+ Edoardo Abati and
201
+ Douglas Blank and
202
+ Ziyao Wang and
203
+ Armin Catovic and
204
+ Marc Alencon and
205
+ Michał Stęchły and
206
+ Christian Bauer and
207
+ Lucas Otávio N. de Araújo and
208
+ JPW and
209
+ MinervaBooks},
210
+ title = {mlco2/codecarbon: v2.4.1},
211
+ month = may,
212
+ year = 2024,
213
+ publisher = {Zenodo},
214
+ version = {v2.4.1},
215
+ doi = {10.5281/zenodo.11171501},
216
+ url = {https://doi.org/10.5281/zenodo.11171501}
217
+ }
218
+ ```
219
+
220
+ </details>
221
+
222
+ ## Contact
223
+
224
+ Feel free to chat with us on [Discord](https://discord.gg/GS9js2XkJR).
225
+
226
+ 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).
227
+
228
+ 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.
229
+
230
+ ### Star History
231
+
232
+ [![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)
@@ -0,0 +1,184 @@
1
+ ![banner](docs/images/banner.png)
2
+
3
+ # Track & reduce CO₂ emissions from your local computing
4
+
5
+ Estimate and track carbon emissions from your computer, quantify and analyze their impact.
6
+
7
+ [![](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) [![Discord](https://img.shields.io/badge/Discord-Join%20Community-7289da?logo=discord&logoColor=white)](https://discord.gg/GS9js2XkJR)
8
+
9
+ - **A lightweight, easy to use Python library** – Simple API to track emissions
10
+ - **Open source, free & community driven** – Built by and for the community
11
+ - **Effective visual outputs** – Put emissions in context with real-world equivalents
12
+
13
+ > **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.
14
+
15
+ > **Join the community!** Have questions, want to share your work, or contribute? Join us on [**Discord**](https://discord.gg/GS9js2XkJR) – we're here to help and excited to hear from you!
16
+
17
+ ## Installation
18
+
19
+ ```bash
20
+ pip install codecarbon
21
+ ```
22
+
23
+ If you use Conda:
24
+
25
+ ```bash
26
+ conda activate your_env
27
+ pip install codecarbon
28
+ ```
29
+
30
+ More installation options: [installation docs](https://docs.codecarbon.io/latest/how-to/installation/).
31
+
32
+ ## Quickstart (Python)
33
+
34
+ ```python
35
+ from codecarbon import EmissionsTracker
36
+
37
+ tracker = EmissionsTracker()
38
+ tracker.start()
39
+
40
+ # Your code here
41
+
42
+ emissions = tracker.stop()
43
+ print(f"Emissions: {emissions} kg CO₂")
44
+ ```
45
+
46
+ [**Learn more** →](https://docs.codecarbon.io/latest/tutorials/first-tracking/)
47
+
48
+ ## Quickstart (CLI)
49
+
50
+ Track a command without changing your code:
51
+
52
+ ```bash
53
+ codecarbon monitor --no-api -- python train.py
54
+ ```
55
+
56
+ Detect your hardware:
57
+
58
+ ```bash
59
+ codecarbon detect
60
+ ```
61
+
62
+ Full CLI guide: [CLI tutorial](https://docs.codecarbon.io/latest/tutorials/cli/).
63
+
64
+ ## Configuration
65
+
66
+ You can configure CodeCarbon using:
67
+
68
+ - `~/.codecarbon.config` (global)
69
+ - `./.codecarbon.config` (project-local)
70
+ - `CODECARBON_*` environment variables
71
+ - Python arguments (`EmissionsTracker(...)`)
72
+
73
+ Configuration precedence and examples: [configuration guide](https://docs.codecarbon.io/latest/how-to/configuration/).
74
+
75
+ ## How it works
76
+
77
+ 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.
78
+
79
+ ![calculation Summary](docs/images/calculation.png)
80
+
81
+ We explain more about this calculation in the [**Methodology**](https://docs.codecarbon.io/latest/explanation/methodology/) section of the documentation.
82
+
83
+ ## Visualize
84
+
85
+ You can visualize your experiment emissions on the [dashboard](https://dashboard.codecarbon.io/) or locally with [carbonboard](https://docs.codecarbon.io/latest/how-to/visualize/).
86
+
87
+ ![dashboard](docs/images/dashboard.png)
88
+
89
+ ## Quick links
90
+
91
+ | Section | Description |
92
+ |---------|-------------|
93
+ | [Quickstart](https://docs.codecarbon.io/latest/tutorials/first-tracking/) | Get started in 5 minutes |
94
+ | [Installation](https://docs.codecarbon.io/latest/how-to/installation/) | Install CodeCarbon |
95
+ | [CLI Tutorial](https://docs.codecarbon.io/latest/tutorials/cli/) | Track emissions from the command line |
96
+ | [Python API Tutorial](https://docs.codecarbon.io/latest/tutorials/python-api/) | Track emissions in Python code |
97
+ | [Comparing Model Efficiency](https://docs.codecarbon.io/latest/tutorials/comparing-model-efficiency/) | Measure carbon efficiency across ML models |
98
+ | [API Reference](https://docs.codecarbon.io/latest/reference/api/) | Full parameter documentation |
99
+ | [Framework examples (scikit-learn)](https://docs.codecarbon.io/latest/how-to/scikit-learn/) | Task-oriented ML framework examples |
100
+ | [Methodology](https://docs.codecarbon.io/latest/explanation/methodology/) | How emissions are calculated |
101
+ | [EcoLogits](https://ecologits.ai/) | Track emissions from GenAI API calls |
102
+ | [Discord Community](https://discord.gg/GS9js2XkJR) | Chat with us and the community |
103
+
104
+ ## Links
105
+
106
+ - [Main website](https://codecarbon.io) to learn why we do this.
107
+ - [Dashboard](https://dashboard.codecarbon.io/) to see your emissions.
108
+ - [Documentation](https://docs.codecarbon.io/) to learn how to use the package and our methodology.
109
+ - [EcoLogits](https://ecologits.ai/) to track emissions from GenAI API calls (OpenAI, Anthropic, etc.).
110
+ - [GitHub](https://github.com/mlco2/codecarbon) to look at the source code and contribute.
111
+ - [Discord](https://discord.gg/GS9js2XkJR) to chat with us.
112
+
113
+ ## Contributing
114
+
115
+ We are hoping that the open-source community will help us edit the code and make it better!
116
+
117
+ 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.
118
+
119
+ Check out our [contribution guidelines](https://github.com/mlco2/codecarbon/blob/master/CONTRIBUTING.md).
120
+
121
+ Feel free to chat with us on [Discord](https://discord.gg/GS9js2XkJR).
122
+
123
+ ## Citation
124
+
125
+ 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).
126
+
127
+ <details>
128
+ <summary>BibTeX</summary>
129
+
130
+ ```tex
131
+ @software{benoit_courty_2024_11171501,
132
+ author = {Benoit Courty and
133
+ Victor Schmidt and
134
+ Sasha Luccioni and
135
+ Goyal-Kamal and
136
+ MarionCoutarel and
137
+ Boris Feld and
138
+ Jérémy Lecourt and
139
+ LiamConnell and
140
+ Amine Saboni and
141
+ Inimaz and
142
+ supatomic and
143
+ Mathilde Léval and
144
+ Luis Blanche and
145
+ Alexis Cruveiller and
146
+ ouminasara and
147
+ Franklin Zhao and
148
+ Aditya Joshi and
149
+ Alexis Bogroff and
150
+ Hugues de Lavoreille and
151
+ Niko Laskaris and
152
+ Edoardo Abati and
153
+ Douglas Blank and
154
+ Ziyao Wang and
155
+ Armin Catovic and
156
+ Marc Alencon and
157
+ Michał Stęchły and
158
+ Christian Bauer and
159
+ Lucas Otávio N. de Araújo and
160
+ JPW and
161
+ MinervaBooks},
162
+ title = {mlco2/codecarbon: v2.4.1},
163
+ month = may,
164
+ year = 2024,
165
+ publisher = {Zenodo},
166
+ version = {v2.4.1},
167
+ doi = {10.5281/zenodo.11171501},
168
+ url = {https://doi.org/10.5281/zenodo.11171501}
169
+ }
170
+ ```
171
+
172
+ </details>
173
+
174
+ ## Contact
175
+
176
+ Feel free to chat with us on [Discord](https://discord.gg/GS9js2XkJR).
177
+
178
+ 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).
179
+
180
+ 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.
181
+
182
+ ### Star History
183
+
184
+ [![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)
@@ -0,0 +1 @@
1
+ __version__ = "3.2.7"
@@ -310,7 +310,7 @@ def config():
310
310
  overwrite_local_config("api_key", api_key, path=file_path)
311
311
  show_config(file_path)
312
312
  print(
313
- "Consult [link=https://docs.codecarbon.io/latest/getting-started/usage/#configuration]configuration documentation[/link] for more configuration options"
313
+ "Consult [link=https://docs.codecarbon.io/latest/how-to/configuration/]configuration documentation[/link] for more configuration options"
314
314
  )
315
315
 
316
316
 
@@ -25,6 +25,7 @@ class Emissions:
25
25
  co2_signal_api_token: Optional[
26
26
  str
27
27
  ] = None, # Deprecated, for backward compatibility
28
+ force_carbon_intensity_g_co2e_kwh: Optional[float] = None,
28
29
  ):
29
30
  self._data_source = data_source
30
31
 
@@ -38,6 +39,7 @@ class Emissions:
38
39
  electricitymaps_api_token = co2_signal_api_token
39
40
 
40
41
  self._electricitymaps_api_token = electricitymaps_api_token
42
+ self._force_carbon_intensity_g_co2e_kwh = force_carbon_intensity_g_co2e_kwh
41
43
 
42
44
  def get_cloud_emissions(
43
45
  self, energy: Energy, cloud: CloudMetadata, geo: GeoMetadata = None
@@ -50,6 +52,12 @@ class Emissions:
50
52
  :return: CO2 emissions in kg
51
53
  """
52
54
 
55
+ if self._force_carbon_intensity_g_co2e_kwh is not None:
56
+ logger.info(
57
+ f"Using forced carbon intensity for cloud emissions: {self._force_carbon_intensity_g_co2e_kwh} gCO2e/kWh"
58
+ )
59
+ return energy.kWh * (self._force_carbon_intensity_g_co2e_kwh / 1000.0)
60
+
53
61
  df: pd.DataFrame = self._data_source.get_cloud_emissions_data()
54
62
  try:
55
63
  emissions_per_kWh: EmissionsPerKWh = EmissionsPerKWh.from_g_per_kWh(
@@ -138,6 +146,12 @@ class Emissions:
138
146
  :param geo: Country and region metadata
139
147
  :return: CO2 emissions in kg
140
148
  """
149
+ if self._force_carbon_intensity_g_co2e_kwh is not None:
150
+ logger.debug(
151
+ f"Using forced carbon intensity for private infrastructure emissions: {self._force_carbon_intensity_g_co2e_kwh} gCO2e/kWh"
152
+ )
153
+ return energy.kWh * (self._force_carbon_intensity_g_co2e_kwh / 1000.0)
154
+
141
155
  if self._electricitymaps_api_token:
142
156
  try:
143
157
  emissions = electricitymaps_api.get_emissions(
@@ -58,7 +58,7 @@ def _has_powermetrics_sudo() -> bool:
58
58
  """Not using PowerMetrics, sudo password prompt detected.
59
59
  If you want to enable Powermetrics please modify your sudoers file
60
60
  as described in :
61
- https://docs.codecarbon.io/latest/introduction/methodology/#power-usage
61
+ https://docs.codecarbon.io/latest/explanation/methodology/#power-usage
62
62
  """
63
63
  )
64
64
  return False
@@ -2256,6 +2256,7 @@ Intel Core Solo T1400,27
2256
2256
  Intel Core Solo ULV U1300,5
2257
2257
  Intel Core Solo ULV U1400,5
2258
2258
  Intel Core Solo ULV U1500,5
2259
+ Intel Core Ultra 7 155H,28
2259
2260
  Intel Core Ultra 7 165H,28
2260
2261
  Intel Core Ultra 7 265H,28
2261
2262
  Intel Core i3-1000G1,12
@@ -195,6 +195,7 @@ class BaseEmissionsTracker(ABC):
195
195
  force_ram_power: Optional[int] = _sentinel,
196
196
  pue: Optional[float] = _sentinel,
197
197
  wue: Optional[float] = _sentinel,
198
+ force_carbon_intensity_g_co2e_kwh: Optional[float] = _sentinel,
198
199
  force_mode_cpu_load: Optional[bool] = _sentinel,
199
200
  allow_multiple_runs: Optional[bool] = _sentinel,
200
201
  rapl_include_dram: Optional[bool] = _sentinel,
@@ -259,11 +260,13 @@ class BaseEmissionsTracker(ABC):
259
260
  then RAM power (W) = Number of RAM Slots × 5 Watts.
260
261
  :param pue: PUE (Power Usage Effectiveness) of the data center where the
261
262
  experiment is being run.
263
+ :param wue: WUE (Water Usage Effectiveness) of the data center. Units of L/kWh:
264
+ litres of water consumed per kilowatt-hour of electricity consumed.
265
+ :param force_carbon_intensity_g_co2e_kwh: Override grid carbon intensity
266
+ in gCO2e/kWh for emissions calculations.
262
267
  :param force_mode_cpu_load: Force the addition of a CPU in MODE_CPU_LOAD
263
268
  :param allow_multiple_runs: Allow multiple CodeCarbon instances on the same machine.
264
269
  Defaults to True since v3 (was False in v2).
265
- :param wue: WUE (Water Usage Effectiveness) of the data center. Units of L/kWh:
266
- litres of water consumed per kilowatt-hour of electricity consumed.
267
270
  :param rapl_include_dram: Include DRAM (memory) power in RAPL measurements on Linux,
268
271
  defaults to False. When True, measures CPU package + DRAM.
269
272
  Only affects systems where RAPL exposes separate DRAM domains.
@@ -276,6 +279,31 @@ class BaseEmissionsTracker(ABC):
276
279
 
277
280
  # logger.info("base tracker init")
278
281
  self._external_conf = get_hierarchical_config()
282
+ self._set_from_conf(
283
+ force_carbon_intensity_g_co2e_kwh,
284
+ "force_carbon_intensity_g_co2e_kwh",
285
+ None,
286
+ float,
287
+ )
288
+ parsed_intensity = None
289
+ if self._force_carbon_intensity_g_co2e_kwh is not None:
290
+ try:
291
+ value = float(self._force_carbon_intensity_g_co2e_kwh)
292
+ if value >= 0:
293
+ parsed_intensity = value
294
+ else:
295
+ logger.warning(
296
+ f"Invalid value for force_carbon_intensity_g_co2e_kwh: '{self._force_carbon_intensity_g_co2e_kwh}'. "
297
+ "It must be a non-negative number. Using default calculation methods."
298
+ )
299
+ except (ValueError, TypeError):
300
+ logger.warning(
301
+ f"Invalid value for force_carbon_intensity_g_co2e_kwh: '{self._force_carbon_intensity_g_co2e_kwh}'. "
302
+ "It must be a numeric value. Using default calculation methods."
303
+ )
304
+ self._force_carbon_intensity_g_co2e_kwh = parsed_intensity
305
+ self._conf["force_carbon_intensity_g_co2e_kwh"] = parsed_intensity
306
+ self.force_carbon_intensity_g_co2e_kwh = parsed_intensity
279
307
  self._set_from_conf(allow_multiple_runs, "allow_multiple_runs", True, bool)
280
308
  if self._allow_multiple_runs:
281
309
  logger.warning(
@@ -353,6 +381,11 @@ class BaseEmissionsTracker(ABC):
353
381
  experiment_id, "experiment_id", "5b0fa12a-3dd7-45bb-9766-cc326314d9f1"
354
382
  )
355
383
 
384
+ if self.force_carbon_intensity_g_co2e_kwh is not None:
385
+ logger.info(
386
+ f"Using forced carbon intensity: {self.force_carbon_intensity_g_co2e_kwh} gCO2e/kWh."
387
+ )
388
+
356
389
  assert self._tracking_mode in ["machine", "process"]
357
390
  set_logger_level(self._log_level)
358
391
  set_logger_format(self._logger_preamble)
@@ -446,7 +479,9 @@ class BaseEmissionsTracker(ABC):
446
479
  self._conf["provider"] = cloud.provider
447
480
 
448
481
  self._emissions: Emissions = Emissions(
449
- self._data_source, self._electricitymaps_api_token
482
+ self._data_source,
483
+ self._electricitymaps_api_token,
484
+ force_carbon_intensity_g_co2e_kwh=self.force_carbon_intensity_g_co2e_kwh,
450
485
  )
451
486
  self._init_output_methods(api_key=self._api_key)
452
487
 
@@ -1310,6 +1345,7 @@ def track_emissions(
1310
1345
  force_ram_power: Optional[int] = _sentinel,
1311
1346
  pue: Optional[float] = _sentinel,
1312
1347
  wue: Optional[float] = _sentinel,
1348
+ force_carbon_intensity_g_co2e_kwh: Optional[float] = _sentinel,
1313
1349
  allow_multiple_runs: Optional[bool] = _sentinel,
1314
1350
  rapl_include_dram: Optional[bool] = _sentinel,
1315
1351
  rapl_prefer_psys: Optional[bool] = _sentinel,
@@ -1392,6 +1428,8 @@ def track_emissions(
1392
1428
  :param pue: PUE (Power Usage Effectiveness) of the data center.
1393
1429
  :param wue: WUE (Water Usage Effectiveness) of the data center. Units of L/kWh:
1394
1430
  litres of water consumed per kilowatt-hour of electricity consumed.
1431
+ :param force_carbon_intensity_g_co2e_kwh: Override grid carbon intensity
1432
+ in gCO2e/kWh for emissions calculations.
1395
1433
  :param rapl_include_dram: Include DRAM in RAPL measurements on Linux (default: False).
1396
1434
  When True, measures CPU package + DRAM.
1397
1435
  :param rapl_prefer_psys: Prefer psys over package domains for RAPL on Linux
@@ -1447,6 +1485,7 @@ def track_emissions(
1447
1485
  force_ram_power=force_ram_power,
1448
1486
  pue=pue,
1449
1487
  wue=wue,
1488
+ force_carbon_intensity_g_co2e_kwh=force_carbon_intensity_g_co2e_kwh,
1450
1489
  allow_multiple_runs=allow_multiple_runs,
1451
1490
  rapl_include_dram=rapl_include_dram,
1452
1491
  rapl_prefer_psys=rapl_prefer_psys,
@@ -1481,6 +1520,7 @@ def track_emissions(
1481
1520
  force_ram_power=force_ram_power,
1482
1521
  pue=pue,
1483
1522
  wue=wue,
1523
+ force_carbon_intensity_g_co2e_kwh=force_carbon_intensity_g_co2e_kwh,
1484
1524
  allow_multiple_runs=allow_multiple_runs,
1485
1525
  rapl_include_dram=rapl_include_dram,
1486
1526
  rapl_prefer_psys=rapl_prefer_psys,
@@ -24,7 +24,7 @@ class RAM(BaseHardware):
24
24
  In V3, we need to improve the accuracy of the RAM power estimation.
25
25
  Because the power consumption of RAM is not linear with the amount of memory used,
26
26
 
27
- See https://docs.codecarbon.io/latest/introduction/methodology/#ram for details on the RAM
27
+ See https://docs.codecarbon.io/latest/explanation/methodology/#ram for details on the RAM
28
28
  power estimation methodology.
29
29
 
30
30
  """