codecarbon 3.2.5__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 (130) 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.5 → codecarbon-3.2.7}/codecarbon/cli/cli_utils.py +12 -16
  5. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/cli/main.py +21 -12
  6. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/cli/monitor.py +2 -1
  7. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/core/emissions.py +14 -0
  8. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/core/powermetrics.py +1 -1
  9. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/data/hardware/cpu_power.csv +1 -0
  10. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/emissions_tracker.py +46 -5
  11. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/external/hardware.py +4 -4
  12. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/external/ram.py +1 -1
  13. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/output.py +3 -0
  14. codecarbon-3.2.7/codecarbon/output_methods/boamps/__init__.py +25 -0
  15. codecarbon-3.2.7/codecarbon/output_methods/boamps/mapper.py +260 -0
  16. codecarbon-3.2.7/codecarbon/output_methods/boamps/models.py +303 -0
  17. codecarbon-3.2.7/codecarbon/output_methods/boamps/output.py +164 -0
  18. codecarbon-3.2.7/codecarbon.egg-info/PKG-INFO +232 -0
  19. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon.egg-info/SOURCES.txt +6 -0
  20. {codecarbon-3.2.5 → codecarbon-3.2.7}/pyproject.toml +12 -5
  21. codecarbon-3.2.7/tests/test_api_call.py +307 -0
  22. codecarbon-3.2.7/tests/test_boamps_output.py +1172 -0
  23. {codecarbon-3.2.5 → codecarbon-3.2.7}/tests/test_config.py +119 -1
  24. {codecarbon-3.2.5 → codecarbon-3.2.7}/tests/test_core_util.py +25 -10
  25. {codecarbon-3.2.5 → codecarbon-3.2.7}/tests/test_cpu.py +192 -0
  26. {codecarbon-3.2.5 → codecarbon-3.2.7}/tests/test_cpu_load.py +65 -0
  27. codecarbon-3.2.7/tests/test_docs_examples.py +53 -0
  28. {codecarbon-3.2.5 → codecarbon-3.2.7}/tests/test_emissions.py +26 -0
  29. {codecarbon-3.2.5 → codecarbon-3.2.7}/tests/test_emissions_tracker.py +27 -0
  30. codecarbon-3.2.7/tests/test_powermetrics.py +161 -0
  31. {codecarbon-3.2.5 → codecarbon-3.2.7}/tests/test_ram.py +147 -0
  32. codecarbon-3.2.7/tests/test_resource_tracker.py +352 -0
  33. {codecarbon-3.2.5 → codecarbon-3.2.7}/tests/test_unsupported_gpu.py +6 -2
  34. codecarbon-3.2.5/PKG-INFO +0 -267
  35. codecarbon-3.2.5/README.md +0 -219
  36. codecarbon-3.2.5/codecarbon/_version.py +0 -1
  37. codecarbon-3.2.5/codecarbon.egg-info/PKG-INFO +0 -267
  38. codecarbon-3.2.5/tests/test_api_call.py +0 -108
  39. codecarbon-3.2.5/tests/test_powermetrics.py +0 -37
  40. codecarbon-3.2.5/tests/test_resource_tracker.py +0 -43
  41. {codecarbon-3.2.5 → codecarbon-3.2.7}/LICENSE +0 -0
  42. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/__init__.py +0 -0
  43. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/cli/__init__.py +0 -0
  44. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/cli/auth.py +0 -0
  45. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/core/__init__.py +0 -0
  46. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/core/api_client.py +0 -0
  47. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/core/cloud.py +0 -0
  48. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/core/config.py +0 -0
  49. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/core/cpu.py +0 -0
  50. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/core/electricitymaps_api.py +0 -0
  51. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/core/gpu.py +0 -0
  52. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/core/gpu_amd.py +0 -0
  53. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/core/gpu_device.py +0 -0
  54. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/core/gpu_nvidia.py +0 -0
  55. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/core/measure.py +0 -0
  56. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/core/rapl.py +0 -0
  57. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/core/resource_tracker.py +0 -0
  58. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/core/schemas.py +0 -0
  59. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/core/units.py +0 -0
  60. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/core/util.py +0 -0
  61. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/data/canada_provinces.geojson +0 -0
  62. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/data/cloud/impact.csv +0 -0
  63. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/data/hardware/cpu_dataset_builder/amd_cpu_scrapper.py +0 -0
  64. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/data/hardware/cpu_dataset_builder/intel_cpu_scrapper.py +0 -0
  65. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/data/hardware/cpu_dataset_builder/merge_scrapped_cpu_power.py +0 -0
  66. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/data/private_infra/2016/usa_emissions.json +0 -0
  67. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/data/private_infra/2023/canada_energy_mix.json +0 -0
  68. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/data/private_infra/carbon_intensity_per_source.json +0 -0
  69. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/data/private_infra/global_energy_mix.json +0 -0
  70. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/data/private_infra/nordic_emissions.json +0 -0
  71. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/external/__init__.py +0 -0
  72. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/external/geography.py +0 -0
  73. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/external/logger.py +0 -0
  74. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/external/scheduler.py +0 -0
  75. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/external/task.py +0 -0
  76. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/input.py +0 -0
  77. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/lock.py +0 -0
  78. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/output_methods/__init__.py +0 -0
  79. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/output_methods/base_output.py +0 -0
  80. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/output_methods/emissions_data.py +0 -0
  81. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/output_methods/file.py +0 -0
  82. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/output_methods/http.py +0 -0
  83. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/output_methods/logger.py +0 -0
  84. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/output_methods/metrics/__init__.py +0 -0
  85. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/output_methods/metrics/logfire.py +0 -0
  86. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/output_methods/metrics/metric_docs.py +0 -0
  87. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/output_methods/metrics/prometheus.py +0 -0
  88. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/py.typed +0 -0
  89. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/viz/__init__.py +0 -0
  90. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/viz/assets/__init__.py +0 -0
  91. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/viz/assets/car_icon.png +0 -0
  92. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/viz/assets/house_icon.png +0 -0
  93. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/viz/assets/tv_icon.png +0 -0
  94. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/viz/carbonboard.py +0 -0
  95. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/viz/carbonboard_on_api.py +0 -0
  96. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/viz/components.py +0 -0
  97. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/viz/data.py +0 -0
  98. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon/viz/units.py +0 -0
  99. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon.egg-info/dependency_links.txt +0 -0
  100. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon.egg-info/entry_points.txt +0 -0
  101. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon.egg-info/requires.txt +0 -0
  102. {codecarbon-3.2.5 → codecarbon-3.2.7}/codecarbon.egg-info/top_level.txt +0 -0
  103. {codecarbon-3.2.5 → codecarbon-3.2.7}/setup.cfg +0 -0
  104. {codecarbon-3.2.5 → codecarbon-3.2.7}/tests/test_cloud.py +0 -0
  105. {codecarbon-3.2.5 → codecarbon-3.2.7}/tests/test_custom_handler.py +0 -0
  106. {codecarbon-3.2.5 → codecarbon-3.2.7}/tests/test_electricitymaps_api.py +0 -0
  107. {codecarbon-3.2.5 → codecarbon-3.2.7}/tests/test_electricitymaps_backward_compatibility.py +0 -0
  108. {codecarbon-3.2.5 → codecarbon-3.2.7}/tests/test_electricitymaps_config_backward_compatibility.py +0 -0
  109. {codecarbon-3.2.5 → codecarbon-3.2.7}/tests/test_emissions_tracker_constant.py +0 -0
  110. {codecarbon-3.2.5 → codecarbon-3.2.7}/tests/test_emissions_tracker_flush.py +0 -0
  111. {codecarbon-3.2.5 → codecarbon-3.2.7}/tests/test_energy.py +0 -0
  112. {codecarbon-3.2.5 → codecarbon-3.2.7}/tests/test_geography.py +0 -0
  113. {codecarbon-3.2.5 → codecarbon-3.2.7}/tests/test_gpu.py +0 -0
  114. {codecarbon-3.2.5 → codecarbon-3.2.7}/tests/test_gpu_amd.py +0 -0
  115. {codecarbon-3.2.5 → codecarbon-3.2.7}/tests/test_gpu_nvidia.py +0 -0
  116. {codecarbon-3.2.5 → codecarbon-3.2.7}/tests/test_input.py +0 -0
  117. {codecarbon-3.2.5 → codecarbon-3.2.7}/tests/test_lock.py +0 -0
  118. {codecarbon-3.2.5 → codecarbon-3.2.7}/tests/test_logger.py +0 -0
  119. {codecarbon-3.2.5 → codecarbon-3.2.7}/tests/test_logging_output.py +0 -0
  120. {codecarbon-3.2.5 → codecarbon-3.2.7}/tests/test_offline_emissions_tracker.py +0 -0
  121. {codecarbon-3.2.5 → codecarbon-3.2.7}/tests/test_package_integrity.py +0 -0
  122. {codecarbon-3.2.5 → codecarbon-3.2.7}/tests/test_rapl_mmio_scanning.py +0 -0
  123. {codecarbon-3.2.5 → codecarbon-3.2.7}/tests/test_rapl_parameters.py +0 -0
  124. {codecarbon-3.2.5 → codecarbon-3.2.7}/tests/test_rapl_permissions.py +0 -0
  125. {codecarbon-3.2.5 → codecarbon-3.2.7}/tests/test_tracking_inference.py +0 -0
  126. {codecarbon-3.2.5 → codecarbon-3.2.7}/tests/test_utilization_tracking.py +0 -0
  127. {codecarbon-3.2.5 → codecarbon-3.2.7}/tests/test_viz_data.py +0 -0
  128. {codecarbon-3.2.5 → codecarbon-3.2.7}/tests/test_viz_units.py +0 -0
  129. {codecarbon-3.2.5 → codecarbon-3.2.7}/tests/testdata.py +0 -0
  130. {codecarbon-3.2.5 → 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"
@@ -5,6 +5,8 @@ from typing import Optional
5
5
  import typer
6
6
  from rich.prompt import Confirm
7
7
 
8
+ from codecarbon.core.config import get_hierarchical_config
9
+
8
10
 
9
11
  def get_config(path: Optional[Path] = None):
10
12
  p = path or Path.cwd().resolve() / ".codecarbon.config"
@@ -37,22 +39,16 @@ def get_api_endpoint(path: Optional[Path] = None):
37
39
  return "https://api.codecarbon.io"
38
40
 
39
41
 
40
- def get_existing_local_exp_id(path: Optional[Path] = None):
41
- p = path or Path.cwd().resolve() / ".codecarbon.config"
42
- if p.exists():
43
- existing_path = p
44
- else:
45
- existing_path = Path("~/.codecarbon.config").expanduser()
46
- return _get_local_exp_id(existing_path)
47
-
48
-
49
- def _get_local_exp_id(p: Optional[Path] = None):
50
- config = configparser.ConfigParser()
51
- config.read(str(p))
52
- if "codecarbon" in config.sections():
53
- d = dict(config["codecarbon"])
54
- if "experiment_id" in d:
55
- return d["experiment_id"]
42
+ def get_existing_exp_id() -> Optional[str]:
43
+ """
44
+ Return experiment_id resolved from the same hierarchical config strategy
45
+ used by EmissionsTracker (global file, local file, then CODECARBON_* env).
46
+ """
47
+ try:
48
+ conf = get_hierarchical_config()
49
+ except KeyError:
50
+ return None
51
+ return conf.get("experiment_id")
56
52
 
57
53
 
58
54
  def write_local_exp_id(exp_id, path: Optional[Path] = None):
@@ -18,7 +18,7 @@ from codecarbon.cli.cli_utils import (
18
18
  create_new_config_file,
19
19
  get_api_endpoint,
20
20
  get_config,
21
- get_existing_local_exp_id,
21
+ get_existing_exp_id,
22
22
  overwrite_local_config,
23
23
  )
24
24
  from codecarbon.cli.monitor import run_and_monitor
@@ -114,7 +114,8 @@ def api_get():
114
114
  """
115
115
  ex: test-api
116
116
  """
117
- api = ApiClient(endpoint_url=API_URL) # TODO: get endpoint from config
117
+ api_endpoint = get_api_endpoint()
118
+ api = ApiClient(endpoint_url=api_endpoint)
118
119
  api.set_access_token(get_access_token())
119
120
  organizations = api.get_list_organizations()
120
121
  print(organizations)
@@ -123,15 +124,18 @@ def api_get():
123
124
  @codecarbon.command("login", short_help="Login to CodeCarbon")
124
125
  def login():
125
126
  authorize()
126
- api = ApiClient(endpoint_url=API_URL) # TODO: get endpoint from config
127
+ api_endpoint = get_api_endpoint()
128
+ api = ApiClient(endpoint_url=api_endpoint)
127
129
  access_token = get_access_token()
128
130
  api.set_access_token(access_token)
129
131
  api.check_auth()
130
132
 
131
133
 
132
134
  def get_api_key(project_id: str):
135
+ api_endpoint = get_api_endpoint()
136
+ api_endpoint = api_endpoint.rstrip("/")
133
137
  req = requests.post(
134
- f"{API_URL}/projects/{project_id}/api-tokens",
138
+ f"{api_endpoint}/projects/{project_id}/api-tokens",
135
139
  json={
136
140
  "project_id": project_id,
137
141
  "name": "api token",
@@ -306,7 +310,7 @@ def config():
306
310
  overwrite_local_config("api_key", api_key, path=file_path)
307
311
  show_config(file_path)
308
312
  print(
309
- "Consult [link=https://mlco2.github.io/codecarbon/usage.html#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"
310
314
  )
311
315
 
312
316
 
@@ -318,20 +322,25 @@ def config():
318
322
  def monitor(
319
323
  ctx: typer.Context,
320
324
  measure_power_secs: Annotated[
321
- int, typer.Option(help="Interval between two measures.")
325
+ int,
326
+ typer.Option(help="Interval between two measures."),
322
327
  ] = 10,
323
328
  api_call_interval: Annotated[
324
- int, typer.Option(help="Number of measures between API calls.")
329
+ int,
330
+ typer.Option(help="Number of measures between API calls."),
325
331
  ] = 30,
326
332
  api: Annotated[
327
- bool, typer.Option(help="Choose to call Code Carbon API or not")
333
+ bool,
334
+ typer.Option(help="Choose to call Code Carbon API or not"),
328
335
  ] = True,
329
336
  offline: Annotated[bool, typer.Option(help="Run in offline mode")] = False,
330
337
  country_iso_code: Annotated[
331
- str, typer.Option(help="3-letter country ISO code for offline mode")
338
+ str,
339
+ typer.Option(help="3-letter country ISO code for offline mode"),
332
340
  ] = None,
333
341
  region: Annotated[
334
- str, typer.Option(help="Region/province for offline mode")
342
+ str,
343
+ typer.Option(help="Region/province for offline mode"),
335
344
  ] = None,
336
345
  ):
337
346
  """Monitor your machine's carbon emissions."""
@@ -356,10 +365,10 @@ def monitor(
356
365
  "region": region,
357
366
  }
358
367
  else:
359
- experiment_id = get_existing_local_exp_id()
368
+ experiment_id = get_existing_exp_id()
360
369
  if api and experiment_id is None:
361
370
  print(
362
- "ERROR: No experiment id, call 'codecarbon config' first. Or run in offline mode with `--offline --country-iso-code FRA` flag if you don't want to connect to the API.",
371
+ "ERROR: No experiment id. Set CODECARBON_EXPERIMENT_ID, call 'codecarbon config' first, or run in offline mode with `--offline --country-iso-code FRA`.",
363
372
  file=sys.stderr,
364
373
  )
365
374
  raise typer.Exit(1)
@@ -14,7 +14,8 @@ from codecarbon.emissions_tracker import EmissionsTracker
14
14
  def run_and_monitor(
15
15
  ctx: typer.Context,
16
16
  log_level: Annotated[
17
- str, typer.Option(help="Log level (critical, error, warning, info, debug)")
17
+ str,
18
+ typer.Option(help="Log level (critical, error, warning, info, debug)"),
18
19
  ] = "error",
19
20
  **tracker_args,
20
21
  ):
@@ -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://mlco2.github.io/codecarbon/methodology.html#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