API tutorial 1 - Introduction to the OEP-API and basic table opperations¶
Please report bugs and improvements here: https://github.com/OpenEnergyPlatform/examples/issues
How to get started with Jupyter Notebooks can be found here: https://realpython.com/jupyter-notebook-introduction/
__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-ful-HTTP API in Python.
The full API documentaion can be found on ReadtheDocs.io.
Part I - How to work with the OpenEnergy Platform (OEP)¶
Get started - Sign-in and get your own token
0 Setup token
1 Create a table
2 Delete a table
3 Query table columns
4 Insert Data into a table
5 Insert data into a specific row
6 Alter data in a table
Links and further information¶
How to work with Python and Jupyter Notebooks
Overview of Packages:¶
0. Get started - Sign-in and get your own token¶
Register a new account on the OpenEnergyPlatform. Then login (https://openenergy-platform.org/).
1. Click on the login button and sign in¶
2. Copy your token¶
Click on your Profile Name to see your information. To view your token, click on "Show token"
3a. Paste your token in an environment variable¶
The variable should be named 'OEP_TOKEN'. On linux :
export OEP_TOKEN=<your token>
set OEP_TOKEN=<your token>
3b. Paste your token in a file (discouraged)¶
Look for the following line in the file
OEP_TOKEN = ''
then paste your token there
OEP_TOKEN = '<paste_your_token_here>'
Save the file but DO NOT PUSH the change to GitHub
import requests import pandas as pd from IPython.core.display import HTML from token_config import oep_url, get_oep_token # token your_token = get_oep_token()
0.1 About the Database and used Packages¶
Data are stored and ordered by topic under the "schema" tab: https://openenergy-platform.org/dataedit/schemas
The data tables can be accessed by calling them via http request.
The "request" package will handle the HTTP communication with the OEP database. It sends requests that insert (put, post, delete) or read (get) data in/from the databank. For either request the URL of a requested table has to be included. For all "put", "post" and "delete" requests one has to include the authentification token as a header, like in the "delete table " example.