Skip to main content

No project description provided

Project description

myeia

PyPI version License: MIT Weekly Downloads Monthly Downloads Downloads

myeia is a simple Python wrapper for the U.S. Energy Information Administration (EIA) APIv2. It is designed to be simple to use and to provide a consistent interface for accessing EIA data.

Installation

pip install myeia

Requirements

  • pandas
  • requests
  • python-dotenv

eia OPEN DATA Registration

To obtain an API Key you need to register on the EIA website.

eia API Query Browser

To find all EIA Datasets visit API Dashboard.

How to use

from myeia.api import API

eia = API()

By Default the EIA class will look for your API EIA_TOKEN.

If you have registered for an API key you can set it in your .env file.

EIA_TOKEN=YOUR_TOKEN_HERE

Get Series

Lets look at an example of how to get the EIA Natural Gas Futures. You can use the simpler v1 API method where you only need to pass the series_id or you can use the newer v2 API method where you need to pass the route, series, and frequency.

df = eia.get_series(series_id="NG.RNGC1.D")

df = eia.get_series_via_route(
    route="natural-gas/pri/fut",
    series="RNGC1",
    frequency="daily",
)

df.head()

Output Example:

            Natural Gas Futures Contract 1 (Dollars per Million Btu)
Date
2022-09-13                                              8.284
2022-09-12                                              8.249
2022-09-09                                              7.996
2022-09-08                                              7.915
2022-09-07                                              7.842
...

Different Facets

Lets look at another example the Total OPEC Petroleum Supply where the facet is available as seriesId. By Default it is set as series but we can define the facet as seriesId.

df = eia.get_series(series_id="STEO.PAPR_OPEC.M")

df = eia.get_series_via_route(
    route="steo",
    series="PAPR_OPEC",
    frequency="monthly",
    facet="seriesId",
)

df.head()

Output Example:

            Total OPEC Petroleum Supply
Date
2023-12-01                    34.517314
2023-11-01                    34.440397
2023-10-01                    34.376971
2023-09-01                    34.416242
2023-08-01                    34.451823

Get Multiple Series

You can also get a list of series for a specific route.

You have to make sure they are both in the same frequency and facet type.

df = eia.get_series_via_route(
    route="natural-gas/pri/fut",
    series=["RNGC1", "RNGC1"],
    frequency="daily",
    facet="seriesId",
)

df.head()

Output Example:

            Natural Gas Futures Contract 1 (Dollars per Million Btu)  Natural Gas Futures Contract 2 (Dollars per Million Btu)
Date                                                                                                                          
2023-08-29                                              2.556                                                     2.662       
2023-08-28                                              2.579                                                     2.665       
2023-08-25                                              2.540                                                     2.657       
2023-08-24                                              2.519                                                     2.636       
2023-08-23                                              2.497                                                     2.592       
...                                                       ...                                                       ...

Define a Start and End Date

You can define a start and end date for your query.

df = eia.get_series(
    series_id="NG.RNGC1.D",
    start="2021-01-01",
    end="2021-01-31",
)

df.head()

Output Example:

            Natural Gas Futures Contract 1 (Dollars per Million Btu)
Date                                                                
2021-01-29                                              2.564       
2021-01-28                                              2.664       
2021-01-27                                              2.760       
2021-01-26                                              2.656       
2021-01-25                                              2.602       
...                                                     ...       

This also works for the get_series_via_route method.

df = eia.get_series_via_route(
    route="natural-gas/pri/fut",
    series=["RNGC1", "RNGC2"],
    frequency="daily",
    start="2021-01-01",
    end="2021-01-31",
)

df.head()

Output Example:

            Natural Gas Futures Contract 1 (Dollars per Million Btu)  Natural Gas Futures Contract 2 (Dollars per Million Btu)
Date
2021-01-29                                              2.564                                                     2.592
2021-01-28                                              2.664                                                     2.675
2021-01-27                                              2.760                                                     2.702
2021-01-26                                              2.656                                                     2.636
2021-01-25                                              2.602                                                     2.598
...                                                       ...                                                       ...

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

myeia-0.3.4.tar.gz (6.9 kB view details)

Uploaded Source

Built Distribution

myeia-0.3.4-py2.py3-none-any.whl (6.1 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file myeia-0.3.4.tar.gz.

File metadata

  • Download URL: myeia-0.3.4.tar.gz
  • Upload date:
  • Size: 6.9 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.17

File hashes

Hashes for myeia-0.3.4.tar.gz
Algorithm Hash digest
SHA256 0ea2230d0dce8f60e7085ed9eae60a129d860fa73f44cd494fd8411b87091831
MD5 ee383b38bc7c498167f72d02e740ba50
BLAKE2b-256 13821d296e2ed273b0e2d3c548586ef11a7c61e68454f01a5928114e317e29a2

See more details on using hashes here.

File details

Details for the file myeia-0.3.4-py2.py3-none-any.whl.

File metadata

  • Download URL: myeia-0.3.4-py2.py3-none-any.whl
  • Upload date:
  • Size: 6.1 kB
  • Tags: Python 2, Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/4.0.2 CPython/3.8.17

File hashes

Hashes for myeia-0.3.4-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 a300bc57de5592c67457e72fbcfb7cf9ea3d18730a22dc67a6c7692136283f8a
MD5 7eca0595b0132454e87ce6fc35fc8fb9
BLAKE2b-256 da4d5770eb4dfb9814a218c6682c423a8694fe014395ce74a92705aef8f95daa

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