OpenEnergy Platform



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"

Tutorial - How to work with the OpenEnergy Platform (OEP)


This is an important information!
This is an information!
This is your task!

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.

Part II

0 Setup token
1 Select data from a table
2 Include filters
3 More Options

Part II

0. Setup token


Do not push your token to GitHub!

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 = ''

1. Select data from a table


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
**200** succesfully selected data!

In [ ]:
# Convert to dataframe
plant_df = pd.DataFrame(get_data.json())
plant_df

2. Include filters

2.1 where


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

2.2 column


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

2.3 limit


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

2.4 orderby


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

2.5 Combine filters


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

3. More Options

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:

  • EQUALS or =,
  • GREATER or >,
  • LOWER or <,
  • NOTEQUAL or != or <>,
  • NOTGREATER or <=,
  • NOTLOWER or >=
Try some selects!

In [ ]: