''' Script example to use the DisGeNET REST API with the new authentication system ''' #For this example we are going to use the python default http library import requests #Build a dict with the following format, change the value of the two keys your DisGeNET account credentials, if you don't have an account you can create one here https://www.disgenet.org/signup/ auth_params = {"email":"change@this.email","password":"changethis"} api_host = "https://www.disgenet.org/api" api_key = None s = requests.Session() try: r = s.post(api_host+'/auth/', data=auth_params) if(r.status_code == 200): #Lets store the api key in a new variable and use it again in new requests json_response = r.json() api_key = json_response.get("token") print(api_key + "This is your user API key.") #Comment this line if you don't want your API key to show up in the terminal else: print(r.status_code) print(r.text) except requests.exceptions.RequestException as req_ex: print(req_ex) print("Something went wrong with the request.") if api_key: #Add the api key to the requests headers of the requests Session object in order to use the restricted endpoints. s.headers.update({"Authorization": "Bearer %s" % api_key}) #Lets get all the diseases associated to a gene eg. APP (EntrezID 351) and restricted by a source. gda_response = s.get(api_host+'/gda/gene/351', params={'source':'UNIPROT'}) print(gda_response.json()) if s: s.close()