Green Software SDK
Tags: webdev, opensource, github
Published: 2023-02-13 21:45:39

Today I want to see something different of what I have been doing.

Some of you may know that Thoughtworks regularly releases their [Technology Radar](https://www.thoughtworks.com/radar). According to Thoughtworks:

> The Radar is a document that sets out the changes that we think are currently interesting in software development — things in motion that we think you should pay attention to and consider using in your projects. It reflects the idiosyncratic opinion of a bunch of senior technologists and is based on our day-to-day work and experiences. While we think this is interesting, it shouldn’t be taken as a deep market analysis.

![tech radar](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/pipx2rv0smr4lg2fiqlk.png)

The radar basically suggest what techniques, tools, platforms, languages and frameworks one might want to adopt, try, assess or hold implementing in our projects.

I usually take a look at the radar every time it comes out, bookmark whatever calls my attention and then when I have time I can go more into detail.

That is where I found the [Carbon Aware SDK
](https://github.com/Green-Software-Foundation/carbon-aware-sdk) and also recently I got a certification from the Linux foundation on [Green Software](https://www.credly.com/org/the-linux-foundation/badge/lfc131-green-software-for-practitioners), so it was like it called to me.

If you want to reduce your software carbon footprint there are only a few ways to do it.  And the obvious way is to use cleaner energy. 

> You can reduce the carbon footprint of your application by just running things at different times and in different locations. That is because not all electricity is produced in the same way. Most is produced through burning fossil fuels, some is produced using cleaner sources like wind and solar.
> The Carbon Aware SDK helps you build the carbon aware software solutions with the intelligence to use the greenest energy sources. Run them at the greenest time, or in the greenest locations, or both! Capture consistent telemetry and report on your emissions reduction and make informed decisions.

The Carbon Aware SDK has a WebApi and a Command Line Interfave (CLI)

> The WebApi is the preferred deployment within large organisations to centralise management and increase control and auditability, especially in regulated environments. It can be deployed as a container for easy management, and can be deployed alongside an application within a cluster or separately.

![WebApi](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/netn1i8ensctyn8glf28.png)

> The CLI tends to be handy for legacy integration and non-cloud deployments, where a command-line can be used. This tends to be common with legacy DevOps pipelines to drive deployment for integration testing where you can test your deployment in the greenest location.

The Carbon Aware SDK is a project part of the Green Software Foundation (GSF) and the GSF Open Source Working Group. And here you can see the [contribution guide](https://github.com/Green-Software-Foundation/carbon-aware-sdk/blob/dev/CONTRIBUTING.md)

I will try to run the Web API. So first we have to have the prerequisites.

- Docker Desktop/CLI ( instructions for [windows](https://docs.docker.com/desktop/install/windows-install/) or [mac](https://docs.docker.com/desktop/install/mac-install/))
- VSCode (it is recommended to work in a Dev Container and more explanations [here](https://code.visualstudio.com/docs/devcontainers/containers))
- Remote Containers extension for VSCode: https://marketplace.visualstudio.com/items?itemName=ms-vscode-remote.remote-containers

Now we have to follow this steps to get the Web API running

1. Set up the repository `git clone https://github.com/Green-Software-Foundation/carbon-aware-sdk.git`
2. Change directory `cd carbon-aware-sdk`
3. Open VSCode `code .`
4. Open VSCode Command Palette `cmd + shift + P`
5. Run the command `Dev Containers: Open Folder in Container` and select the current folder. You should see that the Dev Container is starting ![starting dev container](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/da0du6bqb7xhzpnmtwjf.png)
6. Change directory to `cd src/CarbonAware.WebApi/src`
7. Run the application `dotnet run` 
![dotnet run](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/6lsd7207ap6t1efsws2e.png)

Here is going to depend on your configuration

> The SDK supports multiple data sources for getting carbon data. At this time, only a JSON file, WattTime and ElectricityMaps are supported.

So I'm going to use the JSON file to get data and I'm going to get it from an example file `/workspaces/carbon-aware-sdk/src/data/data-sources/mycustomfile.json`

![custom json](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/ya7ujjqv526tcwn6pshz.png)

Now that I have my data source I can do a GET request and for this I like Postman and I'm going to use this to make the request `http://localhost:5073/emissions/bylocations/best?location=westus&location=eastus&location=westus3&time=2022-08-23T00%3A00&toTime=2022-08-23T23%3A59`

![get request](https://dev-to-uploads.s3.amazonaws.com/uploads/articles/aqhwt4pcjq4m4uveystu.png)

And there you have it, obviously you can play with it more now that it is working, but I'm telling you this is going to be asked by more and more industries/companies, they will want to know and show their CO2 consumption so that customers can prefer greener options, so having an open source options is really awesome.

That is it for now :-)

Cheers!