Crates.io | carbonintensity-api |
lib.rs | carbonintensity-api |
version | 0.3.0 |
source | src |
created_at | 2023-11-21 05:53:05.971513 |
updated_at | 2024-10-15 05:27:35.890743 |
description | Provides a client for the UK National Grid Carbon Intensity API |
homepage | |
repository | https://github.com/jnioche/carbonintensity-api |
max_upload_size | |
id | 1043752 |
size | 92,269 |
A simple Rust library to help retrieve data from the Carbon Intensity API, not all functionalities of the CarbonIntensity API might be exposed.
Please read the API's terms of use.
An executable is provided to try the library. With Rust and Cargo installed
cargo install --locked --path .
then
carbonintensity-api -h
should display the list of available commands and options.
Provides a client for the UK National Grid Carbon Intensity API
Usage: carbonintensity-api [OPTIONS] <VALUE>
Arguments:
<VALUE> numerical value for a region (1-17) or first part of a UK postcode
Options:
-s, --start-date <START_DATE>
-e, --end-date <END_DATE>
-h, --help Print help
-V, --version Print version
To display the current carbon intensity for a given postcode
carbonintensity-api bs7
To do the same for a region
carbonintensity-api 11
The region id is a number between 1 and 17
North Scotland
South Scotland
North West England
North East England
South Yorkshire
North Wales, Merseyside and Cheshire
South Wales
West Midlands
East Midlands
East England
South West England
South England
London
South East England
England
Scotland
Wales
Specifying dates will return a list of intensities for a region or postcode. If no end date is provided, the current day and time will be used.
The dates are expected to be at the %Y-%m-%dT%H:%MZ
format or simply %Y-%m-%d
, for instance
carbonintensity-api -s 2023-11-11 -e 2023-11-11T12:00Z postcode bs7
Intensities are returned by 30 mins windows.
You can use the library in your Rust project by adding it to cargo with
cargo add carbonintensity-api
then declaring it in your code
use carbonintensity::{get_intensity, Target, Region};
...
let scotland = Region::Scotland;
let result = get_intensity(&Target::Region(scotland)).await;
This project is provided under Apache License.