MCPcopy Create free account
hub / github.com/mlco2/codecarbon / CodeCarbonAPIOutput

Class CodeCarbonAPIOutput

codecarbon/output_methods/http.py:36–71  ·  view source on GitHub ↗

Send emissions data to HTTP endpoint

Source from the content-addressed store, hash-verified

34
35
36class CodeCarbonAPIOutput(BaseOutput):
37 """
38 Send emissions data to HTTP endpoint
39 """
40
41 run_id = None
42
43 def __init__(
44 self,
45 endpoint_url: str,
46 experiment_id: str,
47 api_key: str,
48 conf,
49 ):
50 self.endpoint_url: str = endpoint_url
51 self.api = ApiClient(
52 experiment_id=experiment_id,
53 endpoint_url=endpoint_url,
54 api_key=api_key,
55 conf=conf,
56 )
57 self.run_id = self.api.run_id
58
59 def live_out(self, _, delta: EmissionsData):
60 # Called at regular intervals
61 try:
62 self.api.add_emission(dataclasses.asdict(delta))
63 except Exception as e:
64 logger.error(e, exc_info=True)
65
66 def out(self, _, delta: EmissionsData):
67 # Called on exit
68 try:
69 self.api.add_emission(dataclasses.asdict(delta))
70 except Exception as e:
71 logger.error(e, exc_info=True)

Calls

no outgoing calls

Used in the wild real call sites across dependent graphs

searching dependent graphs…