Docs
搜索⌘ K
  • 主页
  • 关于 The Graph
  • 支持的网络
  • 协议合约
  • 子图
    • 子流
      • 代币 API
        • AI Suite
          • 索引
            • 资源
              子图 > 查询

              2 分钟

              使用 Python 和 Subground查询The Graph

              Subgrounds是一个用于查询子图的直观的 Python 库,由 Playgrounds⁠构建。 它允许您直接将子图数据连接到 Python 数据环境。 让您使用像 pandas⁠这样的库来进行数据分析!

              Subgrounds提供了一个简单的 Pythonic API,用于构建GraphQL 查询,实现分页等冗余工作流自动化,并通过受控模式转换增强高级用户的能力。

              开始

              Subgrounds需要 Python 3.10或更高版本,可在 pypi⁠上获取。

              1pip install --upgrade subgrounds2# or3python -m pip install --upgrade subgrounds

              安装完毕后,您可以通过以下查询测试Subgrounds。 下面的示例为 Aave v2 协议拍摄了子图并查询了TVL 订购的前 5 个市场(总值锁定), 选择他们的名字和他们的 TVL (美元) 并返回数据为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⁠团队构建和维护的,可以在 Playplace文档⁠上访问。

              由于Subgrounds有大的功能可以探索,在这里有一些有用的起始地点:

              • 开始查询⁠
                • 用subground构建查询,很好的第一步。
              • 构建合成字段⁠
                • 对定义可转换从模式中定义的数据的合成字段作了简要介绍。
              • 开始查询⁠
                • 学习如何平行地提升您的查询。
              • 导出数据到CSV⁠
                • 一个关于如何无缝保存您的数据为 CSV以便进一步分析的快速文章。
              ⁠在GitHub上编辑⁠

              Live介绍
              在此页面上
              • 开始
              • 文档
              The GraphStatusTestnetBrand AssetsForum安全Privacy PolicyTerms of Service