Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Using GraphQL with Python
#!/usr/bin/python
# -*- coding: utf-8 -*-
import requests
def run_query(query): # A simple function to use requests.post to make the API call.
request = requests.post('https://graphql.bitquery.io/',
json={'query': query})
if request.status_code == 200:
return request.json()
else:
raise Exception('Query failed and return code is {}. {}'.format(request.status_code,
query))
# The GraphQL query
query = """
query{
bitcoin{
blocks{
count
}
}
}
"""
result = run_query(query) # Execute the query
print 'Result - {}'.format(result)
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.