A complete Python library for interacting with the XRP Ledger blockchain, providing transaction creation, account management, and comprehensive XRPL protocol support
npx @tessl/cli install tessl/pypi-xrpl-py@4.3.0A complete Python library for interacting with the XRP Ledger blockchain, providing transaction creation, account management, cryptographic operations, and comprehensive XRPL protocol support. The library offers both synchronous and asynchronous interfaces for building applications that can send transactions, query ledger data, and interact with the decentralized exchange built into the XRPL.
pip install xrpl-pyimport xrplCommon imports for working with XRPL:
from xrpl import (
account, clients, models, transaction, utils, wallet,
CryptoAlgorithm, XRPLException
)
from xrpl.clients import JsonRpcClient
from xrpl.models.transactions import Payment
from xrpl.models.amounts import IssuedCurrencyAmount
from xrpl.wallet import WalletAsynchronous versions:
from xrpl import asyncio as xrpl_asyncio
from xrpl.asyncio.clients import AsyncJsonRpcClientfrom xrpl.clients import JsonRpcClient
from xrpl.wallet import Wallet
from xrpl.models.transactions import Payment
from xrpl import transaction
# Connect to XRPL testnet
client = JsonRpcClient("https://s.altnet.rippletest.net:51234")
# Create or load a wallet
wallet = Wallet.create()
print(f"Wallet address: {wallet.address}")
# Create a payment transaction
payment_tx = Payment(
account=wallet.address,
destination="rN7n7otQDd6FczFgLdSqtcsAUxDkw6fzRH",
amount="1000000" # 1 XRP in drops
)
# Sign and submit the transaction
response = transaction.submit_and_wait(payment_tx, client, wallet)
print(f"Transaction result: {response.result}")
# Query account information
account_info = account.get_balance(wallet.address, client)
print(f"Account balance: {account_info} drops")The xrpl-py library is organized around several key concepts:
The library provides both synchronous and asynchronous versions of most operations, extensive transaction type support for all XRPL features, robust utility functions, and comprehensive model classes for type-safe XRPL interactions.
Low-level cryptographic functions, address encoding/decoding, binary transaction encoding, and fundamental XRPL constants and types.
from xrpl.core.keypairs import generate_seed, derive_keypair, sign
from xrpl.core.addresscodec import encode_classic_address, decode_classic_address
from xrpl.core.binarycodec import encode, decode
from xrpl import CryptoAlgorithm, XRPLExceptionQuery account information, balances, transaction history, and verify account existence on the ledger.
from xrpl import account
def does_account_exist(address: str, client, ledger_index: str = "validated") -> bool: ...
def get_balance(address: str, client, ledger_index: str = "validated") -> int: ...
def get_account_root(address: str, client, ledger_index: str = "validated") -> dict: ...
def get_next_valid_seq_number(address: str, client, ledger_index: str = "current") -> int: ...Create, sign, submit, and manage XRPL transactions with full support for all transaction types including payments, offers, escrows, NFTs, AMM operations, and cross-chain bridges.
from xrpl import transaction
def sign(transaction, wallet, multisign: bool = False): ...
def submit(transaction, client, fail_hard: bool = False): ...
def sign_and_submit(transaction, client, wallet, autofill: bool = True, check_fee: bool = True): ...
def submit_and_wait(transaction, client, wallet, autofill: bool = True, check_fee: bool = True): ...
def autofill(transaction, client): ...Connect to XRPL networks using JSON-RPC or WebSocket protocols with both synchronous and asynchronous interfaces.
from xrpl.clients import JsonRpcClient, WebsocketClient
from xrpl.asyncio.clients import AsyncJsonRpcClient, AsyncWebsocketClient
class JsonRpcClient:
def __init__(self, url: str): ...
def request(self, request): ...
class WebsocketClient:
def __init__(self, url: str): ...
def send(self, request): ...Query ledger state information including current fees, ledger sequences, and network status.
from xrpl import ledger
def get_fee(client, max_fee_xrp: str = None) -> str:
"""Get current base fee and reserve amounts from the network."""
def get_latest_open_ledger_sequence(client) -> int:
"""Get the latest open (not yet validated) ledger sequence number."""
def get_latest_validated_ledger_sequence(client) -> int:
"""Get the latest validated ledger sequence number."""Comprehensive type-safe models for transactions, requests, amounts, currencies, and all XRPL data structures.
from xrpl.models.transactions import Payment, OfferCreate, TrustSet
from xrpl.models.amounts import IssuedCurrencyAmount, Amount
from xrpl.models.currencies import IssuedCurrency, XRP
from xrpl.models.requests import AccountInfo, Ledger, Tx
class Payment(Transaction):
destination: str
amount: Amount
...Create, manage, and operate XRPL wallets including key generation, address derivation, and testnet funding.
from xrpl.wallet import Wallet, generate_faucet_wallet
class Wallet:
address: str
public_key: str
private_key: str
seed: str
@classmethod
def create(cls, algorithm: CryptoAlgorithm = CryptoAlgorithm.ED25519) -> "Wallet": ...
@classmethod
def from_seed(cls, seed: str, algorithm: CryptoAlgorithm = CryptoAlgorithm.ED25519) -> "Wallet": ...Helper functions for unit conversions, time formatting, string encoding, NFT operations, and transaction analysis.
from xrpl.utils import (
xrp_to_drops, drops_to_xrp,
ripple_time_to_datetime, datetime_to_ripple_time,
str_to_hex, hex_to_str,
get_balance_changes, get_nftoken_id
)
def xrp_to_drops(xrp) -> str: ...
def drops_to_xrp(drops) -> Decimal: ...
def ripple_time_to_datetime(ripple_time: int) -> datetime: ...# Base exception
class XRPLException(Exception): ...
# Module-specific exceptions
class XRPLRequestFailureException(XRPLException): ...
class XRPLModelException(XRPLException): ...
class XRPLReliableSubmissionException(XRPLException): ...
class XRPLFaucetException(XRPLException): ...
class XRPLAddressCodecException(XRPLException): ...
class XRPLBinaryCodecException(XRPLException): ...
class XRPLKeypairsException(XRPLException): ...
class XRPRangeException(XRPLException): ...
class XRPLTimeRangeException(XRPLException): ...from xrpl import CryptoAlgorithm
class CryptoAlgorithm(str, Enum):
ED25519 = "ed25519"
SECP256K1 = "secp256k1"