Skip to main content

Thirdwave Python SDK for interacting with blockchain wallet intelligence API

Project description

Python SDK for Thirdwave's API

Python client for interacting with the Thirdwave wallet intelligence API over gRPC

Installation

Install the SDK using pip:

pip install thirdwave-sdk

Usage

Retrieving information about wallet or list of wallets

import nest_asyncio
import asyncio
from thirdwave_sdk import ThirdwaveClient

# Apply nest_asyncio to allow nested event loops
nest_asyncio.apply()


async def main():
    # Initialize the client
    thirdwave_client = ThirdwaveClient(api_key="MY-API-KEY", options={"transport_type": "secure"})
    await thirdwave_client.initialize()

    # Get a single wallet
    wallet_result = await thirdwave_client.wallet.get_one("0x0...")
    print("Single Wallet Result:", wallet_result)

    # Get multiple wallets
    wallet_list = ["0x0...", "0x0..."]
    async for wallet in thirdwave_client.wallet.get_many(wallet_list):
        print("Wallet from List:", wallet)

    # Close the client
    await thirdwave_client.close()


# Run the main function
if __name__ == "__main__":
    asyncio.run(main())

Retrieving information about Erc20 and Native tokens meta-data

import nest_asyncio
import asyncio

from thirdwave_sdk.client import ThirdwaveClient

nest_asyncio.apply()


async def main():
    # Initialize the client
    thirdwave_client = ThirdwaveClient(api_key="MY-API-KEY", options={"transport_type": "secure"})
    await thirdwave_client.initialize()

    wallet_list = ["0x0...", "0x0..."]

    # Using set to work only with unique token identifiers
    native_tokens_set = set()
    erc_20_tokens_set = set()
    
    async for wallet in thirdwave_client.wallet.get_many(wallet_list):
        native_tokens_set.update(item.blockchain_id for item in wallet.native_token_holdings if item is not None)
        erc_20_tokens_set.update((item.blockchain_id, item.address) for item in wallet.erc20_token_holdings if item is not None)

    async for data in thirdwave_client.wallet.get_native_tokens_metadata(native_tokens_set):
        print("Native token data: ", data)

    async for data in thirdwave_client.wallet.get_erc20_tokens_metadata(erc_20_tokens_set):
        print("Erc20 token data: ", data)

    # Close the client
    await thirdwave_client.close()


# Run the main function
if __name__ == "__main__":
    asyncio.run(main())

WalletService

The ThirdwaveClient class utilizes the WalletService to interact with the EVM Wallet service over gRPC. The WalletService provides methods for retrieving wallet information, streaming multiple wallets, and adding a wallet via a gRPC stream.

Attributes

channel: The gRPC channel used to communicate with the EVM Wallet service. api_key: The API key for authenticating requests. stub: The gRPC stub for the EVM Wallet service.

Initialization

init(self, channel, api_key: str) Initializes the WalletService.

Parameters:
  • channel: The gRPC channel to the EVM Wallet service.
  • api_key (str): The API key to authenticate requests.
Methods:
async get_one(self, address: str | bytes) -> EvmWallet

Retrieves the information for a single wallet by address.

Parameters:
  • address (str | bytes): The wallet address in string or bytes format.
Returns:
  • EvmWallet: The wallet object containing the details of the wallet.
Raises:

grpc.RpcError: If the gRPC call fails.

async get_many(self, addresses: List[str] | List[bytes]) -> AsyncGenerator[EvmWallet, None]

Streams information for multiple wallets given a list of addresses.

Parameters:
  • addresses (List[str] | List[bytes]): A list of wallet addresses in string or bytes format.
Yields:

EvmWallet: The wallet object for each address in the list.

Raises:

grpc.RpcError: If the gRPC call fails.


Dev Prerequisites

Setup virtual environment with direnv or poetry env

You can set up the virtual environment using either direnv or Poetry directly. Alternatively, you can set up a Poetry virtual environment by running make venv.

Setting Up Direnv

  1. Install direnv:

Follow the installation instructions for your operating system.

  1. Add this to ~/.direnvc

    layout_poetry() {
      if [[ ! -f pyproject.toml ]]; then
        log_error 'No pyproject.toml found.  Use `poetry new` or `poetry init` to create one first.'
        exit 2
      fi
    
      local VENV=$(dirname $(poetry run which python))
      export VIRTUAL_ENV=$(echo "$VENV" | rev | cut -d'/' -f2- | rev)
      export POETRY_ACTIVE=1
      PATH_add "$VENV"
    }
    
  2. Create .envrc:

    Create a .envrc file in the root of the project with the following content:

    layout poetry
    

Using Poetry to setup a virtual environment

To set up the virtual environment and install dependencies:

poetry env use python3.12

Setup Poetry and Install dependencies with make install

Update protocol buffers to the latest version

First remove existing protos with make clean_proto

make clean_proto

Pull latest proto files and build python stubs

make proto

Generate new proto files with make proto

Ensure that the generated code produced correct import paths, python's grpcio tools are not maintained as well as other languages and often generate code with broken imports

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

thirdwave_sdk-0.1.15.tar.gz (51.4 kB view details)

Uploaded Source

Built Distribution

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

thirdwave_sdk-0.1.15-py3-none-any.whl (57.9 kB view details)

Uploaded Python 3

File details

Details for the file thirdwave_sdk-0.1.15.tar.gz.

File metadata

  • Download URL: thirdwave_sdk-0.1.15.tar.gz
  • Upload date:
  • Size: 51.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/6.11.0-19-generic

File hashes

Hashes for thirdwave_sdk-0.1.15.tar.gz
Algorithm Hash digest
SHA256 1bcdbf2984271eb62aab874d4506b19bd812073e26320ba0179c45da4b6db550
MD5 847f16d08da44ac91ad14521f7655e38
BLAKE2b-256 2bace0e76773f6326b8775b1a063e6dc90905114f03243d7230272ed08e7a0e3

See more details on using hashes here.

File details

Details for the file thirdwave_sdk-0.1.15-py3-none-any.whl.

File metadata

  • Download URL: thirdwave_sdk-0.1.15-py3-none-any.whl
  • Upload date:
  • Size: 57.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.8.2 CPython/3.12.3 Linux/6.11.0-19-generic

File hashes

Hashes for thirdwave_sdk-0.1.15-py3-none-any.whl
Algorithm Hash digest
SHA256 0e18e96a85d0b96888436e2645bde32b6eb0b9e5d3fcefc6c7b2a6cbf5de4a80
MD5 95c2332e2629c55ac5171e06b5c90565
BLAKE2b-256 528f57c0685f79fc311ab990f0812b96d6640c66b5ae2245e80dd600baf053df

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