Skip to content

Evan-Kim2028/subgraph-query-portal

Repository files navigation

Project generated with PyScaffold

Subgraph Query Portal

queryportal is a Subgraph query management library and makes it easy to query cross-chain, cross-subgraph data on the decentralized Graph Network.

Tools

This project utilizes Subgraph endpoints from Messari and Subgrounds, an open-source Python library built by Playgrounds. Data is transformed using Polars.

Subgraphs

Subgraphs are custom APIs built on indexed blockchain data that can be queried using GraphQL endpoints. For a list of standardized subgraph endpoints by Messari, see here.

Subgrounds

Subgrounds is a Pythonic data access library that represents Subgraph schemas as Python objects, allowing Subgraph GraphQL queries to be written exclusively in Python. Subgrounds leverages functional programming design patterns to express subgraphs as. This allows users to integrate Subgraphs into functional programming python data pipelines in Python.

Polars

Polars is a blazingly fast DataFrames library implemented in Rust using Apache Arrow Columnar Format as the memory model.

Library Dependencies

  • Python >= 3.10
  • Subgrounds = 1.5.2
  • Polars
  • Pyarrow

Installation

  1. Install virtualenv:

    python -m venv .venv            
    source .venv/bin/activate   
  2. Install from github source:

    pip install git+https://github.com/Evan-Kim2028/subgraph-query-portal.git

Examples

Run the following commands from the root directory of the project.

For a list of examples, please see https://github.com/Evan-Kim2028/queryportal_notebooks which is a repository of queryportal notebook examples.

Import Package

If you want to use this package in your own project, you can import as follows:

import queryportal

Local Development

To enable editable mode, use the pip install -e . command. This installs the package in a way that allows you to modify the source code and have the changes take effect immediately. However, be cautious when editing the source files, especially if you have also installed the package from GitHub. This may result in conflicting versions of the package.

pip install -e .

For Developers

Queryinterface is an abstract class that defines the interface for all subgraph queries via the query() method.

Some reasons why a developer would want to contribute their subgraph queries to this project: - Provides a common interface for querying subgraphs - Provides polars dataframe output by default - Use existing subgraph queries as building blocks for other queries

Query the Decentralized Graph Network

Create a .env file in the directory and enter the playgrounds api key PG_KEY =api-key

Since decentralized endpoints are defined by hashes, there is no easy default for naming decentralized subgraphs. Thus the main difference for querying the Graph Network compared to the hosted network is that the endpoint will look different and be submitted as a dictionary.

The decentralized endpoint formatting is https://api.playgrounds.network/v1/proxy/subgraphs/id/subgraph_id where subgraph_id is the ID of the subgraph. These can be found by searching https://thegraph.com/explorer. For example the subgraph key for uniswap is found here https://thegraph.com/explorer/subgraphs/2szAn45skWZFLPUbxFEtjiEzT1FMW8Ff5ReUPbZbQxtt?view=Overview&chain=mainnet and is 2szAn45skWZFLPUbxFEtjiEzT1FMW8Ff5ReUPbZbQxtt.