Run A Query
This tutorial assumes you have already signed up for a Flipside Account and generated an API key here in Flipside's Data Studio.
1. Install the SDK (or skip to #2 if using the API directly)
pip install flipside
2. Execute your Query
from flipside import Flipside
# Initialize `Flipside` with your API Key and API Url
flipside = Flipside("<YOUR_API_KEY>", "https://api-v2.flipsidecrypto.xyz")
sql = """
SELECT
date_trunc('hour', block_timestamp) as hour,
count(distinct tx_hash) as tx_count
FROM ethereum.core.fact_transactions
WHERE block_timestamp >= GETDATE() - interval'7 days'
GROUP BY 1
"""
# Run the query against Flipside's query engine and await the results
query_result_set = flipside.query(sql)
3. Paginate over the Results
# what page are we starting on?
current_page_number = 1
# How many records do we want to return in the page?
page_size = 100
# set total pages to 1 higher than the `current_page_number` until
# we receive the total pages from `get_query_results` given the
# provided `page_size` (total_pages is dynamically determined by the API
# based on the `page_size` you provide)
total_pages = 2
# we'll store all the page results in `all_rows`
all_rows = []
while current_page_number <= total_pages:
results = flipside.get_query_results(
query_result_set.query_id,
page_number=current_page_number,
page_size=page_size
)
total_pages = results.page.totalPages
if results.records:
all_rows = all_rows + results.records
current_page_number += 1
Last updated
Was this helpful?