Docs
Cerca⌘ K
  • Home
  • Informazioni su The Graph
  • Supported Networks
  • Protocol Contracts
  • Subgraphs
    • Substreams
      • Token API
        • Hypergraph
          • AI Suite
            • Indexing
              • Resources
                Subgraphs > Querying

                2 minutes

                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 offre una semplice API Pythonic per la creazione di query GraphQL, automatizza i flussi di lavoro più noiosi come la paginazione, e dà agli utenti avanzati la possibilità di effettuare trasformazioni controllate dello schema.

                Per cominciare

                Subgrounds richiede Python 3.10 o superiore ed è disponibile su pypi⁠.

                1pip install --upgrade subgrounds2# or3python -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])

                Documentazione

                Subgrounds è costruito e mantenuto dal team di Playgrounds⁠ e si può accedere su Playgrounds docs⁠.

                Poiché le funzionalità di subgrounds sono numerose e tutte da esplorare, ecco alcuni punti di partenza utili:

                • Introduzione alle query⁠
                  • Un buon primo passo per costruire le query con subgrounds.
                • Costruire campi sintetici⁠
                  • Una leggera introduzione alla definizione di campi sintetici che trasformano i dati definiti dallo schema.
                • Query concorrenti⁠
                  • Imparate a migliorare le vostre query parallelizzandole.
                • Esportazione di dati in CSV⁠
                  • A quick article on how to seamlessly save your data as CSVs for further analysis.
                ⁠Edit on GitHub⁠

                LiveIntroduzione
                On this page
                • Per cominciare
                • Documentazione
                The GraphStatusTestnetBrand AssetsForumSecurityPrivacy PolicyTerms of Service