{"id":26470694,"url":"https://github.com/kristofferandreasen/tomorrow-electricity-api-dotnet-client","last_synced_at":"2025-09-25T16:34:41.647Z","repository":{"id":40308197,"uuid":"303076212","full_name":"kristofferandreasen/tomorrow-electricity-api-dotnet-client","owner":"kristofferandreasen","description":"A .NET Rest client for the Tomorrow electricity map API using C# and .NET Core ⚡ Understand and optimize the carbon footprint of electricity.","archived":false,"fork":false,"pushed_at":"2025-05-13T19:56:12.000Z","size":830,"stargazers_count":2,"open_issues_count":13,"forks_count":0,"subscribers_count":2,"default_branch":"master","last_synced_at":"2025-05-13T21:03:18.771Z","etag":null,"topics":["c-sharp","client","csharp","dependency-injection","dotnet","dotnet-core","electricity","rest-api","tomorrow"],"latest_commit_sha":null,"homepage":"https://www.nuget.org/packages/ElectricityMap.DotNet.Client/","language":"C#","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/kristofferandreasen.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":"CONTRIBUTING.md","funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null,"zenodo":null}},"created_at":"2020-10-11T08:34:24.000Z","updated_at":"2023-06-02T09:07:28.000Z","dependencies_parsed_at":"2023-01-21T04:17:47.875Z","dependency_job_id":"758ddd82-0a20-4874-ad02-74a0ff766769","html_url":"https://github.com/kristofferandreasen/tomorrow-electricity-api-dotnet-client","commit_stats":{"total_commits":128,"total_committers":3,"mean_commits":"42.666666666666664","dds":0.515625,"last_synced_commit":"35dd553cb34eab9bb5cf6cf22a46ef05ab2206ac"},"previous_names":[],"tags_count":10,"template":false,"template_full_name":null,"purl":"pkg:github/kristofferandreasen/tomorrow-electricity-api-dotnet-client","repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristofferandreasen%2Ftomorrow-electricity-api-dotnet-client","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristofferandreasen%2Ftomorrow-electricity-api-dotnet-client/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristofferandreasen%2Ftomorrow-electricity-api-dotnet-client/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristofferandreasen%2Ftomorrow-electricity-api-dotnet-client/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/kristofferandreasen","download_url":"https://codeload.github.com/kristofferandreasen/tomorrow-electricity-api-dotnet-client/tar.gz/refs/heads/master","sbom_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/kristofferandreasen%2Ftomorrow-electricity-api-dotnet-client/sbom","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":261604472,"owners_count":23183646,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["c-sharp","client","csharp","dependency-injection","dotnet","dotnet-core","electricity","rest-api","tomorrow"],"created_at":"2025-03-19T19:44:51.495Z","updated_at":"2025-09-25T16:34:41.556Z","avatar_url":"https://github.com/kristofferandreasen.png","language":"C#","funding_links":[],"categories":[],"sub_categories":[],"readme":"\u003cdiv align=\"center\"\u003e\n  \u003ch1\u003e⚡ Tomorrow Electricity Map API C# .NET Rest Client ⚡\u003c/h1\u003e\n\u003c/div\u003e\n\u003cdiv align=\"center\"\u003e\n  This API wrapper is built to make it easier to use the ELectricity Map API from Tomorrow.\n  It provides a simple interface to understand and optimize the carbon footprint of electricity.\n\u003c/div\u003e\n\n\u003cbr /\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003ca href=\"https://www.nuget.org/packages/ElectricityMap.DotNet.Client/\"\u003e\n    \u003cimg src=\"https://img.shields.io/nuget/v/ElectricityMap.DotNet.Client\"\n      alt=\"NuGet Package\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/kristofferandreasen/tomorrow-electricity-api-dotnet-client/actions\"\u003e\n    \u003cimg src=\"https://github.com/kristofferandreasen/tomorrow-electricity-api-dotnet-client/workflows/build/badge.svg\"\n      alt=\"Build status\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://sonarcloud.io/dashboard?id=kristofferandreasen_tomorrow-electricity-api-dotnet-client\"\u003e\n    \u003cimg src=\"https://sonarcloud.io/api/project_badges/measure?project=kristofferandreasen_tomorrow-electricity-api-dotnet-client\u0026metric=alert_status\"\n      alt=\"Sonar Gate\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://github.com/kristofferandreasen/tomorrow-electricity-api-dotnet-client/issues\"\u003e\n    \u003cimg src=\"https://img.shields.io/github/issues/kristofferandreasen/tomorrow-electricity-api-dotnet-client\"\n      alt=\"GitHub Issues\" /\u003e\n  \u003c/a\u003e\n  \u003ca href=\"https://opensource.org/licenses/MIT\"\u003e\n    \u003cimg src=\"https://img.shields.io/badge/License-MIT-yellow.svg\"\n      alt=\"MIT License\" /\u003e\n  \u003c/a\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003ch3\u003e\n    \u003ca href=\"https://www.nuget.org/packages/ElectricityMap.DotNet.Client/\"\u003e\n      NuGet Package Download\n    \u003c/a\u003e\n    \u003cspan\u003e | \u003c/span\u003e\n    \u003ca href=\"https://github.com/kristofferandreasen/tomorrow-electricity-api-dotnet-client#contributing\"\u003e\n      Contributing\n    \u003c/a\u003e\n    \u003cspan\u003e | \u003c/span\u003e\n    \u003ca href=\"http://static.electricitymap.org/api/docs/index.html\"\u003e\n      Electricity Map API Documentation\n    \u003c/a\u003e\n  \u003c/h3\u003e\n\u003c/div\u003e\n\n\u003cdiv align=\"center\"\u003e\n  \u003csub\u003eA C# .NET Core REST client for the ElectricityMap API. Built with ❤︎ by\n  \u003ca href=\"https://github.com/kristofferandreasen\"\u003eKristoffer Andreasen\u003c/a\u003e\n\u003c/div\u003e\n\n## Installation\n\nYou need to install the NuGet Package to use the library.\nYou can use on of the following ways are install it through Visual Studio.\n\n### Install with Package Manager\n\n```\nInstall-Package ElectricityMap.DotNet.Client\n```\n\n### Install with .NET CLI\n\n```\ndotnet add package ElectricityMap.DotNet.Client\n```\n\n## Available Methods\n\nThere is one method available for each of the endpoints provided by the Electricity Map API.\nThe following table will show you all of them. Check the full API docs for more information on the endpoints.\nMost of the endpoints take a zone or latitude/longitude as parameters. You can find all the available zones in the ZoneConstants class. Be aware API keys are typically limited to specific zones.\n\n| Method  | Description  |\n|:---|:---|\n| GetAvailableZonesAsync  | Get the available zones for your API Key.  |\n| GetLiveCarbonIntensityAsync  | Data on the live carbon intensity.  |\n| GetLivePowerBreakdownAsync  | Live breakdown of the power usage.  |\n| GetRecentCarbonIntensityHistoryAsync  | Get data for recent carbon intensity measurements.  |\n| GetRecentPowerBreakdownHistoryAsync  | Get data for recent power breakdown measurements.  |\n| GetPastCarbonIntensityHistoryAsync  | Get data for past carbon intensity measurements.  |\n| GetPastPowerBreakdownHistoryAsync  | Get data for past power breakdown measurements.  |\n| GetForecastedCarbonIntensityAsync  | Get data for forecasted carbon intensity measurements.  |\n| GetForecastedPowerConsumptionBreakdownAsync  | Get data for forecasted power breakdown measurements.  |\n| GetForecastedMarginalCarbonIntensityAsync  | Get data for forecasted marginal carbon intensity measurements.  |\n| GetForecastedMarginalPowerConsumptionBreakdownAsync  | Get data for forecasted marginal power breakdown measurements.  |\n| GetUpdateInfoAsync  | Get data for API update history.  |\n\n## Using the package\n\nThe easiest way to use the library is by using dependency injection.\nIn the following sections you can see the easiest ways to use the library.\n\n### Dependency Injection: .NET Core Web Application\n\n* Register the ElectricityMapClient interface in the startup file\n* Inject the service in the class where you want to use it\n* [See full example in Example folder](https://github.com/kristofferandreasen/tomorrow-electricity-api-dotnet-client/tree/master/examples/RazorPages.Example)\n\n```\npublic void ConfigureServices(IServiceCollection services)\n{\n    services.AddRazorPages();\n\n    // Register the electricity map client for dependency injection\n    string electricityMapApiKey = Configuration.GetValue\u003cstring\u003e(\"ElectricityMap:ApiKey\");\n    services.AddElectricityMapClient(electricityMapApiKey);\n}\n```\n\n```\nnamespace RazorPages.Example.Pages\n{\n    public class IndexModel : PageModel\n    {\n        private readonly ILogger\u003cIndexModel\u003e _logger;\n        private readonly IElectricityMapClient _electricityMapClient;\n\n        public IndexModel(\n            ILogger\u003cIndexModel\u003e logger,\n            IElectricityMapClient electricityMapClient\n        )\n        {\n            _logger = logger;\n            _electricityMapClient = electricityMapClient;\n        }\n\n        public LiveCarbonIntentsity CarbonIntensity { get; set; }\n\n        public async Task OnGet()\n        {\n            CarbonIntensity = await _electricityMapClient.GetLiveCarbonIntensityAsync(ZoneConstants.Denmark_East_Denmark);\n        }\n    }\n}\n```\n\n### Dependency Injection: Azure Function\n\nThe pattern for using dependency injection in an Azure Function is similar to a web application.\n\n* Create a startup.cs file to enable dependency injection\n* Register the ElectricityMapClient interface in the startup file\n* Inject the service in the class where you want to use it\n* [See full example in Example folder](https://github.com/kristofferandreasen/tomorrow-electricity-api-dotnet-client/tree/master/examples/AzureFunction.Example)\n\n#### Startup.cs file\n\n```\n[assembly: FunctionsStartup(typeof(Azure.Function.Example.Startup))]\nnamespace Azure.Function.Example\n{\n    public class Startup : FunctionsStartup\n    {\n        public override void Configure(IFunctionsHostBuilder builder)\n        {\n            builder.Services.AddHttpClient();\n            builder.Services.AddLogging();\n\n            // Register the electricity map client with your api key\n            string electricityMapApiKey = Environment.GetEnvironmentVariable(\"ElectricityMapApiKey\");\n            builder.Services.AddElectricityMapClient(electricityMapApiKey);\n        }\n    }\n}\n```\n#### GetCarbonIntensity.cs file\n\n```\npublic class GetCarbonIntensityFunction\n{\n    private readonly IElectricityMapClient _electricityMapClient;\n\n    public GetCarbonIntensityFunction(IElectricityMapClient electricityMapClient)\n    {\n        _electricityMapClient = electricityMapClient;\n    }\n\n    [FunctionName(nameof(GetCarbonIntensityFunction))]\n    public  async Task\u003cIActionResult\u003e Run(\n        [HttpTrigger(AuthorizationLevel.Function, \"get\", Route = null)] HttpRequest req,\n        ILogger log)\n    {\n        log.LogInformation(\"C# HTTP trigger function processed a request.\");\n\n        string zone = req.Query[\"zone\"];\n\n        var carbonIntensity = await _electricityMapClient.GetLiveCarbonIntensityAsync(zone);\n\n        return carbonIntensity != null\n            ? (ActionResult)new OkObjectResult(carbonIntensity)\n            : new BadRequestObjectResult(\"Please pass a url on the query string or in the request body\");\n    }\n}\n```\n\n## Developing\n\nThe project is developed as a .NET Core Class Library.\nThe current framework version used is .NET Core 3.1.\n\nTo start developing, you need to clone the repo on your local workstation.\n\n#### Restore Dependencies\n\n```\ndotnet restore\n```\n\n#### Run Project\n\n```\ndotnet run\n```\n\n#### Test Project\n\nThe project is using XUnit for testing.\n\n```\ndotnet test\n```\n\nThis will start up the development server allowing you to see the results.\nBe aware that the solution is setting a cookie and this cookie will be stored in your browser.\nIn order to see the banner again, you will need to open the localhost link in incognito or clear your browser cookies.\n\n## Contributing\n\nYour contributions are always welcome!\nPlease have a look at the [contribution guidelines](https://github.com/kristofferandreasen/tomorrow-electricity-api-dotnet-client/blob/master/CONTRIBUTING.md) first 🎉\n\n## License\n\nMIT © [kristofferandreasen](https://github.com/kristofferandreasen)","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkristofferandreasen%2Ftomorrow-electricity-api-dotnet-client","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fkristofferandreasen%2Ftomorrow-electricity-api-dotnet-client","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fkristofferandreasen%2Ftomorrow-electricity-api-dotnet-client/lists"}