examples Documentation

A set of examples around pytorch in Vision, Text, Reinforcement Learning, etc.

24,076 stars Python Python 1 file ยท ~17,435 tokens
RAW Doc

1. Project Overview & Quickstart (0xPlaygrounds/examples)

examples

TensorFlow examples

Repository Details

Note: High-volume repository documentation is actively indexed and synchronized by YakaAI.

2. Official Technical Reference & Guides (0xPlaygrounds/docs)

File: docs/api/faq/environment.md

Environment Vars

As listed in the docs page for subgrounds, environment variables are one of the easiest ways to access the Playgrounds API seemlessly throughout your projects.

What are they?

An environment variable is a named value set by the user, often used for configuration. Usually, the contain secrets like api keys so that a program can access them in a standardized manner.

{code-block} bash
:caption: Keys generally start with `$`, this is what ours look like.

$PLAYGROUNDS_API_KEY

Inserting into your shell

In most shells, it's relatively straightforward to insert your environment variable.

{code-block} bash
PLAYGROUNDS_API_KEY=pg-123456
python my_script.py

However, this won't persist if you restart your shell. For that, you'll need to add a value to your shell's profile or rc file. These files get ran when your shell launches, so they will always ensure your environment var is always loaded. You'll need to look up the correct file for your shell, here's a shortlist of some common ones:

  • bash
    • ~/.profile
    • ~/.bash_profile
    • ~/.bashrc
  • zsh (Often on MacOS)
    • ~/.profile
    • ~/.zshrc

If you don't have this file, feel free to create a new one. Then, you can fill it with this contents or append this line to an already existing one!

{code-block} bash
export PLAYGROUNDS_API_KEY=pg-123456

Once you set this in your file, you'll have to restart your shell for the changes to take effect.

{hint}
There's quite a few options here! Don't fret, likely something like `.profile` will work. Each one has a slightly different purpose such as whether the file will run in an interactive or non-interactive shell.

Benefits

Now, you are able to use the Subgrounds or AsyncSubgrounds object w/o needing to reference any api keys within your code. This will make your code more portable and easier to share with others!

{code-block} python
:caption: You'll no longer need to include any explicit API key reference in your code!

from subgrounds import Subgrounds

deployment = "..."

with Subgrounds() as sg:
    sg.load_subgraph("https://api.playgrounds.network/v1/proxy/deployments/id/{deployment}")
    sg.query_df(...)

File: docs/api/faq/index.md

FAQ

::::{grid} 1 2 2 2
:gutter: 4

{grid-item-card}
:link: query
:link-type: doc

<h3 class='gradient-text card-heading'>
What is a Query?
</h3>

We measure usage based on queries, but how do we define them?
{grid-item-card}
:link: environment
:link-type: doc

<h3 class='gradient-text card-heading'>
How to use environment vars?
</h3>

Environment vars are the easiest way to load your API key with Subgrounds!

::::

{toctree}
:caption: FAQ
:hidden:

query
environment

File: docs/api/faq/query.md

What is a Query?

In the Playgrounds API, queries are 1:1 to the number of requests made to the underlying decentralized API. Queries are not 1:1 with a singular subgrounds' snippet as a single subgrounds request could be getting hundreds of thousands of rows with a single line of code. Since subgrounds automatically handles pagination, it makes multiple GraphQL queries behind the scenes.

Examples

Generally, whatever is placed in the first argument correlates to the number of expected pages.

{{ thebe_button }}

{code-block} python
:class: thebe
:caption: Common setup for the examples (using the hosted service as an example)

from subgrounds import Subgrounds

sg = Subgrounds()
curve = sg.load_subgraph(
    "https://api.thegraph.com/subgraphs/name/messari/curve-finance-ethereum")

The following example will result in a single query:

{code-block} python
:class: thebe
:caption: Grabbing liquidity pool data

# default for `first` is 100
sg.query_df(
    curve.Query.liquidityPools
)

The following example will result in 10 queries:

{code-block} python
:class: thebe
:caption: Grabbing liquidity pool data

sg.query_df(
    curve.Query.liquidityPools(first=9000)
)
{code-block} python
:caption: This would still be 10 queries as both of these entities would get [merged](/subgrounds/getting_started/field_paths/merging).

sg.query_df(
    curve.Query.liquidityPools(first=9000),
    curve.Query.liquidityGauges(first=9000),
)
{note}
Just because you put a very high number for `first` (such as `1_000_000`), it doesn't mean it'll actually result in that many queries since there might be less than that many rows of data.

Nested Pagination

Since nested fields can also have their own set of arguments, defining first in them will result in nested pagination. This can greatly increase the number of queries made as each nested field will be multiplicative

The number of queries directly is related to the argument you put in first. If you only define first for the most top-level entities, than pagination is summed across all those fields. If you start defining first for sub-fields, then pagination can get multiplicative as for each top-level page, the whole series of sub-pages would be queried.

{code-block} python
:caption: This would still be 100 (10ใƒป10) queries due to nested pagination and return 81 million (9000ใƒป9000) rows.

pools = curve.Query.liquidityPools(first=9000)

sg.query_df(
    pools.dailySnapshots(first=9000)
)

File: docs/api/reference/proxy/deployment_id.md

Deployment ID

{bdg-info-line}/v1/proxy/

`deployments/id/:deployment_id`

{bdg-dark}`POST`

Make a graphql request to the subgraph identified by the id deployment_id.

URL Parameters

{bdg-info-line}deployment_id string
The decentralized network deployment ID you are querying

Request Body (JSON)

{bdg-info-line}query string
The GraphQL query itself

{bdg-info-line}variables dict?
Values for the variables used within the GraphQL query (if any)

Example

bash
curl https://api.playgrounds.network/v1/proxy/deployments/id/QmcPHxcC2ZN7m79XfYZ77YmF4t9UCErv87a9NFKrSLWKtJ \
    -H 'Content-Type: application/json' \
    -H 'Playgrounds-Api-Key: PG_API_KEY' \
    -d '{"query":"{protocols {name totalPoolCount}}"}'

Response:

json
{
    "data": {
        "protocols": [
            {
                "name": "Uniswap V3",
                "totalPoolCount": 13767
            }
        ]
    }
}

File: docs/api/reference/proxy/subgraph_id.md

Subgraph ID

{bdg-info-line}/v1/proxy/

`subgraphs/id/:subgraph_id`

{bdg-dark}`POST`

Make a graphql request to the subgraph identified by the id subgraph_id.

{important}
This endpoint only works with subgraphs deployed on The Graph's Ethereum decentralized service and **not** the Arbitrum decentralized service.

If you want to query a subgraph hosted on the Arbitrum decentralized service, use the [proxy by deployment id](deployment_id.md) endpoint.

URL Parameters

{bdg-info-line}subgraph_id string
The decentralized network subgraph ID you are querying

Request Body (JSON)

{bdg-info-line}query string
The GraphQL query itself

{bdg-info-line}variables dict?
Values for the variables used within the GraphQL query (if any)

Example

bash
curl https://api.playgrounds.network/v1/proxy/subgraphs/id/ELUcwgpm14LKPLrBRuVvPvNKHQ9HvwmtKgKSH6123cr7 \
    -H 'Content-Type: application/json' \
    -H 'Playgrounds-Api-Key: PG_API_KEY' \
    -d '{"query":"{protocols {name totalPoolCount}}"}'

Response:

json
{
    "data": {
        "protocols": [
            {
                "name": "Uniswap V3",
                "totalPoolCount": 13767
            }
        ]
    }
}

File: docs/api/reference/proxy.md

Subgraph Proxy

{bdg-info-line}/v1/proxy/


The proxy endpoints provide access to subgraphs hosted on The Graph's decentralized network without the need to manage GRT tokens or interact with smart contracts.

The proxy endpoint gets its name from the fact that all endpoints originating from it mirror an equivalent endpoint available on The Graph.

For example, consider the following query URL:

bash
https://gateway.thegraph.com/api/[api-key]/subgraphs/id/3nXfK3RbFrj6mhkGdoKRowEEti2WvmUdxmz73tben6Mb

The equivalent Playgrounds API URL going through our proxy endpoint would be:

bash
https://api.playgrounds.network/v1/proxy/subgraphs/id/ELUcwgpm14LKPLrBRuVvPvNKHQ9HvwmtKgKSH6123cr7
{note}
Notice that the URL is mirrored: both URLs contain the `subgraphs/id/3nXfK3RbFrj6mhkGdoKRowEEti2WvmUdxmz73tben6Mb` path!
{important}
Unlike The Graph's endpoint where the Graph API key is inserted in the URL, Playgrounds API endpoints do not contain the user's API key in the URL itself. Instead, the API key is provided via a header value.

::::{grid} 1 2 2 2
:gutter: 3

{grid-item-card}
:link: proxy/subgraph_id
:link-type: doc

<h3 class='gradient-text card-heading'>
    Subgraph ID
</h3>

{bdg-info-line}`/v1/proxy/subgraphs/id`
{grid-item-card}
:link: proxy/deployment_id
:link-type: doc

<h3 class='gradient-text card-heading'>
    Deployment ID
</h3>

{bdg-info-line}`/v1/proxy/deployments/id`

::::

{toctree}
:caption: API Reference
:hidden:

proxy/subgraph_id
proxy/deployment_id

File: docs/api/api-reference.md

API Reference

The Playgrounds API is organized around REST and currently features only one top-level resource accessible with an API key: the proxy resource.

Our API accepts request parameters either via a JSON-encoded request body (for POST requests) or query parameters (for GET requests). Unless explicitly mentioned, all API endpoints return JSON-encoded responses.

Authentication

The Playgrounds API uses API keys to authenticate requests. You can view and manage your API keys in the Playgrounds App.

Your API keys carry many privileges, so be sure to keep them secure! Do not share your secret API keys in publicly accessible areas such as GitHub, client-side code, and so forth.

Authentication to the API is performed via the custom Playgrounds authorization header Playgrounds-Api-Key. To authenticate, include the following into the header of your request (replacing pg-abcdefghijk with your own)!

py
Playgrounds-Api-Key: pg-abcdefghijk
{note}
In `subgrounds`, you can set the `$PLAYGROUNDS_API_KEY` environment variable to your API key and use our endpoints โ€” the library will handle all of the authentication on your behalf!
{toctree}
:caption: API Reference
:hidden:

reference/proxy

Endpoints

We currently only host a single endpoint.

::::{grid} 1 2 2 2
:gutter: 3

{grid-item-card}
:link: reference/proxy
:link-type: doc

<h3 class='gradient-text card-heading'>
    Subgraph Proxy
</h3>

{bdg-info-line}`/v1/proxy`

::::


File: docs/api/index.md

Playgrounds API

Simplify your subgraph queries to the The Graph's decentralized network!

The Playgrounds API is a solution aimed at streamlining the user experience with The Graph's decentralized network. It eliminates the need for traditional wallet and GRT management by providing a convenient and straightforward API key and URL. Users can effortlessly harness the full potential of the decentralized ecosystem.

The Playgrounds API also allows users to download datasets from The Graph's decentralized service via a REST API.

Advantages

  • SaaS-like experience for decentralized subgraphs
  • Fully Integrated with {doc}Subgrounds <subgrounds>
  • Monitor your API key usage

::::{grid} 1 2 2 2
:gutter: 3

{grid-item-card}
:link: https://app.playgrounds.network

<h3 class='gradient-text card-heading'>
Launch Playgrounds
</h3>

Access our app to create API keys
{grid-item-card}
:link: key
:link-type: doc

<h3 class='gradient-text card-heading'>
Getting Started
</h3>

Get started in less than **five minutes**
{grid-item-card}
:link: faq/index
:link-type: doc

<h3 class='gradient-text card-heading'>
FAQ
</h3>

Common questions about the Playgrounds API
{grid-item-card}
:link: api-reference
:link-type: doc

<h3 class='gradient-text card-heading'>
API Reference
</h3>

Full reference on each endpoint we offer

::::



File: docs/api/key.md

Getting a Playgrounds API Key

To start using the Playgrounds API, you'll first need to aquire an API key from our platform.

1. Creating your Playgrounds account

The first step in acquiring a Playgrounds API key is to create a Playgrounds account via our signup page.

:::{centered} {guilabel}Create Account {octicon}triangle-right;1em;color-foreground-secondary {guilabel}Verify Email
:::

2. Create your Playgrounds API key

Once you have created your Playgrounds account and are logged into the Playgrounds app, create a new API key.

:::{centered} {guilabel}Generate API Key
:::

3. Copy your Playgrounds API key

Congratulations, you now have a Playgrounds API key that you can use to query decentralized network subgraphs through our proxy API! To copy the actual key to your clipboard:

:::{centered} {fas}ellipsis-vertical {octicon}triangle-right;1em;color-foreground-secondary {guilabel}Copy API Key
:::

OR

:::{centered} Token: {guilabel}โ€ขโ€ขโ€ขโ€ขโ€ขโ€ขโ€ขโ€ขโ€ขโ€ข
:::

{seealso}
All Playgrounds API keys start with the sequence `pg-` to differentiate them from other API keys (such as The Graph's keys).