Explore electricity generation mix trends and forecasts using UK power grid data.
Grid Generation is a free, no-auth, user-friendly API library that provides access to real-time and forecasted electricity generation mix data from the Carbon Intensity API. This project makes it easy to explore energy contributions from different fuel sources. It’s designed for everyone from energy analysts and students to educators and planners who want to study generation trends and carbon intensity impacts without complex software or specialized expertise.
Each release provides two configuations of the project.
- The bundled, minified format known as "production".
- The unbundled, unminified format known as "development".
https://github.com/LewisRandles/Grid-Generation/releases
// Using the unbundled version needs to be kept with the internal files.
import gridGeneration from './scripts/gridGeneration_unbundled.js';
// Using the bundled version is standalone and has no internal files.
import gridGeneration from './gridGeneration_bundled.js';Providing no parameters will result in the default information being set.
await gridGeneration();The first parameter is providing the desired mode. The format is case-insensitive.
| First Parameter | Type | Description |
|---|---|---|
mode |
string |
Supported mode formats include current and custom. |
| Usage | Type | Description |
|---|---|---|
current |
string |
Get generation mix for current half hour. All times provided in UTC (+00:00). |
custom |
string |
Get generation mix between startDate and endDate times. All times provided in UTC (+00:00). |
// Argument object.
await gridGeneration({"mode": "current"});// External object.
const apiConfig = {
"mode": "current"
}
await gridGeneration(apiConfig);The second parameter is providing the desired startDate The format is case-insensitive.
| Second Parameter | Type | Description |
|---|---|---|
startDate |
string |
Supported startDate formats include DD-MM-YYYY and YYYY-MM-DD. |
| Usage | Type | Description |
|---|---|---|
startDate |
string |
startDate is in ISO8601 format. |
// Argument object.
await gridGeneration({"mode": "current", "startDate": "2025-01-01"});// External object.
const apiConfig = {
"mode": "current",
"startDate": "2025-01-01"
}
await gridGeneration(apiConfig);The third parameter is providing the desired endDate The format is case-insensitive.
| Third Parameter | Type | Description |
|---|---|---|
endDate |
string |
Supported endDate formats include DD-MM-YYYY and YYYY-MM-DD. |
| Usage | Type | Description |
|---|---|---|
endDate |
string |
endDate is in ISO8601 format. |
// Argument object.
await gridGeneration({"mode": "current", "startDate": "2025-01-01", "endDate": "2025-01-02"});// External object.
const apiConfig = {
"mode": "current",
"startDate": "2025-01-01",
"endDate": "2025-01-02"
}
await gridGeneration(apiConfig);During normalization, raw API fields such as [{"fuel":"biomass","perc":2.4},{"fuel":"coal","perc":0},{"fuel":"imports","perc":10.2}] are converted into a processed object such as {biomass: "2.4", coal: "0", imports: "11.8"}. Objects provide more reliable and consistent access than arrays while enabling easier manipulation and processing of nested data structures. Nested objects are flattened, redundant metadata and overlapping identifiers are removed, empty or missing fields are normalized, boolean and encoded values are standardized, and all data is organized into a uniform, consistent key-value JSON structure to produce a clean and predictable final result.
During sanitization, instead of leaving object values as null or undefined, missing or empty fields are filled with a placeholder such as "no value" to ensure that every key in the final result has a valid string; this prevents errors in downstream processing, makes the dataset fully predictable, and allows client applications to safely read and display all values without additional null checks.
This JSON serves as a configuration layer that lets you enable or disable individual parent and child fields and rename them through altName, giving you full control over which properties appear in the final output. Some values from the raw API return are intentionally omitted because they are considered unnecessary or not useful.
The parents group defines the top-level fields that can be enabled, disabled, or renamed, allowing you to control which main object properties appear in the output.
"parents": {
"item1": {
"name": {
"original": "defaultName",
"altName": "customName"
},
"used": true
},
...
}The children group manages the nested fields within those parent objects, giving similar control over which sub-properties are included and how they are labeled.
"children": {
"item1": {
"name": {
"original": "defaultName",
"altName": "customName"
},
"used": true,
"validate": "checkGeneration"
},
...
}Try the hosted demo via GitHub Pages Demo
- For generation API information, the generation API
