Authentication in the Gen3 Data Commons using the SDK

1. Install Gen3 SDK

In [18]:
pip install gen3
Requirement already satisfied: gen3 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (2.4.0)
Requirement already satisfied: requests in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from gen3) (2.24.0)
Requirement already satisfied: pandas in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from gen3) (1.0.5)
Requirement already satisfied: indexclient>=1.6.2 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from gen3) (2.1.0)
Requirement already satisfied: aiohttp in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from gen3) (3.6.2)
Requirement already satisfied: backoff in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from gen3) (1.10.0)
Requirement already satisfied: click in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from gen3) (7.1.2)
Requirement already satisfied: certifi>=2017.4.17 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from requests->gen3) (2020.6.20)
Requirement already satisfied: chardet<4,>=3.0.2 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from requests->gen3) (3.0.4)
Requirement already satisfied: idna<3,>=2.5 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from requests->gen3) (2.10)
Requirement already satisfied: urllib3!=1.25.0,!=1.25.1,<1.26,>=1.21.1 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from requests->gen3) (1.25.9)
Requirement already satisfied: pytz>=2017.2 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from pandas->gen3) (2020.1)
Requirement already satisfied: numpy>=1.13.3 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from pandas->gen3) (1.19.1)
Requirement already satisfied: python-dateutil>=2.6.1 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from pandas->gen3) (2.8.1)
Requirement already satisfied: yarl<2.0,>=1.0 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from aiohttp->gen3) (1.4.2)
Requirement already satisfied: multidict<5.0,>=4.5 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from aiohttp->gen3) (4.7.6)
Requirement already satisfied: attrs>=17.3.0 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from aiohttp->gen3) (19.3.0)
Requirement already satisfied: async-timeout<4.0,>=3.0 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from aiohttp->gen3) (3.0.1)
Requirement already satisfied: six>=1.5 in /Library/Frameworks/Python.framework/Versions/3.8/lib/python3.8/site-packages (from python-dateutil>=2.6.1->pandas->gen3) (1.15.0)
WARNING: You are using pip version 20.2.3; however, version 20.2.4 is available.
You should consider upgrading via the '/Library/Frameworks/Python.framework/Versions/3.8/bin/python3.8 -m pip install --upgrade pip' command.
Note: you may need to restart the kernel to use updated packages.

2. Import the authentication function from the Gen3 SDK library

In [19]:
import gen3
from gen3.auth import Gen3Auth

3. Define API, which is the URL of the Gen3 data commons

In [20]:
endpoint = "https://gen3.datacommons.io/"

4. Define the JSON containing credentials downloaded from Gen3 Data Commons and saved in the workspace

In [1]:
creds = "credentials_1.json" #JSON can be also called with a path

5. Authenticate pointing to the endpoint and credentials

Gen3.auth generates access tokens from the provided refresh token file or string. Automatically refreshes access tokens when they expire.

In [22]:
auth = Gen3Auth(endpoint, creds)

6. Authentication finished.