Python SDK Quickstart
-
Install the Python SDK
The SDK requires Python 3.12+.
Terminal window pip install aptos-sdk -
Create a project file
Terminal window mkdir aptos-python-quickstartcd aptos-python-quickstarttouch quickstart.py -
Set up the Aptos client
Use the v2 API (
aptos_sdk.v2). A connection is established as soon as you create the client.import asynciofrom aptos_sdk.v2 import Account, Aptos, AptosConfig, Networkasync def main():async with Aptos(AptosConfig(network=Network.DEVNET)) as aptos:print("Connected to Aptos devnet")asyncio.run(main()) -
Create and fund accounts
Generate credentials, then fund the accounts so the network knows they exist. On localnet and devnet you can fund from a faucet.
alice = Account.generate()bob = Account.generate()await aptos.faucet.fund_account(alice.address, 100_000_000)await aptos.faucet.fund_account(bob.address, 10_000_000)On testnet, mint from the faucet page.
-
Transfer APT
aptos.coin.transferbuilds, signs, and submits an APT transfer. Then wait for the transaction to land.txn_hash = await aptos.coin.transfer(alice, bob.address, 1_000)result = await aptos.transaction.wait_for_transaction(txn_hash)print(f"Success: {result['success']}")For the lower-level build → simulate → sign → submit → wait flow, see Building Transactions.
Full Quickstart Code
Section titled “Full Quickstart Code”"""Create two accounts, fund them, and transfer APT on devnet."""
import asyncio
from aptos_sdk.v2 import Account, Aptos, AptosConfig, Network
ALICE_INITIAL_BALANCE = 100_000_000BOB_INITIAL_BALANCE = 10_000_000TRANSFER_AMOUNT = 1_000
async def main(): async with Aptos(AptosConfig(network=Network.DEVNET)) as aptos: alice = Account.generate() bob = Account.generate()
print("=== Addresses ===") print(f"Alice: {alice.address}") print(f"Bob: {bob.address}")
await asyncio.gather( aptos.faucet.fund_account(alice.address, ALICE_INITIAL_BALANCE), aptos.faucet.fund_account(bob.address, BOB_INITIAL_BALANCE), )
print("=== Initial Balances ===") print(f"Alice: {await aptos.coin.balance(alice.address)}") print(f"Bob: {await aptos.coin.balance(bob.address)}")
txn_hash = await aptos.coin.transfer(alice, bob.address, TRANSFER_AMOUNT) result = await aptos.transaction.wait_for_transaction(txn_hash) print(f"Transaction: {txn_hash}") print(f"Success: {result['success']}")
print("=== Final Balances ===") print(f"Alice: {await aptos.coin.balance(alice.address)}") print(f"Bob: {await aptos.coin.balance(bob.address)}")
asyncio.run(main())Run it with:
python quickstart.pySummary
Section titled “Summary”You just learned how to transfer APT by:
- Connecting to the network with the
Aptosclient. - Creating and funding accounts.
- Submitting a transfer and waiting for execution.