Skip to content

Python SDK

Github Repo Stars

PyPI Version

Python Version

The Python SDK lets you connect, explore, and interact with the Aptos blockchain. You can use it to request data, send transactions, set up test environments, and more.

Aptos publishes the official Python SDK on PyPI with source code in the aptos-python-sdk GitHub repository. The SDK requires Python 3.12+.

Install with pip:

Terminal window
pip install aptos-sdk

Or from source:

Terminal window
git clone https://github.com/aptos-labs/aptos-python-sdk
cd aptos-python-sdk
pip install .

Transfer APT from the tested example suite

Section titled “Transfer APT from the tested example suite”

The snippet below is pulled from v2/examples/transfer_apt.py in the SDK repository. When you install from PyPI, import the same APIs from aptos_sdk.v2 instead of aptos_sdk_v2.

transfer_apt.py
30 collapsed lines
"""Example: Transfer APT between accounts on devnet."""
import asyncio
from aptos_sdk_v2 import Account, Aptos, AptosConfig, Network
async def main():
config = AptosConfig(network=Network.DEVNET)
async with Aptos(config) as aptos:
# Create two accounts
alice = Account.generate()
bob = Account.generate()
print(f"Alice: {alice.address}")
print(f"Bob: {bob.address}")
# Fund Alice
print("\nFunding Alice...")
await aptos.faucet.fund_account(alice.address, 100_000_000)
# Fund Bob so account exists on-chain
print("Funding Bob...")
await aptos.faucet.fund_account(bob.address, 10_000_000)
# Check balances
alice_balance = await aptos.coin.balance(alice.address)
bob_balance = await aptos.coin.balance(bob.address)
print(f"\nAlice balance: {alice_balance}")
print(f"Bob balance: {bob_balance}")
# Transfer 1000 octas from Alice to Bob
print("\nTransferring 1000 octas from Alice to Bob...")
txn_hash = await aptos.coin.transfer(alice, bob.address, 1_000)
result = await aptos.transaction.wait_for_transaction(txn_hash)
print(f"Transaction: {txn_hash}")
print(f"Success: {result['success']}")
10 collapsed lines
# Check final balances
alice_balance = await aptos.coin.balance(alice.address)
bob_balance = await aptos.coin.balance(bob.address)
print(f"\nAlice balance: {alice_balance}")
print(f"Bob balance: {bob_balance}")
if __name__ == "__main__":
asyncio.run(main())