# US Energy Information Administration API Query Browser, Open Data SourceclassEIA_Client():
api_key=Nonedef__init__(self, api_key=creds.eai_key, data='category', *args, **kwargs):
super().__init__(*args, **kwargs)
ifapi_key==None:
raiseException('Api key is required')
self.api_key=api_keyself. eia_url=f"http://api.eia.gov/{data}/"defcategory(self, cat=1293027):
params= {'api_key': self.api_key, 'category_id':cat}
params_url=urlencode(params)
url=f"{self.eia_url}?{params_url}"response=requests.get(url).json()
returnresponse
PostgreSQL Data Import
SET search_path = countries
--Select two countries data by years (self join)SELECTp1.year, SUM(p1.oil_production) as USA,
SUM(p2.oil_production) as RUSSIA
FROM production as p1
INNER JOIN production as p2 ONp1.year=p2.yearWHEREp1.country='United States of America'ANDp2.country='Russia'GROUP BYp1.yearORDER BYp1.yearDESC