Skip to content

Instantly share code, notes, and snippets.

Last active April 5, 2021 01:58
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
Star You must be signed in to star a gist
What would you like to do?
GraphQL example for PeptoidDB API
#importing requests and json module
import requests
import json
#returns the set of residues in peptoids with author given by input lastName
def authorToResidues(lastName):
#GrapQL query for authors by lastName and their published peptoids' residues
query = """
authors {
edges {
node {
peptoids {
edges {
node {
peptoidResidue {
edges {
node {
#sending request to /graphql route
url = ""
r =,json={'query':query})
#parsing response for author given by last name and then the residues in their peptoids
rDict = json.loads(r.text)
authorNodes = rDict['data']['authors']['edges']
for author in authorNodes:
if author['node']['lastName'] == lastName:
peptoids = author['node']['peptoids']['edges']
residues = [p['node']['peptoidResidue']['edges'] for p in peptoids]
residues = set([item['node']['longName'] for sublist in residues for item in sublist])
return residues #set object of peptoids found
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment