Docs
Поиск⌘ K
  • Главная страница
  • О The Graph
  • Поддерживаемые сети
  • Protocol Contracts
  • Субграфы
    • Субпотоки
      • Token API
        • Hypergraph
          • AI Suite
            • Индексирование
              • Graph Horizon
                • Ресурсы
                  Субграфы > Запрос

                  2 минуты

                  Запросы к The Graph с использованием Python и 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 предлагает простой Pythonic API для создания GraphQL-запросов, автоматизирует утомительные рабочие процессы, такие как пагинация, и предоставляет расширенные возможности для опытных пользователей через управляемые преобразования схем.

                  Начало работы

                  Subgrounds requires Python 3.10 or higher and is available on 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])

                  Documentation

                  Subgrounds is built and maintained by the Playgrounds⁠ team and can be accessed on the Playgrounds docs⁠.

                  Since subgrounds has a large feature set to explore, here are some helpful starting places:

                  • Getting Started with Querying⁠
                    • A good first step for how to build queries with subgrounds.
                  • Building Synthetic Fields⁠
                    • A gentle introduction to defining synthetic fields that transform data defined from the schema.
                  • Concurrent Queries⁠
                    • Learn how to level up your queries by parallelizing them.
                  • Exporting Data to CSVs⁠
                    • Краткая статья о том, как легко сохранять данные в формате CSV для дальнейшего анализа.
                  ⁠Редактировать на GitHub⁠

                  LiveВведение
                  На этой странице
                  • Начало работы
                  • Documentation
                  The GraphСтатусТестовая сетьБрундовые ресурсыФорумБезопасностьПолитика конфиденциальностиУсловия обслуживания