The official Python SDK for interacting with the Aptos blockchain. Get started with the integration guide.
Note: The sync client is deprecated. Please use the async client for all new projects.
pip install aptos-sdkimport asyncio
from aptos_sdk.account import Account
from aptos_sdk.async_client import FaucetClient, RestClient
async def main():
rest_client = RestClient("https://fullnode.devnet.aptoslabs.com/v1")
faucet_client = FaucetClient("https://faucet.devnet.aptoslabs.com", rest_client)
# Create and fund two accounts
alice = Account.generate()
bob = Account.generate()
await faucet_client.fund_account(alice.address(), 100_000_000)
await faucet_client.fund_account(bob.address(), 0)
# Transfer 1_000 octas from Alice to Bob
txn_hash = await rest_client.bcs_transfer(alice, bob.address(), 1_000)
await rest_client.wait_for_transaction(txn_hash)
print(f"Bob's balance: {await rest_client.account_balance(bob.address())}")
await rest_client.close()
asyncio.run(main())| Class | Description |
|---|---|
RestClient |
Async client for the Aptos REST API (accounts, transactions, events, blocks). |
FaucetClient |
Funds accounts on devnet/testnet via the faucet service. |
Account |
Represents a keypair and address; supports Ed25519 and Secp256k1. |
AccountAddress |
32-byte account address with AIP-40 compliant formatting. |
EntryFunction |
Constructs Move entry function payloads for submission. |
PackagePublisher |
Publishes and upgrades Move packages, with large-package chunking support. |
This SDK uses Poetry for packaging and dependency management:
curl -sSL https://install.python-poetry.org | python3 -
poetry installmake test- Download and install the Aptos CLI.
- Set the environment variable
APTOS_CLI_PATHto the full path of the CLI. - Retrieve the Aptos Core Github Repo (git clone https://github.com/aptos-labs/aptos-core)
- Set the environment variable
APTOS_CORE_REPOto the full path of the Repository. make integration_test
You can do this a bit more manually by:
First, run a local testnet (run this from the root of aptos-core):
aptos node run-local-testnet --force-restart --assume-yes --with-indexer-apiNext, tell the end-to-end tests to talk to this locally running testnet:
export APTOS_CORE_REPO="/path/to/repo"
export APTOS_FAUCET_URL="http://127.0.0.1:8081"
export APTOS_INDEXER_URL="http://127.0.0.1:8090/v1/graphql"
export APTOS_NODE_URL="http://127.0.0.1:8080/v1"Finally run the tests:
make examplesIntegration Testing Using the Aptos CLI:
make integration_testNote
The Python SDK does not require the Indexer, if you would prefer to test without it, unset or do not set the environmental variable APTOS_INDEXER_URL and exclude --with-indexer-api from running the aptos node software.
make fmtmake lint- Download the Aptos CLI.
- Set the environment variable
APTOS_CLI_PATHto the full path of the CLI. poetry run python -m aptos_sdk.cliand set the appropriate command-line parameters
This project follows semver as closely as possible