2 分
Query The Graph with Python and Subgrounds
Subgrounds is an intuitive Python library for querying Subgraphs, built by Playgrounds. It allows you to directly connect Subgraph data to a Python data environment, letting you use libraries like pandas to perform data analysis!
Subgroundsは、GraphQLクエリを構築するためのシンプルなPythonic APIを提供し、ページ分割のような面倒なワークフローを自動化し、制御されたスキーマ変換によって高度なユーザーを支援します。
はじめに
SubgroundsはPython 3.10以降を必要とし、pypiで利用可能です。
1pip install --upgrade subgrounds2# または3python -m pip install --upgrade subgrounds
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.
1from subgrounds import Subgrounds23sg = Subgrounds()45# Load the Subgraph6aave_v2 = sg.load_subgraph(7 "https://api.thegraph.com/subgraphs/name/messari/aave-v2-ethereum")89# Construct the query10latest_markets = aave_v2.Query.markets(11 orderBy=aave_v2.Market.totalValueLockedUSD,12 orderDirection='desc',13 first=5,14)15# Return query to a dataframe16sg.query_df([17 latest_markets.name,18 latest_markets.totalValueLockedUSD,19])
ドキュメンテーション
SubgroundsはPlaygroundsチームによってビルド、メンテナンスされており、Playgrounds docsからアクセスすることができます。
Subgroundsには多くの機能があるので、まずはここから始めましょう:
-
- クエリ入門](https://docs.playgrounds.network/subgrounds/getting_started/basics/)
-
- subgroundsでクエリを構築するための最初のステップです。
- {合成フィールドの構築](https://docs.playgrounds.network/subgrounds/getting_started/synthetic_fields/)
-
- スキーマから定義されたデータを変換する合成フィールドの定義をやさしく紹介します。
-
- 並行クエリ
- クエリを並列化することで、クエリをレベルアップする方法を紹介します。
- データをCSVにエクスポートする
- A quick article on how to seamlessly save your data as CSVs for further analysis.