Skip to main content

An officially maintained python client for WattTime's API providing access to electricity grid emissions data.

Project description

About

This SDK is meant to help users with basic queries to WattTime’s API (version 3), and to get data returned in specific formats (e.g., JSON, pandas, csv).

Users may register for access to the WattTime API through this client, however the basic user scoping given will only allow newly registered users to access data for the CAISO_NORTH region. Additionally, data may not be available for all signal types for newly registered users.

Full documentation of WattTime's API, along with response samples and information about available endpoints is also available.

Configuration

The SDK can be installed as a python package from the PyPi repository, we recommend using an environment manager such as miniconda or venv.

pip install watttime

If you are not registered for the WattTime API, you can do so using the SDK:

from watttime import WattTimeMyAccess

wt = WattTimeMyAccess(username=<USERNAME>, password=<PASSWORD>)
wt.register(email=<EMAIL>, organization=<ORGANIZATION>)

If you are already registered for the WattTime API, you may set your credentials as environment variables to avoid passing these during class initialization:

# linux or mac
export WATTTIME_USER=<your WattTime API username>
export WATTTIME_PASSWORD=<your WattTime API password>

Once you have set your credentials as environment variables, you can omit passing username and password when instantiating sdk objects. For instance, in the example below, you could replace the second line with

wt_myaccess = WattTimeMyAccess()

Using the SDK

Users may first want to query the /v3/my-access endpoint using the WattTimeMyAccess class to get a dataframe of regions and signal types available to them:

from watttime import WattTimeMyAccess

wt_myaccess = WattTimeMyAccess(username, password)

# return a nested json describing signals and regions you have access to
wt_myaccess.get_access_json()

# return a pandas dataframe describing signals and regions you have access to
wt_myaccess.get_access_pandas()

Accessing Historical Data

Once you confirm your access, you may wish to request data for a particular region:

from watttime import WattTimeHistorical

wt_hist = WattTimeHistorical(username, password)

# get data as a pandas dataframe
moers = wt_hist.get_historical_pandas(
    start = '2022-01-01 00:00Z', # ISO 8601 format, UTC
    end = '2023-01-01 00:00Z', # ISO 8601 format, UTC
    region = 'CAISO_NORTH',
    signal_type = 'co2_moer' # ['co2_moer', 'co2_aoer', 'health_damage', etc.]
)

# save data as a csv -> ~/watttime_historical_csvs/<region>_<signal_type>_<start>_<end>.csv
wt_hist.get_historical_csv(
    start = '2022-01-01 00:00Z', # ISO 8601 format, UTC
    end = '2023-01-01 00:00Z', # ISO 8601 format, UTC
    region = 'CAISO_NORTH',
    signal_type = 'co2_moer' # ['co2_moer', 'co2_aoer', 'health_damage', etc.]
)

You could also combine these classes to iterate through all regions where you have access to data:

from watttime import WattTimeMyAccess, WattTimeHistorical
import pandas as pd

wt_myaccess = WattTimeMyAccess(username, password)
wt_hist = WattTimeHistorical(username, password)

access_df = wt_myaccess.get_access_pandas()

moers = pd.DataFrame()
moer_regions = access_df.loc[access_df['signal_type'] == 'co2_moer', 'region'].unique()
for region in moer_regions:
    region_df = wt_hist.get_historical_pandas(
        start = '2022-01-01 00:00Z',
        end = '2023-01-01 00:00Z',
        region = region,
        signal_type = 'co2_moer'
    )
    moers = pd.concat([moers, region_df], axis='rows')

Accessing Real-Time and Historical Forecasts

You can also use the SDK to request a current forecast for some signal types, such as co2_moer and health_damage:

from watttime import WattTimeForecast

wt_forecast = WattTimeForecast(username, password)
forecast = wt_forecast.get_forecast_json(
    region = 'CAISO_NORTH',
    signal_type = 'health_damage'
)

We recommend using the WattTimeForecast class to access data for real-time optimization. The first item of the response from this call is always guaranteed to be an estimate of the signal_type for the current five minute period, and forecasts extend at least 24 hours at a five minute granularity, which is useful for scheduling utilization during optimal times.

Methods also exist to request historical forecasts, however these responses may be slower as the volume of data can be significant:

hist_forecasts = wt_forecast.get_historical_forecast_json(
    start = '2022-12-01 00:00+00:00',
    end = '2022-12-31 23:59+00:00',
    region = 'CAISO_NORTH',
    signal_type = 'health_damage'
)

Accessing Location Data

We provide two methods to access location data:

  1. The region_from_loc() method allows users to provide a latitude and longitude coordinates in order to receive the valid region for a given signal type.

  2. the WattTimeMaps class provides a get_maps_json() method which returns a GeoJSON object with complete boundaries for all regions available for a given signal type. Note that access to this endpoint is only available for Pro and Analyst subscribers.

from watttime import WattTimeMaps

wt = WattTimeMaps()

# get BA region for a given location
wt.region_from_loc(
    latitude=39.7522,
    longitude=-105.0,
    signal_type='co2_moer'
)

# get shape files for all regions of a signal type
wt.get_maps_json('co2_moer')

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

watttime-1.2.1.tar.gz (11.9 kB view details)

Uploaded Source

Built Distribution

watttime-1.2.1-py3-none-any.whl (8.0 kB view details)

Uploaded Python 3

File details

Details for the file watttime-1.2.1.tar.gz.

File metadata

  • Download URL: watttime-1.2.1.tar.gz
  • Upload date:
  • Size: 11.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for watttime-1.2.1.tar.gz
Algorithm Hash digest
SHA256 960caf3784c142d82a45a1e716603dd55a29e6287be3e13e949e1064e05fd86e
MD5 4d312c74d1b09099627b32a088a77fbd
BLAKE2b-256 a60f70e00f811378d87cff3a6d017ea466f12b45b245ed066173f5fc6561958f

See more details on using hashes here.

File details

Details for the file watttime-1.2.1-py3-none-any.whl.

File metadata

  • Download URL: watttime-1.2.1-py3-none-any.whl
  • Upload date:
  • Size: 8.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/5.0.0 CPython/3.12.2

File hashes

Hashes for watttime-1.2.1-py3-none-any.whl
Algorithm Hash digest
SHA256 db92259b65209ec7b92da914b6b883751ab0af97658934840bf947bd8e7af03f
MD5 5eeb07beb28384750edb9d80ac337a14
BLAKE2b-256 0811d5fd3040b31edfef7f55e8cbf9b878212c1b7cad12198293cae3904a6a71

See more details on using hashes here.

Supported by

AWS AWS Cloud computing and Security Sponsor Datadog Datadog Monitoring Fastly Fastly CDN Google Google Download Analytics Microsoft Microsoft PSF Sponsor Pingdom Pingdom Monitoring Sentry Sentry Error logging StatusPage StatusPage Status page