Package: thirdweb-sdk
thirdweb Python SDKBest in class Web3 SDK for Python 3.7+Installationpipinstallthirdweb-sdkGetting StartedTo 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 keyshere.Instantiating the SDKOnce you have all the necessary dependencies, you can follow the following setup steps to get started with the SDK read-only functions:fromthirdwebimportThirdwebSDKfromthirdweb.typesimportSDKOptions# Get your secret key from the thirdweb api keys dashboardSECRET_KEY="..."# You can create a new instance of the SDK to use by passing in a network name and your api keysdk=ThirdwebSDK("mumbai",options=SDKOptions(secret_key=SECRET_KEY))The SDK supports themainnet,rinkeby,goerli,polygon,mumbai,fantom, andavalanchenetworks.Alternatively, if you want to use your own custom RPC URL, you can pass in the RPC URL directly as follows:fromthirdwebimportThirdwebSDK# Set your RPC_URLRPC_URL="https://rpc-mainnet.matic.network"# And now you can instantiate the SDK with itsdk=ThirdwebSDK(RPC_URL)Working With ContractsOnce you instantiate the SDK, you can use it to access your thirdweb contracts. You can use the SDK's contract getter functions likeget_token,get_edition,get_nft_collection, andget_marketplaceto 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 hereNFT_COLLECTION_ADDRESS="0x.."# And you can instantiate your contract with just one linenft_collection=sdk.get_nft_collection(NFT_COLLECTION_ADDRESS)# Now you can use any of the read-only SDK contract functionsnfts=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:fromthirdwebimportThirdwebSDKfromthirdweb.types.nftimportNFTMetadataInputimportos# Get your secret key from the thirdweb api keys dashboardSECRET_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 keysdk=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 functionsnft_collection.mint(NFTMetadataInput.from_json({"name":"Cool NFT","description":"Minted with the Python SDK!"}))Development EnvironmentIn 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 SetupIf you want to work with this repository, make sure to setupPoetry, you're virtual environment, and the code styling tools.Assuming you've installed and setup poetry, you can setup this repository with:$makeinitRunning TestsOnce you have run the initialization step, you can run the following to run all tests:$maketestPublishing the PackageTo make a build & publish the package, you need to have apypiaccount with permission to edit thethirdweb-sdkpypi package. You can authenticate your pypi account with poetry with the following command:poetryconfigpypi-token.pypipypi-token-hereThen, you can build and release a prerelease version with the following command:makepublishCode Style SetupMake sure you havemypy,pylint, andblackinstalled (all included in the dev dependencies withpoetry install.If you're working in VSCode, there a few steps to get everything working with the poetry .venv: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 thisstack overflow answer. You need to runpoetry config virtualenvs.in-project trueand then make sure you delete/create a new poetry env.In.vscode/settings.json, you should have the following:{"python.linting.mypyEnabled":true,"python.linting.enabled":true,"python.linting.pylintEnabled":false}Make sure to set your VSCodePython: Interpretersetting to the Python version inside your poetry virtual environment.Generate Python ABI WrappersUse theabi-genpackage to create the Python ABIs. You can install it with the following command:$npminstall-g@0x/abi-genAssuming you have the thirdweb contract ABIs in this directory at/abi, you can run the following command to generate the necessary ABIs.$makeabi