Please note that this page is very much a work in progress, and currently used to document the most important information for users.

4. JupyterHub

The Funder Data Platform uses JupyterHub (https://jupyter.org/hub) as an analytical work space, allowing researchers and funders to collaborate on analysing data sets.

4.1. Main functionality

4.1.1 Installing packages

Several standard packages for analysing data come pre-installed in the FDP JupyterHub, but if you are missing a specific package, you can access PIP for installing packages like so:

!pip install psycopg

4.1.2 Connecting to PostgreSQL

To access data from the FDP PostgreSQL database, you need to first create a connection to it in your jupyter notebook. You are welcome to use other approaches, but we recommend connecting through psycopg. Example code for testing the connection is found here:

!pip install psycopg
import psycopg

# Database connection settings for the fdp postgresql server
db_name = "fdp"
db_user = "fdp_view"
db_password = "ImprobableImpala"
db_host = "172.17.0.1"

# Testing connection to the database server
try:
    conn = psycopg.connect(
        dbname=db_name,
        user=db_user,
        password=db_password,
        host=db_host
    )
    cur = conn.cursor()
    print("Connection successful.")
    # If the above text is printed, further code can be added here, at this indentation.
except Exception as e:
    print("Connection failed.")
    print(e)

If the connection is working, this can be simplified somewhat, like so:

import psycopg
conn = psycopg.connect("172.17.0.1", "fdp_view", "ImprobableImpala", "fdp")
cur = conn.cursor()

Reading data from views requires two steps: setting a key and selecting data from a view. Once the key is set, multiple views can be read without setting the key again. For specific details on how to read a view, please see the system-generated code for a view you have been granted access to. If you use the connection script above, you can run the view-code as-is.