Skip to main content

substreams-python

WIP Python Interface for querying via substreams

Requirements

  1. Install the package:
pip3 install substreams
  1. Generate a StreamingFast API Token

    • Can do so via this link
    • Be sure to save the Token as an env var
    export SUBSTREAMS_API_TOKEN="<MY_CUSTON_SPI_TOKEN>"
    
  2. Retrieve the relevant .spkg file

    • Can retrieve officially released .spkg files from the instructions here
      • Alternatively, can refer to the official StreamingFast README or generate a Messari .spkg from these build instructions

Instructions

Instantiation

First import the Substream object and pass in the path to your .spkg file

from substreams import Substream

sb = Substream("substreams-uniswap-v2-v0.1.0.spkg")

If you already have the sf/substreams repo generated (as per step #3 in these instructions), then the library will import from those files. Otherwise, the files will be generated dynamically.

Polling

In order to poll the substream, you will need to call the poll() function on the Substream object. poll() requires that you specify a list of output modules, you can inspect what modules are available by calling supported_output_modules

# View available modules on .spkg
print(sb.output_modules)

# Poll the module and return a list of SubstreamOutput objects in the order of the specified modules
result = sb.poll("map_swap_events", start_block=10000835, end_block=10000835+20000)

With the default inputs, this function outputs Pandas Dataframes after streaming all blocks between the start_block and end_block. However depending on how this function is called, a dict object is returned. The poll() function has a number of inputs

  • output_modules
    • String of the output module to stream
  • start_block
    • Integer block number to start the polling
  • end_block
    • Integer block number to end the polling. In theory, there is no max block number as any block number past chain head will stream the blocks in real time. Its recommended to use an end_block far off into the future if building a data app that will be streaming datain real time as blocks finalize, such as block 20,000,000
  • return_first_result
    • Boolean value that if True will return data on the first block after the start block to have an applicable TX/Event.
    • Can be called recursively on the front end while incrementing the start_block to return data as its streamed rather than all data at once after streaming is completed
    • Defaults to False
  • initial_snapshot
    • Boolean value, defaults to False
  • return_first_result_function
    • Custom filtering function that accepts parsed data passed as an argument and returns as either True or False
    • Gets called when return_first_result is True and a block has applicable events/txs
    • If function resolves to True, the polling function returns the data from the block
    • If function resolves to False, the polling function continues iteration
  • return_type
    • Specifies the type of value to return
    • Passing "df" returns the data in a pandas DataFrame
    • Passing "dict" returns in the format {"data": [], "module_name": String, "data_block": int, error: str | None}
    • Passing "csv" returns in the format {"data": String(CSV), "module_name": String, "data_block": int, error: str | None}

The result here is the default SubstreamOutput object, you can access both the data and snapshots dataframes by doing:

# These will return pandas DataFrames
swap_events_result = results[0]
data_df = swap_events_result.data
snapshots_df = swap_events_result.snapshots

Metadata

Release files for substreams 0.0.8

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for substreams 0.0.8
File Size Uploaded
substreams-0.0.8.macosx-11.1-arm64.tar.gz 10.4 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for substreams 0.0.8
File Interpreter ABI Platform
substreams-0.0.8-py3-none-any.whl Python 3 none any Details

Total release size: 17.4 kB

Release files / substreams-0.0.8.macosx-11.1-arm64.tar.gz

Download URL substreams-0.0.8.macosx-11.1-arm64.tar.gz
Size 10.4 kB
Tags Source
SHA-256 checksum
How to use checksums
2105b371e5817fdeb2a3e355a5abc0c47ff5c94b7c8156d45ef525af7926e72f
BLAKE2b-256 checksum
How to use checksums
fff0a40178050ad6890b23269cf1f88847f5aa62eb6f973e689b38be2756c85a
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.6

Release files / substreams-0.0.8-py3-none-any.whl

Download URL substreams-0.0.8-py3-none-any.whl
Size 7.0 kB
Tags Python 3
SHA-256 checksum
How to use checksums
3afe864359df90f7d38f9e6574e35a509d24537489d04858dada06c750a90377
BLAKE2b-256 checksum
How to use checksums
8475924f9bd3e873adfc06443173cadab3f11ff967cf80aed0fd0fac5ada4cf9
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/4.0.1 CPython/3.10.6

Release history Release notifications | RSS feed

This release

0.0.8 This release

2 release files

0.0.7

1 release file

0.0.6

1 release file

0.0.5

1 release file

0.0.4

1 release file

0.0.2

1 release file

0.0.1

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page