Skip to main content

Configuration

You can configure pyeia with your API key either at runtime.

  • Declare EIA_APIKEY="myapikey" in a .env file
  • Set an environment variable explicitly, export EIA_APIKEY="myapikey"
  • If you are using dynaconf, you can include an [eia] environment in your settings.toml file (or any other configured settings files.)
[eia]
apikey = "my apikey"

About

The U.S. Energy Information Adminsitration provides an API for access to commonly used datasets for policy makers and researchers. See the EIA API documentation for more information.

Warning : This package is a work in progress! A substantial update is expected in January 2020, with a published version on PyPi. The author took a break from this domain area, but is returning! Hoping to have a similar or identical R interface/API as well, but that may be much farther down the pipeline.

Basic Usage

Since this package is still under active development, it has not been pushed to PyPi. That said, I believe it is stable and reliable enough for immediate use. You can install this via git+https, i.e. :

pip install pyeia
pip show pyeia

There are two main strategies for interacting with this package.

EIA Browser

EIA provides a web-based data browser Since most interactions for discovering data via the API will likely occur through this browser, this motivated a programmatic version.

The general strategy is to traverse a datapath or multiple datapaths, and when you arrive to the desired node, you flag one or more dataseries.
There is also the ability to add in meta information as you flag a dataseries.

Running the export method on a Browser object will make a request to the Series API to collect data you've flagged.

There's currently a separate class for each dataset which is mostly syntactic. In the future, there will likely be methods and visualizations builtin that are specific to the datasets described at the root category level from EIA.

  1. Browser Quickstart to Collect AEO data
  2. Computing Marginal Values for AEO data

Direct API usage

Each endpoint has a corresponding class in eia.api. Every class has a query method that makes a call to EIA. The returned result is always the response body. Metadata about the request is dropped. The Series and Geoset classes have a special query_df method since their response bodies have a naturally tabular schema.

from eia import api

myapikey = ""  # Register here : www.eia.gov/opendata/register.cfm

# Make a call to the Category endpoint
category = api.Category(myapikey)
category.query()

# Make a call to the Series endpoint
series = api.Series(
    "AEO.2015.REF2015.CNSM_DEU_TOTD_NA_DEU_NA_ENC_QBTU.A",
    "AEO.2015.REF2015.CNSM_ENU_ALLS_NA_DFO_DELV_ENC_QBTU.A",
    api_key=myapikey,
)
series.to_dict()  # Export data from its json response
# Make the same query, but get results as a pandas DataFrame
series.to_dataframe()

# Make a call to the Geoset endpoint
geoset = api.Geoset("ELEC.GEN.ALL-99.A", "USA-CA", "USA-FL", "USA-MN", api_key=myapikey)
geoset.to_dict()
geoset.query_df()

# Make a call to the SeriesCategory endpoint

seriescategory = api.SeriesCategory(
    "AEO.2015.REF2015.CNSM_DEU_TOTD_NA_DEU_NA_ENC_QBTU.A",
    "AEO.2015.REF2015.CNSM_ENU_ALLS_NA_DFO_DELV_ENC_QBTU.A",
    api_key=myapikey,
)
seriescategory.to_dict()

# Make a call to the Updates endpoint

updates = api.Updates(
    category_id=2102358,
    rows=0,
    firstrow="currently_not_used",
    deep=False,
    api_key=myapikey,
)
updates.to_dict()

# Make a call to the Search endpoint
search = api.Search(api_key=myapikey)

# Make a series_id search
search.to_dict("series_id", "EMI_CO2_COMM_NA_CL_NA_NA_MILLMETNCO2.A", "all")

# Make a name search
search.to_dict("name", "crude oil", 25)

# Make a date-range search
# Dates can be input as a list/tuple of any valid pd.to_datetime argument
search.to_dict("last_updated", ["Dec. 1st, 2014", "06/14/2015 3:45PM"])

Metadata

Release files for pyeia 0.1.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for pyeia 0.1.6
File Size Uploaded
pyeia-0.1.6.tar.gz 12.8 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for pyeia 0.1.6
File Interpreter ABI Platform
pyeia-0.1.6-py3-none-any.whl Python 3 none any Details

Total release size: 27.7 kB

Release files / pyeia-0.1.6.tar.gz

Download URL pyeia-0.1.6.tar.gz
Size 12.8 kB
Tags Source
SHA-256 checksum
How to use checksums
62168e75de30303a4d68c21e20018aef47afbb216f4d280ff2042cc54151d904
BLAKE2b-256 checksum
How to use checksums
9e5598bfb26c43163d588a03089ef71f56c30418a50174194ed6886a42d3ec45
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.10 CPython/3.9.7 Linux/5.15.5-76051505-generic

Release files / pyeia-0.1.6-py3-none-any.whl

Download URL pyeia-0.1.6-py3-none-any.whl
Size 14.9 kB
Tags Python 3
SHA-256 checksum
How to use checksums
af0d939cf122ee67d67e361596079c82855e9849405fed04abdb253880888fa3
BLAKE2b-256 checksum
How to use checksums
960d77cb4c263ab71f1669487409b854227b372f30c073bbab8648f39ea91676
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.1.10 CPython/3.9.7 Linux/5.15.5-76051505-generic

Release history Release notifications | RSS feed

This release

0.1.6 This release

2 release files

0.1.5

2 release files

0.1.4

2 release files

0.1.3

2 release files

0.1.2

2 release files

0.1.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page