|
| 1 | +--- |
| 2 | +title: Subgrounds |
| 3 | +--- |
| 4 | + |
| 5 | +Subgrounds is an intuitive Python library for querying subgraphs, built by [Playgrounds](https://playgrounds.network/). It allows you to directly connect subgraph data to a Python data environment, letting you use libraries like [pandas](https://pandas.pydata.org/) to perform data analysis! |
| 6 | + |
| 7 | +Subgrounds offers a simple Pythonic API for building GraphQL queries, automates tedious workflows such as pagination, and empowers advanced users through controlled schema transformations. |
| 8 | + |
| 9 | +## Getting Started |
| 10 | + |
| 11 | +Subgrounds requires Python 3.10 or higher and is available on [pypi](https://pypi.org/project/subgrounds/). |
| 12 | + |
| 13 | +```bash |
| 14 | +pip install --upgrade subgrounds |
| 15 | +# or |
| 16 | +python -m pip install --upgrade subgrounds |
| 17 | +``` |
| 18 | + |
| 19 | +Once installed, you can test out subgrounds with the following query. The following example grabs a subgraph for the Aave v2 protocol and queries the top 5 markets ordered by TVL (Total Value Locked), selects their name and their TVL (in USD) and returns the data as a pandas [DataFrame](https://pandas.pydata.org/pandas-docs/dev/reference/api/pandas.DataFrame.html#pandas.DataFrame). |
| 20 | + |
| 21 | +```python |
| 22 | +from subgrounds import Subgrounds |
| 23 | + |
| 24 | +sg = Subgrounds() |
| 25 | + |
| 26 | +# Load the subgraph |
| 27 | +aave_v2 = sg.load_subgraph( |
| 28 | + "https://api.thegraph.com/subgraphs/name/messari/aave-v2-ethereum") |
| 29 | + |
| 30 | +# Construct the query |
| 31 | +latest_markets = aave_v2.Query.markets( |
| 32 | + orderBy=aave_v2.Market.totalValueLockedUSD, |
| 33 | + orderDirection='desc', |
| 34 | + first=5, |
| 35 | +) |
| 36 | +# Return query to a dataframe |
| 37 | +sg.query_df([ |
| 38 | + latest_markets.name, |
| 39 | + latest_markets.totalValueLockedUSD, |
| 40 | +]) |
| 41 | +``` |
| 42 | + |
| 43 | +## Documentation |
| 44 | + |
| 45 | +Subgrounds is built and maintained by the [Playgrounds](https://playgrounds.network/) team and can be accessed on the [Playgrounds docs](https://docs.playgrounds.network/subgrounds). |
| 46 | + |
| 47 | +Since subgrounds has a large feature set to explore, here are some helpful starting places: |
| 48 | + |
| 49 | +- [Getting Started with Querying](https://docs.playgrounds.network/subgrounds/getting_started/basics/) |
| 50 | + - A good first step for how to build queries with subgrounds. |
| 51 | +- [Building Synthetic Fields](https://docs.playgrounds.network/subgrounds/getting_started/synthetic_fields/) |
| 52 | + - A gentle introduction to defining synthetic fields that transform data defined from the schema. |
| 53 | +- [Concurrent Queries](https://docs.playgrounds.network/subgrounds/getting_started/async/) |
| 54 | + - Learn how to level up your queries by parallelizing them. |
| 55 | +- [Exporting Data to CSVs](https://docs.playgrounds.network/subgrounds/faq/exporting/) |
| 56 | + - A quick article on how to seemlessly save your data as CSVs for further analysis. |
0 commit comments