Package: pyeia
ConfigurationYou can configure pyeia with your API key either at runtime.DeclareEIA_APIKEY="myapikey"in a.envfileSet an environment variable explicitly,export EIA_APIKEY="myapikey"If you are using dynaconf, you can include an[eia]environment in yoursettings.tomlfile (or any other configured settings files.)[eia]apikey="my apikey"AboutThe U.S. Energy Information Adminsitration provides an API for access to commonly used datasets for policy makers
and researchers. See theEIA API documentationfor 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 UsageSince 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. :pipinstallpyeia
pipshowpyeiaThere are two main strategies for interacting with this package.EIA BrowserEIA provides a web-based data browserSince 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 theexportmethod on a Browser object will make a request to theSeriesAPI 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.Browser Quickstart to Collect AEO dataComputing Marginal Values for AEO dataDirect API usageEach endpoint has a corresponding class ineia.api.  Every class has aquerymethod that makes a call to EIA.
The returned result is always the response body.  Metadata about the request is dropped.  TheSeriesandGeosetclasses have a specialquery_dfmethod since their response bodies have a naturally tabular schema.fromeiaimportapimyapikey=""# Register here : www.eia.gov/opendata/register.cfm# Make a call to the Category endpointcategory=api.Category(myapikey)category.query()# Make a call to the Series endpointseries=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 DataFrameseries.to_dataframe()# Make a call to the Geoset endpointgeoset=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 endpointseriescategory=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 endpointupdates=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 endpointsearch=api.Search(api_key=myapikey)# Make a series_id searchsearch.to_dict("series_id","EMI_CO2_COMM_NA_CL_NA_NA_MILLMETNCO2.A","all")# Make a name searchsearch.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 argumentsearch.to_dict("last_updated",["Dec. 1st, 2014","06/14/2015 3:45PM"])