2 मिनट
Query The Graph with Python and Subgrounds
Subgrounds एक सहज Python लाइब्रेरी है जो Subgraph को क्वेरी करने के लिए बनाई गई है, जिसे Playgrounds द्वारा विकसित किया गया है। यह आपको सीधे Python डेटा वातावरण से Subgraph डेटा को कनेक्ट करने की अनुमति देता है, जिससे आप pandas जैसी लाइब्रेरी का उपयोग करके डेटा विश्लेषण कर सकते हैं!
Subgrounds GraphQL queries के निर्माण के लिए एक सरल Pythonic API प्रदान करता है, pagination जैसे कठिन workflows को स्वचालित करता है, और नियंत्रित schema परिवर्तनों के माध्यम से उन्नत users को strong बनाता है।
शुरू करना
Subgrounds requires Python 3.10 or higher and is available on pypi.
1pip install --upgrade subgrounds2# or3python -m pip install --upgrade subgrounds
एक बार इंस्टॉल करने के बाद, आप नीचे दिए गए क्वेरी के साथ subgrounds का परीक्षण कर सकते हैं। नीचे दिया गया उदाहरण Aave v2 प्रोटोकॉल के लिए एक Subgraph प्राप्त करता है और TVL (Total Value Locked) के आधार पर शीर्ष 5 बाजारों को क्रमबद्ध करता है, उनके नाम और उनका TVL (USD में) चुनता है और डेटा को एक pandas DataFrame के रूप में लौटाता है।
1from subgrounds import Subgrounds23sg = Subgrounds()45# Subgraph लोड करें6aave_v2 = sg.load_subgraph(7 "https://api.thegraph.com/subgraphs/name/messari/aave-v2-ethereum")89# क्वेरी बनाएँ10latest_markets = aave_v2.Query.markets(11 orderBy=aave_v2.Market.totalValueLockedUSD,12 orderDirection='desc',13 first=5,14)1516# क्वेरी को DataFrame में बदलें17sg.query_df([18 latest_markets.name,19 latest_markets.totalValueLockedUSD,20])
Documentation
Subgrounds is built and maintained by the Playgrounds team and can be accessed on the Playgrounds docs.
चूंकि subgrounds में तलाशने के लिए एक बड़ी सुविधा मौजूद है, इसलिए यहां कुछ उपयोगी शुरुआती स्थान दिए गए हैं:
- Getting Started with Querying
- Subgrounds के साथ queries कैसे बनाएं, इसके लिए एक अच्छा पहला कदम।
- 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
- कैसे अपने डेटा को CSVs के रूप में सहजता से सहेजें ताकि आगे के विश्लेषण के लिए इसका उपयोग किया जा सके।