Stellar SDK

raw JSON →
13.2.1 verified Fri May 01 auth: no python

The Python Stellar SDK provides APIs to build transactions, interact with Horizon and Stellar RPC servers, and support Soroban smart contracts. Version 13.2.1 supports Protocol 23, SEP-45, and async operations. Released roughly monthly on GitHub.

pip install stellar-sdk
error AttributeError: module 'stellar_sdk' has no attribute 'Server'
cause Server is not directly under stellar_sdk; it's in a submodule.
fix
Use from stellar_sdk.server import Server
error stellar_sdk.exceptions.NotFoundError: Resource not found
cause Using a public network Horizon URL for a testnet account, or vice versa.
fix
Match the horizon_url to the network: testnet -> https://horizon-testnet.stellar.org, public -> https://horizon.stellar.org
error stellar_sdk.exceptions.BadRequestError: ... "op_no_destination"
cause Payment operation has no destination account or invalid destination.
fix
Ensure the destination account exists on the network and is a valid Stellar address.
breaking In v13.0.0, `StrKey` added support for med25519, liquidity pools, and claimable balances. Existing encoded strings may change interpretation.
fix Review usage of `StrKey.decode_ed25519_public_key` or similar; ensure encoded data still works as expected.
deprecated `diagnostic_events_xdr` has been removed from `stellar_sdk.soroban_rpc.Events`. Use `GetTransactionResponse.diagnostic_events_xdr` instead.
fix Access `diagnostic_events_xdr` via `GetTransactionResponse` or `Transaction` objects.
gotcha `SorobanServer.get_events()` and similar paginated methods: `start_ledger` is optional, but if omitted the server may return unexpected results.
fix Always pass `start_ledger` explicitly when paginating to avoid missing events.
breaking From v13.0.0, Transaction meta handling is updated for Protocol 23 v4. Older meta formats may not parse correctly.
fix Ensure any metadata deserialization code is updated for the new XDR format (v4).
gotcha When creating a `TransactionBuilder`, you must provide a valid `network_passphrase`. Using the wrong passphrase (e.g., testnet vs public) will cause submission failures.
fix Use `stellar_sdk.Network.TESTNET_NETWORK_PASSPHRASE` or `Network.PUBLIC_NETWORK_PASSPHRASE`.

Generate a random keypair and load its account from the testnet.

from stellar_sdk.keypair import Keypair
from stellar_sdk.server import Server

server = Server(horizon_url="https://horizon-testnet.stellar.org")
keypair = Keypair.random()
print(f"Public: {keypair.public_key}, Secret: {keypair.secret}")
account = server.load_account(keypair.public_key)
print(f"Sequence: {account.sequence}")