Glassnode API Python Tutorial (2022)

This article demonstrates how you can use the Python client for Glassnode API for on-chain data analytics. 

You will see how to call various Glassnode API endpoints to retrieve useful blockchain metrics, e.g., market insights,  blockchain information, fees, supply, transaction insights, etc. 


You will create Python scripts that fetch Glassnode API data using glassnode-api-python-client and the Python request method.

What Is Glassnode?

Glassnode is an on-chain data analytics platform founded by Rafael Schultze Kraft in 2007 to provide insights into complex crypto data. Glassnode ingests blockchain data and employs AI techniques to provide insights into the various networks.

How Do You Use Glassnode Data?

Glassnode insights can help you make crucial investment decisions. For example, Glassnode can help you identify cryptocurrencies with the highest trading volumes. You may want to invest in such cryptocurrencies instead of dormant currencies. 

How do I Download Data from Glassnode?

Two main ways to download data from Glassnode:

  1. Glassnode Studio
  2. Glassnode REST API (which you will see in this tutorial)

Is Glassnode Free?

Glassnode offers four pricing plans:

  • Standard: Free
  • Advanced: $29
  • Professional: $799
  • Institutional: Tailored plan, price varies. 

Glassnode API metrics are categorized into three tiers. Access to functionalities within a specific tier depends upon your subscription. You can only access tier 1 metrics with a standard (free) account. 

Is Glassnode Reliable?

Glassnode doesn’t generate its data; it extracts information from mostly public blockchain data. Some users report that Glassnode insights are often not based on the latest data.

Why Should I Use Glassnode?

  1. Glassnode offers a free standard account. 
  2. Glassnode Studio provides plenty of options to navigate intelligent on-chain data metrics.
  3. Glassnode Academy is an excellent resource learning resource for beginners.

Why Should I Not Use Glassnode?

  1. Some users complain that Glassnode insights are outdated
  2. Not very user-friendly for beginners. Though, you can get help from Glassnode Academy. 

What Can You Do with the Glassnode API?

With Glassnode API, you can develop customized software applications that fetch intelligent data insights from Glassnode.

Glassnode API pricing

Glassnode doesn’t have a different pricing plan for its API. The access to Glassnode API depends upon your default Glassnode subscription plan. 

Getting Started with Glassnode API in Python

Access to Glassnode API requires an API you can get by signing up with Glassnode.

Signing up for a Glassnode Account

Go to glassnode.com and click the “Sign Up” button at the top right corner of the page.

Glassnode Signup Page

Fill out the signup form by entering your first name, last name, email, and password. Click the “Sign Up” button. 

Glassnode Signup Form

You will receive an email for account activation. Click the activation link in your email. Once your account is activated, you will see the following message. 

Get your API key from Glassnode Studio

Go to the API settings page and click the “Generate Key” button to generate your Glassnode API Key. 

You can view the API documentation by clicking the “View API Documentation” button. 

Simple Example of Fetching Data from Glassnode API in Python

You can use the Glassnode API Python Client library or the Python request function to make calls to Glassnode API. 

Glassnode API Python Client Library Example

The following command installs the glassnode-api-python-client library. 

pip install glassnode

The first step is to Import the GlassnodeClient class from the glassnode module and pass your API key to the class constructor. 

You can use the get() method from the GlassnodeClient class to make a Glassnode API call. You must pass the endpoint and API call names to the get() method. You also need to pass a Python dictionary containing the API call parameters. 

For example, the script below makes the following API call. 

https://api.glassnode.com/v1/metrics/addresses/active_count

Here, the endpoint name is highlighted in green, while the metric inside the endpoint is highlighted in yellow. 

The call above returns the number of active bitcoin accounts on the blockchain, as we pass “BTC” as the symbol value to the parameter “a,” which corresponds to the asset symbol. 

The response from the API call is a list of dictionaries. Each dictionary contains two items: t and v, where t corresponds to the period, and v corresponds to the active account values.

from glassnode import GlassnodeClient
import os
import pandas as pd

api_key = os.environ['GN-Key']

## behind the scene API call
## https://api.glassnode.com/v1/metrics/addresses/active_count

client = GlassnodeClient(api_key)
data = client.get("addresses", "active_count", {"a": "BTC"})
print(type(data))
print(data[0].keys())

Output:

<class 'list'>
dict_keys(['t', 'v'])

For a better view, you can convert the list of dictionaries into a Pandas dataframe using the following script. 

## create a pandas dataframe using the list of dictionaries
df = pd.DataFrame.from_dict(data)
print(df.shape)
df.tail()

Output:

Glassnode API Python Client Output

By default, the time values are in UNIX format. The following script can convert the time values to ISO date format.

import datetime
def convert_date(unix_date):
    return datetime.datetime.fromtimestamp(int(unix_date)).strftime('%Y-%m-%d') 
df["t"] = df["t"].apply(convert_date)
df.tail()

Output:

Glassnode API Python Client ISO Dates Output
The API query parameters allow you to filter results from the Glassnode API.

For instance, the script returns BTC’s 24-hour active account addresses from January 23, 2009, to February 02, 2029.
from glassnode import GlassnodeClient
import os
import pandas as pd

api_key = os.environ['GN-Key']

## behind the scene API call
## https://api.glassnode.com/v1/metrics/addresses/active_count

client = GlassnodeClient(api_key)

since = 1232668800 # 2009-01-23
until = 1233532800 # 2009-02-03
resolution = "24h"

params = {"a": "BTC", "s": since, "u": until, "i": resolution}
data = client.get("addresses", "active_count", params)
df = pd.DataFrame.from_dict(data)
df["t"] = df["t"].apply(convert_date)
print(df.shape)
df.tail(20)

Output:

Glassnode API Python Client Params Filter Output
You can find the details of the query parameter by clicking the API call, as shown in the following screenshot.
Glassnode API Parameters Info
Glassnode API Request Function Example

The glassnode-api-python-client library can be a litter slower as it adds a programming layer over the Python requests library. 

If speed is a concern, you can directly make calls to the Glassnode API via the Python request function, as demonstrated in the following script.
import json
import requests
import os
import pandas as pd

api_key = os.environ['GN-Key']

# make API request
res = requests.get('https://api.glassnode.com/v1/metrics/addresses/active_count',
    params={'a': 'BTC', 'api_key': api_key})

# convert to pandas dataframe
df = pd.read_json(res.text, convert_dates=['t'])
df.head()

Output:

Glassnode API Python Request Method Raw Output
Similarly, the following script shows how to pass query parameters while calling the Glassnode API using the request method. 
import json
import requests
import os
import pandas as pd

api_key = os.environ['GN-Key']


since = 1232668800 # 2009-01-23
until = 1233532800 # 2009-02-03
resolution = "24h"

# make API request
res = requests.get('https://api.glassnode.com/v1/metrics/addresses/active_count',
    params={"a": "BTC", "s": since, "u": until, "i": resolution, 'api_key': api_key})


# convert to pandas dataframe
df = pd.read_json(res.text, convert_dates=['t'])
df.tail(20
Glassnode API Python Request Method Params Filter Output
Getting a List of Metrics

You can get a list of all Glassnode API metrics via the 

https://api.glassnode.com/v2/metrics/endpoints API call, as demonstrated in the following script. 

The output contains information such as the metric path, tier, supported assets and currencies, the time resolution, and the output format.
import json
import requests
import os
import pandas as pd

api_key = os.environ['GN-Key']


# make API request
res = requests.get('https://api.glassnode.com/v2/metrics/endpoints',
    params={'api_key': api_key})

# convert to pandas dataframe
df = pd.read_json(res.text, convert_dates=['t'])
df.head()

Output:

Glassnode API Metrics Endpoint Output
Getting a List of Assets

You can get information about all the assets using the https://api.glassnode.com/v1/metrics/assets API call, as shown in the following script.
import json
import requests
import os
import pandas as pd

api_key = os.environ['GN-Key']


# make API request
res = requests.get('https://api.glassnode.com/v1/metrics/assets',
    params={'api_key': api_key})

# convert to pandas dataframe
df = pd.read_json(res.text, convert_dates=['t'])
df.head()

Output:

Glassnode API Assets Endpoint Output
What are Glassnode API Endpoints?
Glassnode API offers 17 endpoints listed below:

Addresses
Blockchain
DeFi
Derivates
Distribution
Entities
ETH 2.0
Fees
Indicators
Institutions
Lightening
Market
Mempool
Mining
Protcols
Supply
Transactions

Out of these endpoints, metrics from Lightning, DeFi, Derivates, Distribution, Entities, and Mempool endpoints are not available with the standard subscription. 

The following sections will show you how to call the metrics available with the standard subscriptions. All of these metrics belong to the tier 1 metrics category. 
Addresses Endpoint

The addresses API endpoint returns information related to the addresses involved in a blockchain transaction. 

The following addresses metrics are available with the standard subscription. 






Description
Path
Active Addresses
The number of unique addresses active in a successful transaction
https://api.glassnode.com/v1/metrics/addresses/active_count
Sending Addresses
The number of unique sending addresses active in a successful transaction
https://api.glassnode.com/v1/metrics/addresses/sending_count
Receiving Addresses
The number of unique receiving addresses active in a successful transaction
https://api.glassnode.com/v1/metrics/addresses/receiving_count
New Addresses
The number of unique addresses appearing for the first time in a successful transaction
https://api.glassnode.com/v1/metrics/addresses/new_non_zero_count
Total Addresses 
The number of all unique addresses involved in a transaction of the native coin in a network
https://api.glassnode.com/v1/metrics/addresses/count

Refer to the complete list of addressee metrics to know more about other metrics. 

The following script demonstrates how to call the metrics mentioned above. 

We iterate through the list of API calls using a for loop. In each iteration, we convert the response from the API call to a Pandas dataframe, which we append to a Python list. Finally, we concatenate the list of Pandas dataframe. 

The dataframe columns in the output dataset correspond to metric names appearing in API calls.
Glassnode API Assets Endpoint Output

What are Glassnode API Endpoints?

Glassnode API offers 17 endpoints listed below:

Out of these endpoints, metrics from Lightning, DeFi, Derivates, Distribution, Entities, and Mempool endpoints are not available with the standard subscription. 

The following sections will show you how to call the metrics available with the standard subscriptions. All of these metrics belong to the tier 1 metrics category. 

Addresses Endpoint

The addresses API endpoint returns information related to the addresses involved in a blockchain transaction. 

The following address metrics are available with the standard subscription. 

DescriptionPath
Active AddressesThe number of unique addresses active in a successful transactionhttps://api.glassnode.com/v1/metrics/addresses/active_count
Sending AddressesThe number of unique sending addresses active in a successful transactionhttps://api.glassnode.com/v1/metrics/addresses/sending_count
Receiving AddressesThe number of unique receiving addresses active in a successful transactionhttps://api.glassnode.com/v1/metrics/addresses/receiving_count
New AddressesThe number of unique addresses appearing for the first time in a successful transactionhttps://api.glassnode.com/v1/metrics/addresses/new_non_zero_count
Total Addresses The number of all unique addresses involved in a transaction of the native coin in a networkhttps://api.glassnode.com/v1/metrics/addresses/count

Refer to the complete list of addressee metrics to know more about other metrics. 

The following script demonstrates how to call the metrics mentioned above. 

We iterate through the list of API calls using a for loop. In each iteration, we convert the response from the API call to a Pandas dataframe, which we append to a Python list. Finally, we concatenate the list of Pandas dataframe. 

The dataframe columns in the output dataset correspond to metric names appearing in API calls.

import json
import requests
import os
import pandas as pd

api_key = os.environ['GN-Key']

api_calls = ["https://api.glassnode.com/v1/metrics/addresses/active_count", # Active Addresses 
             "https://api.glassnode.com/v1/metrics/addresses/sending_count", # Sending Addresses 
             "https://api.glassnode.com/v1/metrics/addresses/receiving_count", # Receiving Addresses 
             "https://api.glassnode.com/v1/metrics/addresses/new_non_zero_count", # New Addresses  
             "https://api.glassnode.com/v1/metrics/addresses/count" # Total Addresses
            ]

results = []
for call in api_calls:
    
    endpoint_name = call.split("/")[-1]
    
    # make API request
    res = requests.get(call, 
                       params={"a": "BTC", 'api_key': api_key})

    # convert to pandas dataframe
    df = pd.read_json(res.text, convert_dates=['t'])
    
    # rename dataframe column names
    df.columns = ["Time", endpoint_name]
    
    # set Time as the index column
    df.set_index("Time", inplace = True)
    # adding the result to a list of pandas dataframe
    results.append(df)
    
# concatenating all dataframes horizontally
results_df = pd.concat(results, axis=1)
results_df.tail()

Output:

Glassnode API Addresses Endput Output
Blockchain Endpoint

The blockchain endpoint provides metrics for blockchain-specific information, e.g., the number of blocks in a blockchain, block size, the number of unspent transaction outputs (UTXO), etc. 

A total of 15 metrics from the blockchain endpoint are accessible with the standard account.
MetricDescriptionPath
Block HeightThe sum of blocks created in the main blockchainhttps://api.glassnode.com/v1/metrics/blockchain/block_height
Blocks Mined The total number of blocks created in the main blockchain in a specific period. https://api.glassnode.com/v1/metrics/blockchain/block_count
Block Interval (Mean) The average time  between mined blocks (in seconds)https://api.glassnode.com/v1/metrics/blockchain/block_interval_mean
Block Interval (Median)  The median time  between mined blocks (in seconds)https://api.glassnode.com/v1/metrics/blockchain/block_interval_median
Block Size (Total)The total size (in bytes) of all blocks mined in a specific period. https://api.glassnode.com/v1/metrics/blockchain/block_size_sum
Block Size (Mean)The average size (in bytes) of all blocks mined in a specific period. https://api.glassnode.com/v1/metrics/blockchain/block_size_mean
UTXOs CreatedThe number of UTXOs created in a specific periodhttps://api.glassnode.com/v1/metrics/blockchain/utxo_created_count
UTXOs SpentThe number of spent UTXOshttps://api.glassnode.com/v1/metrics/blockchain/utxo_spent_count
UTXOs (Total)The total number of UTXOs in the network.https://api.glassnode.com/v1/metrics/blockchain/utxo_count
UTXO Value Created (Total)The total amount of coins in a newly created UTXOhttps://api.glassnode.com/v1/metrics/blockchain/utxo_created_value_sum
UTXO Value Created (Mean)The mean amount of coins in a newly created UTXOhttps://api.glassnode.com/v1/metrics/blockchain/utxo_created_value_mean
UTXO Value Created (Median)The median of coins in a newly created UTXOhttps://api.glassnode.com/v1/metrics/blockchain/utxo_created_value_median
UTXO Value Spent (Total)The total amount of coins in spent UTXOshttps://api.glassnode.com/v1/metrics/blockchain/utxo_spent_value_sum
UTXO Value Spent (Mean)The mean  amount of coins in spent UTXOshttps://api.glassnode.com/v1/metrics/blockchain/utxo_spent_value_mean
UTXO Value Spent (Median)The median amount of coins in spent UTXOshttps://api.glassnode.com/v1/metrics/blockchain/utxo_spent_value_median

The following code shows an example of how you can call some of the standard metrics from the blockchain endpoint.

import json
import requests
import os
import pandas as pd

api_key = os.environ['GN-Key']

api_calls = ["https://api.glassnode.com/v1/metrics/blockchain/block_height", # Block Height
             "https://api.glassnode.com/v1/metrics/blockchain/block_count", # Blocks Mined 
             "https://api.glassnode.com/v1/metrics/blockchain/block_interval_mean", # Block Interval (Mean) 
             "https://api.glassnode.com/v1/metrics/blockchain/block_interval_median", # Block Interval (Median) 
             "https://api.glassnode.com/v1/metrics/blockchain/block_size_sum", # Block Size (Total)
             "https://api.glassnode.com/v1/metrics/blockchain/block_size_mean" # Block Size (Mean)
             
            ]

results = []
for call in api_calls:
    
    endpoint_name = call.split("/")[-1]
    
    # make API request
    res = requests.get(call, 
                       params={"a": "BTC", 'api_key': api_key})

    # convert to pandas dataframe
    df = pd.read_json(res.text, convert_dates=['t'])
    
    # rename dataframe column names
    df.columns = ["Time", endpoint_name]
    
    # set Time as the index column
    df.set_index("Time", inplace = True)
    # adding the result to a list of pandas dataframe
    results.append(df)
    
# concatenating all dataframes horizontally
results_df = pd.concat(results, axis=1)
results_df.tail()

Output:

Glassnode API Blockchain Endpoint Output
The script below demonstrates how you can call metrics returning UTXO information from the blockchain endpoint.
import json
import requests
import os
import pandas as pd

api_key = os.environ['GN-Key']

api_calls = ["https://api.glassnode.com/v1/metrics/blockchain/utxo_created_count", # UTXOs Created
             "https://api.glassnode.com/v1/metrics/blockchain/utxo_spent_count", # UTXOs Spent
             #"https://api.glassnode.com/v1/metrics/blockchain/utxo_count", # UTXOs (Total)
             "https://api.glassnode.com/v1/metrics/blockchain/utxo_created_value_sum", # UTXO Value Created (Total)
             "https://api.glassnode.com/v1/metrics/blockchain/utxo_created_value_mean", # UTXO Value Created (Mean)
             "https://api.glassnode.com/v1/metrics/blockchain/utxo_created_value_median", # UTXO Value Created (Median)
             "https://api.glassnode.com/v1/metrics/blockchain/utxo_spent_value_sum", # UTXO Value Spent (Total)
             "https://api.glassnode.com/v1/metrics/blockchain/utxo_spent_value_mean", # UTXO Value Spent (Mean)
             "https://api.glassnode.com/v1/metrics/blockchain/utxo_spent_value_median", # UTXO Value Spent (Median)
            ]


results = []
for call in api_calls:
    
    endpoint_name = call.split("/")[-1]
    
    # make API request
    res = requests.get(call, 
                       params={"a": "BTC", 'api_key': api_key})

    # convert to pandas dataframe
    df = pd.read_json(res.text, convert_dates=['t'])
    
    # rename dataframe column names
    df.columns = ["Time", endpoint_name]
    
    # set Time as the index column
    df.set_index("Time", inplace = True)
    # adding the result to a list of pandas dataframe
    results.append(df)
    
# concatenating all dataframes horizontally
results_df = pd.concat(results, axis=1)
results_df.tail()

Output:

Glassnode API Blockchain Endpoint UTXO Output

You can find the list of all blockchain metrics at the official documentation link. 

ETH 2.0 Endpoint

ETH 2.0 endpoint metrics return information about ETH 2.0, e.g., transactions and transfers involving ETH 2.0, total ETH 2.0 volume, etc. 

The following table contains the ETH 2.0 endpoint metrics accessible from the standard account.  

MetricDescriptionPath
ETH 2.0 New DepositsThe number of transactions depositing 32 ETH to ETH 2 deposit contracthttps://api.glassnode.com/v1/metrics/eth2/staking_deposits_count
ETH 2.0 New Value StakedThe total amount of ETH deposited to the ETH2 deposit contract https://api.glassnode.com/v1/metrics/eth2/staking_volume_sum
ETH 2.0 New ValidatorsThe number of new unique addresses depositing ETH  to the ETH2 deposit contract https://api.glassnode.com/v1/metrics/eth2/staking_validators_count
ETH 2.0 Total Number of DepositsThe total number of transactions in the ETH2 deposit contracthttps://api.glassnode.com/v1/metrics/eth2/staking_total_deposits_count
ETH 2.0 Total Value StakedThe total amount of ETH deposited to the ETH2 deposit contracthttps://api.glassnode.com/v1/metrics/eth2/staking_total_volume_sum
ETH 2.0 Total Number of ValidatorsThe number of unique addresses depositing ETH  to the ETH2 deposit contract https://api.glassnode.com/v1/metrics/eth2/staking_total_validators_count
ETH 2.0 Phase 0 Staking GoalThe ETH volume divided by 524,288.https://api.glassnode.com/v1/metrics/eth2/staking_phase_0_goal_percent

The code below shows how to access the ETH 2.0 endpoint in Python.

import json
import requests
import os
import pandas as pd

api_key = os.environ['GN-Key']

api_calls = ["https://api.glassnode.com/v1/metrics/eth2/staking_deposits_count", 
             "https://api.glassnode.com/v1/metrics/eth2/staking_volume_sum",
             "https://api.glassnode.com/v1/metrics/eth2/staking_validators_count",
             "https://api.glassnode.com/v1/metrics/eth2/staking_total_deposits_count",
             "https://api.glassnode.com/v1/metrics/eth2/staking_total_volume_sum",
             "https://api.glassnode.com/v1/metrics/eth2/staking_total_validators_count",
             "https://api.glassnode.com/v1/metrics/eth2/staking_phase_0_goal_percent"
            ]



results = []
for call in api_calls:
    
    endpoint_name = call.split("/")[-1]
    
    # make API request
    res = requests.get(call, 
                       params={"a": "ETH",  'api_key': api_key})

    # convert to pandas dataframe
    df = pd.read_json(res.text, convert_dates=['t'])
    
    # rename dataframe column names
    df.columns = ["Time", endpoint_name]
    
    # set Time as the index column
    df.set_index("Time", inplace = True)
    # adding the result to a list of pandas dataframe
    results.append(df)
    
# concatenating all dataframes horizontally
results_df = pd.concat(results, axis=1)
results_df.tail()

Output:

Glassnode API Eth 2.0 Endpoint Output

Check the official documentation to see the complete list of ETH 2.0 endpoint metrics. 

Fees Endpoint

The fees API endpoint provides metrics that return the fee information for various cryptocurrency assets. The table below summarizes the fees metrics available with the standard account. 

MetricDescriptionPath
Fees (Total)The total fee paid to minershttps://api.glassnode.com/v1/metrics/fees/volume_sum
Fees (Mean)The average fee per transactionhttps://api.glassnode.com/v1/metrics/fees/volume_mean
Fees (Median)The median fee per transactionhttps://api.glassnode.com/v1/metrics/fees/volume_median
Transaction Gas Limit (Mean)The average gas limit per transaction https://api.glassnode.com/v1/metrics/fees/gas_limit_tx_mean
Transaction Gas Limit (Median)The median gas limit per transaction https://api.glassnode.com/v1/metrics/fees/gas_limit_tx_median
Gas Price (Mean)The average gas price per transaction https://api.glassnode.com/v1/metrics/fees/gas_price_mean
Gas Price (Median)The median gas price per transactionhttps://api.glassnode.com/v1/metrics/fees/gas_price_median
Gas Used (Mean)The average gas used per transactionhttps://api.glassnode.com/v1/metrics/fees/gas_used_mean
Gas Used (Median)The median amount of  gas used per transactionhttps://api.glassnode.com/v1/metrics/fees/gas_used_median
Gas Used (Total)The total gas used per transactionhttps://api.glassnode.com/v1/metrics/fees/gas_used_sum

The following script demonstrates how to call some of the aforementioned fees metrics.
Note: I have commented some of the API calls since not all API calls return an equal number of rows which results in an error while concentrating pandas dataframes. You can make API calls individually to see the results.

import json
import requests
import os
import pandas as pd

api_key = os.environ['GN-Key']

api_calls = ["https://api.glassnode.com/v1/metrics/fees/volume_sum", # Fees (Total)
              "https://api.glassnode.com/v1/metrics/fees/volume_mean",# Fees (Mean)
              "https://api.glassnode.com/v1/metrics/fees/volume_median", # Fees (Median)
#             "https://api.glassnode.com/v1/metrics/fees/gas_limit_tx_mean", # Transaction Gas Limit (Mean)
#              "https://api.glassnode.com/v1/metrics/fees/gas_limit_tx_median", # Transaction Gas Limit (Median)
#              "https://api.glassnode.com/v1/metrics/fees/gas_price_mean", # Gas Price (Mean)
#              "https://api.glassnode.com/v1/metrics/fees/gas_price_median", # Gas Price (Median)
#              "https://api.glassnode.com/v1/metrics/fees/gas_used_mean", # Gas Used (Mean)
#             "https://api.glassnode.com/v1/metrics/fees/gas_used_median", # Gas Used (Median)
#             "https://api.glassnode.com/v1/metrics/fees/gas_used_sum" # Gas Used (Total)
            ]



results = []
for call in api_calls:
    
    endpoint_name = call.split("/")[-1]
    
    # make API request
    res = requests.get(call, 
                       params={"a": "BTC",  'api_key': api_key})

    # convert to pandas dataframe
    df = pd.read_json(res.text, convert_dates=['t'])
    
    # rename dataframe column names
    df.columns = ["Time", endpoint_name]
    
#     # set Time as the index column
#     df.set_index("Time", inplace = True)
#     # adding the result to a list of pandas dataframe
    results.append(df)
    
# concatenating all dataframes horizontally
results_df = pd.concat(results, axis=1)
results_df.tail()

Output:

Glassnode API Fees Endpoint Output

Check out the official documentation to see the complete list of fees endpoint metrics

Indicators Endpoint

The indicators endpoint metrics provide information about various blockchain indicators, e.g., the extent of bitcoin mining difficulty, spent output profit ratio, stock-to-flow ratio, etc. 

The following indicators metrics are accessible with the standard account.

MetricDescriptionPath
Pi Cycle Top IndicatorIndicates 111-day moving average and 2x multiple of the 350-day moving average of Bitcoin’s pricehttps://api.glassnode.com/v1/metrics/indicators/pi_cycle_top
Difficulty RibbonIndicates the extent of bitcoin mining difficulty. https://api.glassnode.com/v1/metrics/indicators/difficulty_ribbon
SOPRIndicates the spent output profit ratiohttps://api.glassnode.com/v1/metrics/indicators/sopr
Stock-to-Flow RatioIndicates the stock-to-flow-ratiohttps://api.glassnode.com/v1/metrics/indicators/stock_to_flow_ratio

The following code shows how to call the indicators endpoint metrics in a Python script. 

import json
import requests
import os
import pandas as pd

api_key = os.environ['GN-Key']

api_calls = ["https://api.glassnode.com/v1/metrics/indicators/pi_cycle_top", # Pi Cycle Top Indicator
#             "https://api.glassnode.com/v1/metrics/indicators/difficulty_ribbon", # Difficulty Ribbon - value too big for pandas dataframe
              "https://api.glassnode.com/v1/metrics/indicators/sopr", # SOPR
              "https://api.glassnode.com/v1/metrics/indicators/stock_to_flow_ratio" # Stock-to-Flow Ratio
            ]



results = []
for call in api_calls:
    
    endpoint_name = call.split("/")[-1]
    
    # make API request
    res = requests.get(call, 
                       params={"a": "BTC",  'api_key': api_key})

    # convert to pandas dataframe
    df = pd.read_json(res.text, convert_dates=['t'])
    
    # rename dataframe column names
    df.columns = ["Time", endpoint_name]
    
#     # set Time as the index column
#     df.set_index("Time", inplace = True)
#     # adding the result to a list of pandas dataframe
    results.append(df)
    
# concatenating all dataframes horizontally
results_df = pd.concat(results, axis=1)
results_df.head()

Output:

Glassnode API Indicators Endpoint Output
Refer to the complete list of indicators endpoint metrics to know more about other metrics. 
Institutions Endpoint

This endpoint contains metrics that fetch information from  3iQ, a digital asset management company. Two metrics from the institutions endpoint are accessible from the standard account. 




Metric
Description
Path
Purpose Bitcoin ETF Flows
The number of bitcoins flowing to/from exchange-traded funds
https://api.glassnode.com/v1/metrics/institutions/purpose_etf_flows_sum
Purpose Bitcoin ETF Holdings
The number of bitcoins in exchange-traded funds
https://api.glassnode.com/v1/metrics/institutions/purpose_etf_holdings_sum

The following code shows how to call the above two metrics from the institutions endpoint.
import json
import requests
import os
import pandas as pd

api_key = os.environ['GN-Key']

api_calls = ["https://api.glassnode.com/v1/metrics/institutions/purpose_etf_flows_sum", # Purpose Bitcoin ETF Flows
             "https://api.glassnode.com/v1/metrics/institutions/purpose_etf_holdings_sum" # Purpose Bitcoin ETF Holdings
            ]


results = []
for call in api_calls:
    
    endpoint_name = call.split("/")[-1]
    
    # make API request
    res = requests.get(call, 
                       params={"a": "BTC",  'api_key': api_key})

    # convert to pandas dataframe
    df = pd.read_json(res.text, convert_dates=['t'])
    
    # rename dataframe column names
    df.columns = ["Time", endpoint_name]
    
#     # set Time as the index column
#     df.set_index("Time", inplace = True)
#     # adding the result to a list of pandas dataframe
    results.append(df)
    
# concatenating all dataframes horizontally
results_df = pd.concat(results, axis=1)
results_df.tail()

Output:

Glassnode API Insitutions Endpoint Output

Check out the official documentation to see the complete list of institutions endpoint metrics

Market Endpoint

Market endpoint contains metrics that return market information, e.g., the market cap, the opening, high, low, and closing values of an asset in USD, etc. 

The following four market endpoints are available with the standard account. 

MetricDescriptionPath
Market CapThe product of the current USD price by the current supply of an assethttps://api.glassnode.com/v1/metrics/market/marketcap_usd
PriceThe closing price of an asset in USDhttps://api.glassnode.com/v1/metrics/market/price_usd_close
Price OHLCCandlestick chart values for open, high, low, and close values of an asset in USDhttps://api.glassnode.com/v1/metrics/market/price_usd_ohlc
Price Drawdown from ATHThe percent decrease of an asset price from the previous all-time highhttps://api.glassnode.com/v1/metrics/market/price_drawdown_relative

The following example shows how to access the Glassnode Market endpoint in Python.

import json
import requests
import os
import pandas as pd

api_key = os.environ['GN-Key']

api_calls = ["https://api.glassnode.com/v1/metrics/market/marketcap_usd", # Market Cap
             "https://api.glassnode.com/v1/metrics/market/price_usd_close", # Price
             "https://api.glassnode.com/v1/metrics/market/price_usd_ohlc", # Price OHLC
             "https://api.glassnode.com/v1/metrics/market/price_drawdown_relative" # Price Drawdown from ATH
            ]


results = []
for call in api_calls:
    
    endpoint_name = call.split("/")[-1]
    
    # make API request
    res = requests.get(call, 
                       params={"a": "BTC",  'api_key': api_key})

    # convert to pandas dataframe
    df = pd.read_json(res.text, convert_dates=['t'])
    
    # rename dataframe column names
    df.columns = ["Time", endpoint_name]
    
#     # set Time as the index column
#     df.set_index("Time", inplace = True)
#     # adding the result to a list of pandas dataframe
    results.append(df)
    
# concatenating all dataframes horizontally
results_df = pd.concat(results, axis=1)
results_df.tail()

Output:

Glassnode API Market Endpoint Output

Refer to the official documentation to see the complete list of market endpoint metrics.

Mining Endpoint

This endpoint provides information on blockchain mining statistics, e.g., the number of hashes required to mine a block for an asset. 

The following two metrics are accessible with the standard account.

MetricDescriptionPath
DifficultyThe estimated number of hashes required to mine a block for an assethttps://api.glassnode.com/v1/metrics/mining/difficulty_latest
HashrateThe estimated mean value for hashes produced by miners in the networkhttps://api.glassnode.com/v1/metrics/mining/hash_rate_mean

The script below demonstrates how to call these two mining metrics in Python. 

 In this case, the output is not in the form of a Pandas dataframe because, sometimes, the values returned by Glassnode API metrics are too big to be stored in a Pandas dataframe. 

Therefore, the output displays a plain text string you can parse to extract relevant information.

import json
import requests
import os
import pandas as pd

api_key = os.environ['GN-Key']

api_calls = ["https://api.glassnode.com/v1/metrics/mining/difficulty_latest" # Difficulty
            #"https://api.glassnode.com/v1/metrics/mining/hash_rate_mean"] # Hashrate


results = []
for call in api_calls:
    
    endpoint_name = call.split("/")[-1]
    
    # make API request
    res = requests.get(call, 
                       params={"a": "BTC",  'api_key': api_key})

    
    results.append(res.text)
    
print(results[0][:225])

Output:

[{"t":1231459200,"v":4294967296},{"t":1231545600,"v":4294967296},{"t":1231632000,"v":4294967296},{"t":1231718400,"v":4294967296},{"t":1231804800,"v":4294967296},{"t":1231891200,"v":4294967296},{"t":1231977600,"v":4294967296},

Check out the official documentation to see the complete list of mining endpoint metrics

Protocols Endpoint

The protocols endpoint provides metrics that fetch asset information from Uniswap cryptocurrency exchange. It has three metrics that you can access through a standard subscription.

MetricDescriptionPath
Uniswap LiquidityThe latest liquidity of an asset on Uniswaphttps://api.glassnode.com/v1/metrics/protocols/uniswap_liquidity_latest
Uniswap TransactionsThe total number of assets involved in Uniswap contractshttps://api.glassnode.com/v1/metrics/protocols/uniswap_transaction_count
Uniswap VolumeThe total volume of an asset traded on Uniswaphttps://api.glassnode.com/v1/metrics/protocols/uniswap_volume_sum

The following code shows an example of how you can call the metrics from the protocol endpoint:

import json
import requests
import os
import pandas as pd

api_key = os.environ['GN-Key']

api_calls = ["https://api.glassnode.com/v1/metrics/protocols/uniswap_liquidity_latest",  # Uniswap Liquidity
             "https://api.glassnode.com/v1/metrics/protocols/uniswap_transaction_count", # Uniswap Transactions
             "https://api.glassnode.com/v1/metrics/protocols/uniswap_volume_sum", # Uniswap Volume
            ]

results = []
for call in api_calls:
    
    endpoint_name = call.split("/")[-1]
    
    # make API request
    res = requests.get(call, 
                       params={"a": "ETH",  'api_key': api_key})

    
    results.append(res.text)
    
print(results[0][:210])

Output:

[{"t":1588636800,"v":0.00490852351350741},{"t":1588723200,"v":0.0159213628437584},{"t":1588809600,"v":0.0159213628437726},{"t":1588896000,"v":0.0887127385961924},{"t":1588982400,"v":0.0887127385961924},{"t":158

You can find the list of all protocols endpoint metrics at the official documentation link. 

Supply Endpoint

The supply endpoint metrics provide information on asset supply. You can only access one metric from this endpoint with the standard account. 

MetricDescriptionPath
Supply Last Active 1+ Years AgoThe percentage value of immobile asset supply in at least a year https://api.glassnode.com/v1/metrics/supply/active_more_1y_percent

The following code shows how to call the Supply Last Active 1+ Years Ago metric from the supply endpoint. 

import json
import requests
import os
import pandas as pd

api_key = os.environ['GN-Key']

api_calls = ["https://api.glassnode.com/v1/metrics/supply/active_more_1y_percent", 
            ]


results = []
for call in api_calls:
    
    endpoint_name = call.split("/")[-1]
    
    # make API request
    res = requests.get(call, 
                       params={"a": "BTC",  'api_key': api_key})

    # convert to pandas dataframe
    df = pd.read_json(res.text, convert_dates=['t'])
    
    # rename dataframe column names
    df.columns = ["Time", endpoint_name]
    
#     # set Time as the index column
#     df.set_index("Time", inplace = True)
#     # adding the result to a list of pandas dataframe
    results.append(df)
    
# concatenating all dataframes horizontally
results_df = pd.concat(results, axis=1)
results_df.ta

Output:

Glassnode API Supply Endpoint Output
 See the official documentation to know more about supply endpoint metrics.
Transactions Endpoint

The transactions endpoint contains metrics that convey an asset’s transaction information, e.g., transaction, count, size, rate, etc. The following table contains the transaction endpoint metrics accessible through the standard (free) account.
MetricDescriptionPath
Transaction CountThe total amount of successful transactions for an assethttps://api.glassnode.com/v1/metrics/transactions/count
Transaction RateThe number of successful transactions per secondhttps://api.glassnode.com/v1/metrics/transactions/rate
Transaction Size (Total)The total size of all transactions within a specific periodhttps://api.glassnode.com/v1/metrics/transactions/size_sum
Transaction Size (Mean)The average  size of all transactions within a specific periodhttps://api.glassnode.com/v1/metrics/transactions/size_mean
Transfer Volume (Total)The total amount of coins transferred in successful transfershttps://api.glassnode.com/v1/metrics/transactions/transfers_volume_sum
Transfer Volume (Mean)The average amount of coins transferred in successful transfershttps://api.glassnode.com/v1/metrics/transactions/transfers_volume_mean
Transfer Volume (Median)The median  amount of coins transferred in successful transfershttps://api.glassnode.com/v1/metrics/transactions/transfers_volume_median

Check the official documentation to see the complete list of transactions metrics. 

The script below demonstrates how to call the above API metric and store the response in a Pandas dataframe.

import json
import requests
import os
import pandas as pd

api_key = os.environ['GN-Key']

api_calls = ["https://api.glassnode.com/v1/metrics/transactions/count", # Transaction Count
              "https://api.glassnode.com/v1/metrics/transactions/rate", # Transaction Rate
              "https://api.glassnode.com/v1/metrics/transactions/size_sum", # Transaction Size (Total)
              "https://api.glassnode.com/v1/metrics/transactions/size_mean", # Transaction Size (Mean)
              "https://api.glassnode.com/v1/metrics/transactions/transfers_volume_sum", # Transfer Volumne (Total)
              "https://api.glassnode.com/v1/metrics/transactions/transfers_volume_mean", # Transfer Volume (Mean)
              "https://api.glassnode.com/v1/metrics/transactions/transfers_volume_median" # Transfer Volume (Median)
            ]


results = []
for call in api_calls:
    
    endpoint_name = call.split("/")[-1]
    
    # make API request
    res = requests.get(call, 
                       params={"a": "BTC",  'api_key': api_key})

    # convert to pandas dataframe
    df = pd.read_json(res.text, convert_dates=['t'])
    
    # rename dataframe column names
    df.columns = ["Time", endpoint_name]
    
    # set Time as the index column
    df.set_index("Time", inplace = True)
    # adding the result to a list of pandas dataframe
    results.append(df)
    
# concatenating all dataframes horizontally
results_df = pd.concat(results, axis=1)
results_df.tail()

Output:

Glassnode API Transaction Endpoint Output
import json
import requests
import os
import pandas as pd

api_key = os.environ['GN-Key']

api_calls = ["https://api.glassnode.com/v1/metrics/transactions/transfers_count", # Transfer Count
             "https://api.glassnode.com/v1/metrics/transactions/transfers_rate" # Transfer Rate
            ]

results = []
for call in api_calls:
    
    endpoint_name = call.split("/")[-1]
    
    # make API request
    res = requests.get(call, 
                       params={"a": "ETH",  'api_key': api_key})

    results.append(res.text)
    
print(results[1][:200])

Output:

[{"t":1438905600,"v":0.022928240740740742},{"t":1438992000,"v":0.017974537037037035},{"t":1439078400,"v":0.014398148148148148},{"t":1439164800,"v":0.01765046296296296},{"t":1439251200,"v":0.0380324074

Common Errors and Issues Accessing Glassnode API

Depending on the metric tier and the way you want to store information from the Glassnode API, you may face some issues. 

In some instances, the values returned by the Glassnode APIs are too big to be stored in Pandas dataframes. In such cases, you should consider other data structures for storing the response. 

For instance, the following script returns a “Value is too Big” error.

import json
import requests
import os
import pandas as pd

api_key = os.environ['GN-Key']

api_calls = [#"https://api.glassnode.com/v1/metrics/mining/difficulty_latest"
             "https://api.glassnode.com/v1/metrics/mining/hash_rate_mean"
            ]


results = []
for call in api_calls:
    
    endpoint_name = call.split("/")[-1]
    
    # make API request
    res = requests.get(call, 
                       params={"a": "BTC",  'api_key': api_key})

    df = pd.read_json(res.text, convert_dates=['t'])
    
    results.append(res.text)

Output:

Glassdoe API Common Error Value Too Big

Another common issue you will likely face is the inability to access some metrics. For instance, the following script returns an error while accessing the difficulty metric from the mining endpoint, although the metric falls in the category of tier 1 metrics. 

#"https://api.glassnode.com/v1/metrics/blockchain/utxo_count", # UTXOs (Total)

import json
import requests
import os
import pandas as pd

api_key = os.environ['GN-Key']

api_calls = [#"https://api.glassnode.com/v1/metrics/mining/difficulty_latest"
             "https://api.glassnode.com/v1/metrics/blockchain/utxo_count"
            ]

results = []
for call in api_calls:
    endpoint_name = call.split("/")[-1]
    
    # make API request
    res = requests.get(call, 
                       params={"a": "BTC",  'api_key': api_key})

    df = pd.read_json(res.text, convert_dates=['t'])
    
    results.append(res.text)

Output:

Glassnode API Common Metrics Error

The error in the above output is not clear. In such cases, you may want to make an API call via the glassnode-api-python-client library, as shown in the script below:

from glassnode import GlassnodeClient
import os
import pandas as pd

api_key = os.environ['GN-Key']

## behind the scene API call
## https://api.glassnode.com/v1/metrics/addresses/active_count

client = GlassnodeClient(api_key)
data = client.get("blockchain", "utxo_count", {"a": "BTC"})
print(type(data))
print(data[0].keys())

Output:

As you can see, the error returned, in this case, is more readable as it says that the asset (‘BTC’) is forbidden for this endpoint. 

How do I Extract Glassnode Data to Excel?

To extract Glassnode data to an Excel file, you can store the response from the Glassnode API in a Pandas dataframe; you can then use the to_excel() function from the Pandas dataframe to write the data into an excel file. 

The following script demonstrates how to extract Glassnode data to Excel.

import json
import requests
import os
import pandas as pd

api_key = os.environ['GN-Key']


since = 1232668800 # 2009-01-23
until = 1233532800 # 2009-02-03
resolution = "24h"

# make API request
res = requests.get('https://api.glassnode.com/v1/metrics/addresses/active_count',
    params={"a": "BTC", "s": since, "u": until, "i": resolution, 'api_key': api_key})


# convert to pandas dataframe
df = pd.read_json(res.text, convert_dates=['t'])

df.to_excel("D:\Datasets\glassnode_output.xlsx",
             sheet_name='Sheet_name_1')

Output:

Glassnode API Data to Excel
How do I Pull Glassnode Data into Google Sheets?

To pull data from Glassnode into Google sheets, you require three libraries:

Pandas 
gspread
Df2gspread

As a first step, you can import the Glassnode data into a Pandas dataframe.
import json
import requests
import os
import pandas as pd

api_key = os.environ['GN-Key']

since = 1232668800 # 2009-01-23
until = 1233532800 # 2009-02-03
resolution = "24h"

# make API request
res = requests.get('https://api.glassnode.com/v1/metrics/addresses/active_count',
    params={"a": "BTC", "s": since, "u": until, "i": resolution, 'api_key': api_key})


# convert to pandas dataframe
df = pd.read_json(res.text, convert_dates=['t'])

The next step is to connect to Google spreadsheets from your Python application. To do so, you need a JSON file containing an API key that lets you connect to your Google spreadsheet account. 

You can use the gspread library to connect to Google spreadsheets from your Python application. The process is explained on the official documentation page of gspread library.

Download the API Key, and authenticate your credentials using the following script:

# pip install gspread
import gspread

#pip install df2gspread
from df2gspread import df2gspread

from oauth2client import service_account

scope = ['https://spreadsheets.google.com/feeds',
         'https://www.googleapis.com/auth/drive']

credentials = service_account.ServiceAccountCredentials.from_json_keyfile_name(
    'D:\Datasets\my-project-1470409419661-70e344e255e3.json', scope)

gc = gspread.authorize(credentials)

Finally, you can use the upload()  function from the  df2gspread module to pull the data from the Pandas dataframe into Google sheets, as shown in the following script. 

spreadsheet_key = os.environ['GSS-Key']
sheet_name = 'Sheet1'
df2gspread.upload(df, spreadsheet_key, sheet_name, credentials=credentials, row_names=True)
Glassnode API Data to Google Sheets

Glassnode Alternatives

Following are some of the other platforms providing on-chain data analytics services: 

Glassnode vs. CryptoQuant

GlassnodeCryptoQuant
Membership FeesStandard: FreeAdvanced: $29Professional: $799Institutional: Tailored as per requirementStandard: FreeAdvanced: $29Professional $99Premium: $799
Monthly Visits (August 2022)640.4K605.4 K
FeaturesGlassnode studioGlassnode AcademyGlass node Insights and ReportingAbility to view multiple chartsAbility to set alertsAbility to view multiple chartsLarge user community and social media presence
Beginner FriendlinessNot very beginner friendly due to the complex interfaceBeginner-friendly

There is little to choose between Glassnode and CryptoQuant as both platforms have similar pricing and offer comparable features. However, CryptoQuant might be a good starting point for beginners. 

Conclusion

Glassnode is an intelligent data analytics platform that provides insights into blockchain data. In addition to a sophisticated GUI dashboard in Glassnode studio, Glass node offers programmatically accessible REST API endpoints. 

This tutorial teaches how to fetch data from Glassnode API in a Python application. You saw how to use the Python request method and the glassnode-api-python-client library to call the Glassnode API. The information in this tutorial can help you develop blockchain data analytics software.

Leave a Comment