Leveraging the Subgrounds Python library to interact with subgraphs.
Overview
DataFrame
.Subgrounds is a Python library by the Playgrounds team designed specifically to reduce friction present within python-based subgraph querying.Environment setup
3.10
, but less than 4.0
In this case, the only dependency here is subgrounds
, which you can install by running: pip install subgrounds
Defining the subgraph object
sg
and CHAINSTACK_SUBGRAPH
.sg
can be set equal to Subgrounds()
CHAINSTACK_SUBGRAPH
can be set equal to the query URL of a chosen subgraph you’ve deployed on Chainstack.load_subgraph
function on sg
and pass in CHAINSTACK_SUBGRAPH
.Defining the query
latest_pairs
, or a variable name of your choice, which will contain the query, subgraph.Query.{root field}
, in this case, we’ll be using the pairs
root field.orderBy
, orderDirection
, and first
.Understanding the response
DataFrame
, we can see a truncated view of the table containing the data we queried.