Skip to main content

No project description provided

Project description



thirdweb Python SDK

pypi version Build Status Join our Discord!

Best in class Web3 SDK for Python 3.7+


Installation

pip install thirdweb-sdk

Getting Started

To start using this SDK, you just need to pass in a provider configuration. It's also strongly recommended that you use your thirdweb API keys with the SDK in order to get the best infrastructure performance (across RPCs, IPFS, etc.) - you can learn more about creating and using API keys here.

Instantiating the SDK

Once you have all the necessary dependencies, you can follow the following setup steps to get started with the SDK read-only functions:

from thirdweb import ThirdwebSDK
from thirdweb.types import SDKOptions

# Get your secret key from the thirdweb api keys dashboard
SECRET_KEY = "..."

# You can create a new instance of the SDK to use by passing in a network name and your api key
sdk = ThirdwebSDK("mumbai", options=SDKOptions(secret_key=SECRET_KEY))

The SDK supports the mainnet, rinkeby, goerli, polygon, mumbai, fantom, and avalanche networks.

Alternatively, if you want to use your own custom RPC URL, you can pass in the RPC URL directly as follows:

from thirdweb import ThirdwebSDK

# Set your RPC_URL
RPC_URL = "https://rpc-mainnet.matic.network"

# And now you can instantiate the SDK with it
sdk = ThirdwebSDK(RPC_URL)

Working With Contracts

Once you instantiate the SDK, you can use it to access your thirdweb contracts. You can use the SDK's contract getter functions like get_token, get_edition, get_nft_collection, and get_marketplace to get the respective SDK contract instances. To use an NFT Collection contract for example, you can do the following.

# Add your NFT Collection contract address here
NFT_COLLECTION_ADDRESS = "0x.."

# And you can instantiate your contract with just one line
nft_collection = sdk.get_nft_collection(NFT_COLLECTION_ADDRESS)

# Now you can use any of the read-only SDK contract functions
nfts = nft_collection.get_all()
print(nfts)

Signing Transactions

:warning: Never commit private keys to file tracking history, or your account could be compromised.

Meanwhile, if you want to use write functions as well and connect a signer, you can use the following setup:

from thirdweb import ThirdwebSDK
from thirdweb.types.nft import NFTMetadataInput
import os

# Get your secret key from the thirdweb api keys dashboard
SECRET_KEY = "..."

# This PRIVATE KEY is coming from your environment variables. Make sure to never put it in a tracked file or share it with anyone.
PRIVATE_KEY = os.environ.get("PRIVATE_KEY")

# Now you can create a new instance of the SDK with your private key
sdk = ThirdwebSDK.from_private_key(PRIVATE_KEY, "mumbai", options=SDKOptions(secret_key=SECRET_KEY))

# Instantiate a new NFT Collection contract as described above.
NFT_COLLECTION_ADDRESS = "0x.."
nft_collection = sdk.get_nft_collection(NFT_COLLECTION_ADDRESS)

# Now you can use any of the SDK contract functions including write functions
nft_collection.mint(NFTMetadataInput.from_json({ "name": "Cool NFT", "description": "Minted with the Python SDK!" }))

Development Environment

In this section, we'll go over the steps to get started with running the Python SDK repository locally and contributing to the code. If you aren't interested in contributing to the thirdweb Python SDK, you can ignore this section.

Poetry Environment Setup

If you want to work with this repository, make sure to setup Poetry, you're virtual environment, and the code styling tools.

Assuming you've installed and setup poetry, you can setup this repository with:

$ make init

Running Tests

Once you have run the initialization step, you can run the following to run all tests:

$ make test

Publishing the Package

To make a build & publish the package, you need to have a pypi account with permission to edit the thirdweb-sdk pypi package. You can authenticate your pypi account with poetry with the following command:

poetry config pypi-token.pypi pypi-token-here

Then, you can build and release a prerelease version with the following command:

make publish

Code Style Setup

Make sure you have mypy, pylint, and black installed (all included in the dev dependencies with poetry install.

If you're working in VSCode, there a few steps to get everything working with the poetry .venv:

  1. To setup poetry virtual environment inside your VSCode so it gets recognized as part of your project (import for linters), you can take the following steps from this stack overflow answer. You need to run poetry config virtualenvs.in-project true and then make sure you delete/create a new poetry env.
  2. In .vscode/settings.json, you should have the following:
{
  "python.linting.mypyEnabled": true,
  "python.linting.enabled": true,
  "python.linting.pylintEnabled": false
}
  1. Make sure to set your VSCode Python: Interpreter setting to the Python version inside your poetry virtual environment.

Generate Python ABI Wrappers

Use the abi-gen package to create the Python ABIs. You can install it with the following command:

$ npm install -g @0x/abi-gen

Assuming you have the thirdweb contract ABIs in this directory at /abi, you can run the following command to generate the necessary ABIs.

$ make abi

Project details


Release history Release notifications | RSS feed

This version

3.1.1

Download files

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

Source Distribution

thirdweb_sdk-3.1.1.tar.gz (818.3 kB view details)

Uploaded Source

Built Distribution

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

thirdweb_sdk-3.1.1-py3-none-any.whl (1.2 MB view details)

Uploaded Python 3

File details

Details for the file thirdweb_sdk-3.1.1.tar.gz.

File metadata

  • Download URL: thirdweb_sdk-3.1.1.tar.gz
  • Upload date:
  • Size: 818.3 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.1 CPython/3.9.16 Darwin/22.1.0

File hashes

Hashes for thirdweb_sdk-3.1.1.tar.gz
Algorithm Hash digest
SHA256 0382879b138472f3a9c0fdc3de6098d91371b24d8b67324aa5ae4042142956d8
MD5 919c8f86820f1c2340023cd2656a3fa8
BLAKE2b-256 ce2e968d6d2125bf266ff54a78b8fafcac562a5ed4e00ff12ab39ca4beef954b

See more details on using hashes here.

File details

Details for the file thirdweb_sdk-3.1.1-py3-none-any.whl.

File metadata

  • Download URL: thirdweb_sdk-3.1.1-py3-none-any.whl
  • Upload date:
  • Size: 1.2 MB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.4.1 CPython/3.9.16 Darwin/22.1.0

File hashes

Hashes for thirdweb_sdk-3.1.1-py3-none-any.whl
Algorithm Hash digest
SHA256 ba3506348b3f5769193c8fea10b79f4f3af67f121d4a512fea24017cd639a164
MD5 c60cc6c53bff9256e358c953334bddc2
BLAKE2b-256 cd0d91eacf0ca40da7043d769388919964720038370bb7480d2a27702bee159b

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