Subgrounds Integration#
While you can certainly use the Playgrounds proxy alone by submitting requests with a valid Playgrounds API key, pairing it with Subgrounds simplifies and streamlines the querying and data analysis from decentralized subgraphs.
Click for Interactive Documentation
Clicking this button will enable editing and execution of the code-blocks on this page. Learn more here.
1. Using your Playgrounds API Key in Subgrounds#
There are two main ways to validate your API key with subgrounds.
Note
Replace "PG_API_KEY"
with API key gathered from earlier!
from subgrounds import Subgrounds
sg = Subgrounds.from_pg_key("PG_API_KEY")
PLAYGROUNDS_API_KEY="PG_API_KEY"
from subgrounds import Subgrounds
sg = Subgrounds()
Warning
This method will produce a RuntimeWarning
if $PLAYGROUNDS_API_KEY
does not look like valid.
It will also be overriden if the headers are set manually, or via Subgrounds.from_pg_key()
from subgrounds import Subgrounds
sg = Subgrounds(headers={"Playgrounds-Api-Key": "PG_API_KEY"})
2. Query a decentralized subgraph#
Once the Subgrounds
object has been initialized with the custom header containing your API key, you can query a decentralized network subgraph through our proxy endpoint just like you would query any other subgraph.
subgraph = sg.load_subgraph(
"https://api.playgrounds.network/v1/proxy/subgraphs/id/ELUcwgpm14LKPLrBRuVvPvNKHQ9HvwmtKgKSH6123cr7"
)
sg.query_df([
subgraph.Query.tokens.id,
subgraph.Query.tokens.symbol,
])