Skip to main content

Lightweight Python client for querying blockchain data from SQD Network

Project description

sqd_py

Python client for querying blockchain data from SQD Network.

Installation

pip install sqd_py

Quick Start

import asyncio
from sqd import SQD, Dataset, EvmFields

async def main():
    sqd = SQD(dataset=Dataset.ETHEREUM)
    
    query = sqd.get_transactions(
        from_block=17_000_000,
        to_block=17_000_010,
        address="0x742d35Cc6634C0532925a3b844Bc454e4438f44e",
    )
    
    async for block in query:
        for tx in block.get("transactions", []):
            print(tx["hash"])

asyncio.run(main())

Usage

Querying Logs

query = sqd.get_logs(
    from_block=17_000_000,
    to_block=17_000_100,
    address="0xA0b86991c6218b36c1d19D4a2e9Eb0cE3606eB48",
    topic0="0xddf252ad1be2c89b69c2b068fc378daa952ba7f163c4a11628f55a4df523b3ef",
)

async for block in query:
    for log in block.get("logs", []):
        print(log)

ERC-20 Transfers

query = sqd.get_transfers(
    from_block=17_000_000,
    to_block=17_100_000,
    contract_address="0xc02aaa39b223fe8d0a0e5c4f27ead9083c756cc2",
)

async for block in query.with_progress(shards=15):
    for log in block.get("logs", []):
        print(log)

Selecting Fields

query = sqd.get_transactions(
    from_block=17_000_000,
    to_block=17_000_010,
    include_fields=[
        EvmFields.TransactionField.hash,
        EvmFields.TransactionField.from_,
        EvmFields.TransactionField.gasUsed,
    ],
)

Chaining Queries

query = sqd.get_transactions(
    from_block=17_000_000,
    to_block=17_000_010,
    address="0x...",
).get_logs(
    address="0x...",
    topic0="0x...",
)

async for block in query:
    # block contains both transactions and logs
    pass

Progress Bar

async for block in query.with_progress(shards=15):
    pass

The shards parameter controls parallel fetching for historical data.

Supported Datasets

Chain Dataset
Ethereum Dataset.ETHEREUM or "ethereum-mainnet"
Binance Smart Chain Dataset.BINANCE or "binance-mainnet"
Solana Dataset.SOLANA or "solana-mainnet"

API

SQD

SQD(
    dataset: Dataset | str,
    portal_url: str = "https://portal.sqd.dev",
    stream_type: Literal["finalized", "realtime"] = "realtime",
)

Query Methods

EVM:

  • get_blocks(from_block, to_block, ...)
  • get_transactions(from_block, address, to_block, ...)
  • get_logs(from_block, address, topic0, to_block, ...)
  • get_transfers(from_block, contract_address, ...)
  • get_traces(from_block, to_block, ...)
  • get_state_diffs(from_block, to_block, ...)

Iteration

  • async for block in query — default iteration
  • query.with_progress(shards=N) — with progress bar and parallel fetching

Requirements

  • Python 3.10+
  • aiohttp >= 3.9.0
  • tqdm >= 4.67.1
  • ujson >= 5.11.0

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

sqd_py-0.1.5.tar.gz (24.1 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

sqd_py-0.1.5-py3-none-any.whl (31.0 kB view details)

Uploaded Python 3

File details

Details for the file sqd_py-0.1.5.tar.gz.

File metadata

  • Download URL: sqd_py-0.1.5.tar.gz
  • Upload date:
  • Size: 24.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for sqd_py-0.1.5.tar.gz
Algorithm Hash digest
SHA256 ab9b769f1b2e7b8b5651f8c1b105cf7d1ff38ccb31284b141f0ddbae53024624
MD5 5483fc3cb4785ed321b5a419c697ad0e
BLAKE2b-256 913a0341d536d42997388656f8fc4265d3e371d2dbd70b6297f7d7d20b3e473e

See more details on using hashes here.

File details

Details for the file sqd_py-0.1.5-py3-none-any.whl.

File metadata

  • Download URL: sqd_py-0.1.5-py3-none-any.whl
  • Upload date:
  • Size: 31.0 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.9.17 {"installer":{"name":"uv","version":"0.9.17","subcommand":["publish"]},"python":null,"implementation":{"name":null,"version":null},"distro":{"name":"macOS","version":null,"id":null,"libc":null},"system":{"name":null,"release":null},"cpu":null,"openssl_version":null,"setuptools_version":null,"rustc_version":null,"ci":null}

File hashes

Hashes for sqd_py-0.1.5-py3-none-any.whl
Algorithm Hash digest
SHA256 8a4d494f524cae23d89b2aa3b99f459813698113af9d38eadd7f0793b6d7c14f
MD5 5845f5b3f830edbd3b745607be4dce57
BLAKE2b-256 0cfd585a39fbf92904fffe9442a8742f3d14bde72046e45ed88bfd2d37ae6c86

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page