Python for Solana
Python is a first-class off-chain language for Solana. Teams use it for bots, backend services, research notebooks, ETL, and ops automation against Agave 4.1.1 RPC nodes.
Search across all documentation pages
Python is a first-class off-chain language for Solana. Teams use it for bots, backend services, research notebooks, ETL, and ops automation against Agave 4.1.1 RPC nodes.
It does not run inside the Sealevel runtime. On-chain programs stay Rust (often Anchor 0.32.1), built and deployed with Solana CLI 3.0.10. Python talks to those programs over JSON-RPC, websockets, and IDL clients.
This page is the section umbrella. Sibling articles cover the SDK pair, transaction construction, AnchorPy, reads, bots, analytics, and production habits.
solana), AnchorPy, VersionedTransaction, blockhash, simulation / preflight, AsyncClient, getProgramAccounts / filters, DAS API, pandas / Polars, Python vs Kit.Solana program source is Rust 1.91.1 targeting sBPF. Python never enters that compile path. Your process is a normal host runtime that:
That separation is the whole model. Durable app state lives in accounts. Programs mutate them. Python observes, schedules, and sometimes signs.
The default Python stack is:
| Package | Role |
|---|---|
| solders | Fast Rust-backed types: Pubkey, Keypair, Instruction, messages, versioned txs, system and compute-budget helpers |
solana (solana-py) | JSON-RPC client (Client / AsyncClient), TxOpts, subscriptions |
| anchorpy | Load Anchor IDL, typed program.rpc / account fetch, Provider + Wallet |
Pin RPC URLs and program IDs per environment. Dev scripts should not silently point at mainnet-beta. For local work, combine Solana CLI 3.0.10 (solana-test-validator or team Surfpool / LiteSVM workflows for programs) with a Python venv for client code.
Money is always integers: lamports and token base units. Never use floats for balances, fees, or PnL that must match the chain.
solders is the type and serialization layer. It mirrors Solana primitives with Rust performance across the Python boundary. Prefer solders constructors for instructions, account metas, and message packing rather than hand-rolling wire formats.
solana-py (import path solana) is the network layer. Use it to:
get_latest_blockhash, get_balance, get_account_infosimulate_transaction and send_transactionget_signatures_for_address, get_transactionModern solana-py expects solders types. Treat them as one stack, not competing SDKs. Details and copy-paste recipes live in solders & solana-py.
The happy path for a Python-built transaction:
Message.new_with_blockhash or versioned message APIs).VersionedTransaction (or legacy only when a dependency forces it).Priority fees and compute limits are ordinary instructions (solders compute-budget helpers). Place them early in the message. Long-running bots must treat blockhash lifetime and duplicate-signature rules as core control-loop concerns, not edge cases.
Full composition patterns are in Building Transactions in Python.
If the on-chain program is Anchor 0.32.1, ship the IDL from anchor build and load it with AnchorPy. That gives you:
fetch / decodeProvider binding of RPC client, wallet, and default optionsWorkflow:
Provider + Program.at(...) or explicit Idl.from_json.program.rpc["instruction_name"](...) or build instructions for custom batching.Regenerate clients when the IDL changes. Mismatched discriminators or account order fail at simulation or runtime. AnchorPy sits on solders/solana-py; you still own blockhash, simulation, and confirmation. See AnchorPy.
Reads dominate most production Python services.
Core RPC
get_account_info (raw or jsonParsed where supported)get_balanceget_token_accounts_by_owner (and jsonParsed variants)get_signatures_for_address then get_transactionget_program_accounts with memcmp filters on discriminators or fixed fieldsDAS (Digital Asset Standard)
NFT and cNFT portfolios often need a provider DAS endpoint (getAsset, search, proofs). Use httpx or similar HTTP clients when solana-py does not wrap the method; keep DAS URLs and API keys out of git.
Production read habits
get_program_accounts with filters; do not dump whole programs on public RPCDeep dives: Reading Chain Data.
Python's comparative advantage is the data stack: pandas, Polars, NumPy, notebooks, and ML tooling.
Typical flow:
Treat chain time (slots, block times) carefully; join keys are usually pubkey, signature, or mint. Lamports stay integers until presentation. Patterns and framing: Data Analysis.
Python scripts should agree with how operators use Solana CLI 3.0.10: same RPC URL, same keypair JSON format (Keypair.from_bytes on the 64-byte secret array), same cluster (devnet / mainnet-beta / local). Agave 4.1.1 RPC semantics (commitment, simulation meta, compute unit reporting) are what your client must handle - not a separate "Python Solana."
| Need | Prefer | Why |
|---|---|---|
| Wallet connect, browser dApp, Action/Blink POST in Next.js | @solana/kit 7.0.0 | Wallet standards, web ecosystem, this site's default frontend stack |
| Bots, batch jobs, ML, pandas/Polars research | Python | Async services + data science libraries |
| Shared monorepo of TS services and web | Kit (or dual clients) | One language for product path |
| Existing Python FastAPI/Django estate | Python | Reuse auth, queues, and observability |
| Codama / Kit-first typed clients for many programs | Kit | Stronger codegen story in the TS world |
| Anchor IDL calls from a research laptop | AnchorPy | Fast path without a frontend |
Many orgs run both: Kit in the user-facing app; Python for market data, risk, rebalancing, and ops. The wire format is the same - versioned transactions and RPC JSON. Do not invent a second program interface per language; share program IDs, IDL versions, and account layout docs.
processed for snappy UX is not settlement for accounting; pick commitment per risk.Trading and automation glue RPC reads, transaction builders, and risk limits into a control loop. That sits on the same foundations as this overview; section pages for trading and best practices cover pacing, priority fees, and failure handling without turning Python into a strategy black box.
Python does not care whether the program is Anchor, native solana-program, or Pinocchio. You need correct program id, account metas, and instruction bytes. AnchorPy reduces that cost for Anchor IDLs. For native programs, hand-build with solders or maintain small codecs shared with Rust tests.
Off-chain work: reading accounts, building and sending transactions, calling programs via RPC/IDL, running bots, backends, and analytics. Programs stay Rust (or other sBPF toolchains).
A venv, then solders and solana (solana-py). Add anchorpy when you call Anchor programs. Add httpx, pandas or polars for DAS and analytics.
Yes for modern solana-py: core types and serialization come from solders. Learn both packages as one stack.
When you invoke Anchor 0.32.1 programs and want IDL-driven instruction and account clients instead of manual discriminators and account metas.
Compose solders instructions, fetch a recent blockhash, build a message, sign a versioned transaction, simulate, then send via solana-py. See Building Transactions in Python.
Use RPC token account methods for SPL balances and a DAS-capable provider for NFT/cNFT metadata and compression-aware queries. See Reading Chain Data.
Possible but awkward. Prefer @solana/kit 7.0.0 (and wallet adapters) in the browser; keep Python for servers and bots that do not need in-page wallet UX.
They are RPC clients of Agave nodes (or compatible providers). Commitment levels, simulation results, and fee markets match cluster behavior - not a Python-specific chain.
Load Solana CLI-compatible keypair JSON only in secure environments. Prefer env vars or a secrets manager. Never commit key files. Use hot wallets with limited funds for bots.
Blockhashes are short-lived. Long event loops must refresh blockhashes and resign. Retry policies should detect expiry and rebuild, not resubmit a stale signature forever.
Pull bounded signature or account samples (or indexer CSV/Parquet), normalize integer amounts, then aggregate in pandas/Polars. See Data Analysis.
Prefer AsyncClient when you poll many accounts, fan out RPC, or mix websockets with sends. Sync Client is fine for short scripts.
This overview, then Python for Solana Basics, then solders/solana-py, transactions, AnchorPy, reads, and analytics as your role requires.
Not strictly for RPC-only scripts, but CLI 3.0.10 is invaluable for keygen, airdrops on devnet, config, and aligning cluster settings with your Python env.
Deployment is a CLI / toolchain concern (solana program deploy, Anchor deploy). Python can wrap subprocess calls in ops automation; it does not replace cargo build-sbf.
Stack versions: This page was written for Agave 4.1.1, Solana CLI 3.0.10, Anchor 0.32.1, Rust 1.91.1, and @solana/kit 7.0.0.
Reviewed by Chris St. John·Last updated Jul 15, 2026