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.

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!

Initialize Subgrounds object with a playgrounds api key#
from subgrounds import Subgrounds

sg = Subgrounds.from_pg_key("PG_API_KEY")
The environment variable can be set any way you like!#
PLAYGROUNDS_API_KEY="PG_API_KEY"
This method is great since you don't need to change your code at all!#
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()

Internally, both method sets the request headers#
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,
])