In [ ]:
__copyright__ = "Reiner Lemoine Institut, Zentrum für nachhaltige Energiesysteme Flensburg"
__license__ = "GNU Affero General Public License Version 3 (AGPL-3.0)"
__url__ = "https://github.com/openego/data_processing/blob/master/LICENSE"
__author__ = "wolfbunke, Ludee"
This tutorial gives you an overview of the OpenEnergy Platform and how you can work with the REST-full-HTTP API in Python.
The full API documentaion can be found on ReadtheDocs.io.
0 Setup token
1 Select data from a table
2 Include filters
3 More Options
In [ ]:
import requests
import pandas as pd
from IPython.core.display import HTML
# oedb
oep_url= 'http://oep.iks.cs.ovgu.de/'
# token
your_token = ''
In [ ]:
# select data
schema = 'model_draft'
table = 'example_api_table_test'
get_data = requests.get(oep_url+'/api/v0/schema/'+schema+'/tables/'+table+'/rows/')
get_data.status_code
In [ ]:
# Convert to dataframe
plant_df = pd.DataFrame(get_data.json())
plant_df
In [ ]:
schema = 'model_draft'
table = 'example_api_table_test'
where = 'type=wind_onshore'
result = requests.get(oep_url+'/api/v0/schema/'+schema+'/tables/'+table+'/rows/?where='+where, )
result.status_code
# Convert to dataframe
df = pd.DataFrame(result.json())
df
In [ ]:
schema = 'model_draft'
table = 'example_api_table_test'
column = 'column=name&column=id&column=type'
result = requests.get(oep_url+'/api/v0/schema/'+schema+'/tables/'+table+'/rows/?'+column, )
result.status_code
# Convert to dataframe
df = pd.DataFrame(result.json())
df
In [ ]:
schema = 'model_draft'
table = 'example_api_table_test'
limit = '2'
result = requests.get(oep_url+'/api/v0/schema/'+schema+'/tables/'+table+'/rows/?limit='+limit, )
result.status_code
# Convert to dataframe
df = pd.DataFrame(result.json())
df
In [ ]:
schema = 'model_draft'
table = 'example_api_table_test'
order_by = 'id'
result = requests.get(oep_url+'/api/v0/schema/'+schema+'/tables/'+table+'/rows/?orderby='+order_by, )
result.status_code
print(result)
# Convert to dataframe
df = pd.DataFrame(result.json())
df
In [ ]:
schema = 'model_draft'
table = 'example_api_table_test'
order_by = 'id'
limit = '2'
result = requests.get(oep_url+'/api/v0/schema/'+schema+'/tables/'+table+'/rows/?limit='+limit+'&orderby='+order_by, )
result.status_code
print(result)
# Convert to dataframe
df = pd.DataFrame(result.json())
df
In [ ]:
schema = 'model_draft'
table = 'example_api_table_test'
where = 'type=photovoltaics'
column = 'column=name&column=id&column=type'
#result = requests.get(oep_url+'/api/v0/schema/'+schema+'/tables/'+table+'/rows/?where='+where+'&'+column, )
#result = requests.get(oep_url+'/api/v0/schema/'+schema+'/tables/'+table+'/rows/?where=type=photovoltaics&column=name&column=id&column=type', )
result.status_code
# Convert to dataframe
df = pd.DataFrame(result.json())
df
There are also optional parameters for these GET-queries:
limit: Limit the number of returned rows
offset: Ignore the specified amount of rows
orderby: Name of a column to refer when ordering
column: Name of a column to include in the results. If not present, all columns are returned
where: Constraint fourmulated as VALUE+OPERATOR+VALUE with
1 VALUE: Constant or name of a column
2 OPERATOR: One of the following:
In [ ]: