Python bindings for Solana Rust tools providing high-performance blockchain development primitives, RPC functionality, and testing infrastructure.
npx @tessl/cli install tessl/pypi-solders@0.26.00
# Solders
1
2
A high-performance Python library for interacting with the Solana blockchain. Solders provides Python bindings to core Solana Rust libraries, offering fast serialization/deserialization, cryptographic operations, transaction building, and RPC client functionality with native-level performance.
3
4
## Package Information
5
6
- **Package Name**: solders
7
- **Language**: Python
8
- **Installation**: `pip install solders`
9
- **Version**: 0.26.0
10
11
## Core Imports
12
13
```python
14
import solders
15
```
16
17
Essential core types for blockchain operations:
18
19
```python
20
from solders.pubkey import Pubkey
21
from solders.keypair import Keypair
22
from solders.signature import Signature
23
from solders.hash import Hash
24
```
25
26
Transaction building imports:
27
28
```python
29
from solders.transaction import Transaction, VersionedTransaction
30
from solders.instruction import Instruction, AccountMeta
31
from solders.message import Message, MessageV0
32
```
33
34
System operations:
35
36
```python
37
from solders.system_program import transfer, TransferParams
38
from solders.compute_budget import set_compute_unit_limit
39
```
40
41
## Basic Usage
42
43
### Creating a Simple Transfer Transaction
44
45
```python
46
from solders.keypair import Keypair
47
from solders.pubkey import Pubkey
48
from solders.transaction import Transaction
49
from solders.system_program import transfer, TransferParams
50
from solders.hash import Hash
51
52
# Generate keypairs
53
sender = Keypair()
54
recipient = Keypair()
55
56
# Create transfer instruction
57
transfer_ix = transfer(TransferParams(
58
from_pubkey=sender.pubkey(),
59
to_pubkey=recipient.pubkey(),
60
lamports=1000000 # 0.001 SOL
61
))
62
63
# Create transaction
64
recent_blockhash = Hash.from_string("11111111111111111111111111111112") # Example
65
tx = Transaction.new_with_payer([transfer_ix], sender.pubkey())
66
tx.recent_blockhash = recent_blockhash
67
68
# Sign transaction
69
tx.sign([sender], recent_blockhash)
70
```
71
72
### Working with Public Keys
73
74
```python
75
from solders.pubkey import Pubkey
76
77
# Create from string
78
pubkey = Pubkey.from_string("11111111111111111111111111111112")
79
80
# Create from bytes
81
pubkey_bytes = bytes(32) # 32 zero bytes
82
pubkey = Pubkey(pubkey_bytes)
83
84
# Get program derived address
85
seeds = [b"metadata", bytes(pubkey)]
86
program_id = Pubkey.from_string("TokenkegQfeZyiNwAJbNbGKPFXCWuBvf9Ss623VQ5DA")
87
pda, bump = Pubkey.find_program_address(seeds, program_id)
88
```
89
90
### Creating Instructions
91
92
```python
93
from solders.instruction import Instruction, AccountMeta
94
from solders.pubkey import Pubkey
95
96
# Create account metadata
97
accounts = [
98
AccountMeta(pubkey=sender.pubkey(), is_signer=True, is_writable=True),
99
AccountMeta(pubkey=recipient.pubkey(), is_signer=False, is_writable=True)
100
]
101
102
# Create instruction
103
instruction = Instruction(
104
program_id=Pubkey.from_string("11111111111111111111111111111112"),
105
accounts=accounts,
106
data=bytes([0, 1, 2, 3]) # Instruction data
107
)
108
```
109
110
## Architecture
111
112
Solders is organized into functional modules that mirror Solana's core architecture:
113
114
- **Cryptographic Layer**: Ed25519 keypairs, signatures, and SHA-256 hashing primitives
115
- **Transaction Layer**: Message construction, instruction building, and transaction formatting
116
- **Program Layer**: System program, compute budget, and token program interactions
117
- **Network Layer**: RPC client operations, commitment levels, and network configuration
118
- **State Layer**: Account management, sysvars, and blockchain state representations
119
120
The library leverages Rust's performance through native extensions while providing Pythonic interfaces. Most functionality is exposed through a native extension module `solders.solders`, ensuring fast serialization and cryptographic operations essential for blockchain interactions.
121
122
### Optional Dependencies
123
124
- **RPC functionality** requires the `ring` cryptographic library
125
- **LiteSVM testing** requires additional native dependencies
126
127
## Capabilities
128
129
### Cryptographic Primitives
130
131
Core blockchain cryptography including Ed25519 keypairs, signatures, public keys, and SHA-256 hashing. These primitives form the foundation for all Solana operations.
132
133
```python { .api }
134
class Pubkey:
135
def __init__(self, value: bytes): ...
136
@classmethod
137
def from_string(cls, s: str) -> 'Pubkey': ...
138
@staticmethod
139
def find_program_address(seeds: List[bytes], program_id: 'Pubkey') -> Tuple['Pubkey', int]: ...
140
141
class Keypair:
142
def __init__(self): ...
143
@classmethod
144
def from_seed(cls, seed: bytes) -> 'Keypair': ...
145
def pubkey(self) -> Pubkey: ...
146
def sign_message(self, message: bytes) -> 'Signature': ...
147
148
class Signature:
149
def __init__(self, signature_bytes: bytes): ...
150
@classmethod
151
def from_string(cls, s: str) -> 'Signature': ...
152
153
class Hash:
154
def __init__(self, value: bytes): ...
155
@classmethod
156
def from_string(cls, s: str) -> 'Hash': ...
157
```
158
159
[Cryptographic Primitives](./cryptographic-primitives.md)
160
161
### Transaction Construction
162
163
Transaction and message building with support for both legacy and versioned formats, including address lookup tables and instruction compilation.
164
165
```python { .api }
166
class Transaction:
167
def __init__(self, instructions: List[Instruction], payer: Optional[Pubkey]): ...
168
@staticmethod
169
def new_with_payer(instructions: List[Instruction], payer: Optional[Pubkey]) -> 'Transaction': ...
170
def sign(self, signers: List[Union[Keypair, Presigner]], recent_blockhash: Hash) -> None: ...
171
172
class VersionedTransaction:
173
def __init__(self, message: VersionedMessage, signatures: List[Signature]): ...
174
175
class Instruction:
176
def __init__(self, program_id: Pubkey, accounts: List[AccountMeta], data: bytes): ...
177
178
class AccountMeta:
179
def __init__(self, pubkey: Pubkey, is_signer: bool, is_writable: bool): ...
180
```
181
182
[Transaction Construction](./transaction-construction.md)
183
184
### Account Management
185
186
Account data structures, encoding formats, and metadata handling for both raw and parsed account information.
187
188
```python { .api }
189
class Account:
190
def __init__(self, lamports: int, data: bytes, owner: Pubkey, executable: bool, rent_epoch: int): ...
191
192
class UiAccountEncoding:
193
Base64: 'UiAccountEncoding'
194
JsonParsed: 'UiAccountEncoding'
195
Base58: 'UiAccountEncoding'
196
197
class CommitmentConfig:
198
def __init__(self, commitment: CommitmentLevel): ...
199
200
class CommitmentLevel:
201
Processed: 'CommitmentLevel'
202
Confirmed: 'CommitmentLevel'
203
Finalized: 'CommitmentLevel'
204
```
205
206
[Account Management](./account-management.md)
207
208
### System Programs
209
210
Built-in Solana programs including the System program for account creation and transfers, and the Compute Budget program for transaction optimization.
211
212
```python { .api }
213
def transfer(params: TransferParams) -> Instruction: ...
214
def create_account(params: CreateAccountParams) -> Instruction: ...
215
def allocate(params: AllocateParams) -> Instruction: ...
216
217
def set_compute_unit_limit(units: int) -> Instruction: ...
218
def set_compute_unit_price(micro_lamports: int) -> Instruction: ...
219
def request_heap_frame(bytes: int) -> Instruction: ...
220
221
# Address lookup table operations
222
def create_lookup_table(params: CreateLookupTableParams) -> Instruction: ...
223
def extend_lookup_table(params: ExtendLookupTableParams) -> Instruction: ...
224
def close_lookup_table(params: CloseLookupTableParams) -> Instruction: ...
225
```
226
227
[System Programs](./system-programs.md)
228
229
### Token Operations
230
231
SPL Token program support including token account management, associated token addresses, and token state parsing.
232
233
```python { .api }
234
def get_associated_token_address(owner: Pubkey, mint: Pubkey) -> Pubkey: ...
235
236
class Mint:
237
def __init__(self, mint_authority: Optional[Pubkey], supply: int, decimals: int, ...): ...
238
239
class TokenAccount:
240
def __init__(self, mint: Pubkey, owner: Pubkey, amount: int, ...): ...
241
242
class TokenAccountState:
243
Uninitialized: 'TokenAccountState'
244
Initialized: 'TokenAccountState'
245
Frozen: 'TokenAccountState'
246
```
247
248
[Token Operations](./token-operations.md)
249
250
### RPC Functionality
251
252
Comprehensive RPC client support with request/response handling, configuration options, and subscription capabilities for interacting with Solana networks.
253
254
```python { .api }
255
class GetAccountInfo:
256
def __init__(self, pubkey: Pubkey, config: Optional[RpcAccountInfoConfig]): ...
257
258
class GetBalance:
259
def __init__(self, pubkey: Pubkey, config: Optional[CommitmentConfig]): ...
260
261
class GetTransaction:
262
def __init__(self, signature: Signature, config: Optional[RpcTransactionConfig]): ...
263
264
class RpcAccountInfoConfig:
265
def __init__(self, encoding: Optional[UiAccountEncoding], ...): ...
266
```
267
268
[RPC Functionality](./rpc-functionality.md)
269
270
### Network and Sysvars
271
272
Network configuration, system variables, and blockchain state including clock information, rent parameters, and epoch scheduling.
273
274
```python { .api }
275
class Clock:
276
def __init__(self, slot: int, epoch_start_timestamp: Optional[int], epoch: int, ...): ...
277
278
class Rent:
279
def __init__(self, lamports_per_byte_year: int, exemption_threshold: float, burn_percent: int): ...
280
281
class EpochInfo:
282
def __init__(self, epoch: int, slot_index: int, slots_in_epoch: int, ...): ...
283
284
class EpochSchedule:
285
def __init__(self, slots_per_epoch: int, leader_schedule_slot_offset: int, ...): ...
286
```
287
288
[Network and Sysvars](./network-sysvars.md)
289
290
### Transaction Status
291
292
Transaction metadata, execution results, and status tracking including error handling and parsed transaction data.
293
294
```python { .api }
295
class TransactionStatus:
296
def __init__(self, slot: int, confirmations: Optional[int], ...): ...
297
298
class UiTransactionStatusMeta:
299
def __init__(self, err: Optional[TransactionErrorType], fee: int, ...): ...
300
301
class ParsedInstruction:
302
def __init__(self, program: str, program_id: Pubkey, parsed: dict): ...
303
304
TransactionErrorType = Union[TransactionErrorFieldless, TransactionErrorInstructionError, ...]
305
```
306
307
[Transaction Status](./transaction-status.md)
308
309
### Testing Infrastructure
310
311
LiteSVM lightweight runtime for local testing and transaction simulation without requiring a full Solana network.
312
313
```python { .api }
314
class LiteSVM:
315
def __init__(self): ...
316
def send_transaction(self, transaction: Union[Transaction, VersionedTransaction]) -> TransactionResult: ...
317
def get_account(self, pubkey: Pubkey) -> Optional[Account]: ...
318
def get_balance(self, pubkey: Pubkey) -> int: ...
319
320
TransactionResult = Union[TransactionMetadata, FailedTransactionMetadata]
321
```
322
323
[Testing Infrastructure](./testing-infrastructure.md)
324
325
### Error Handling
326
327
Comprehensive error types for transaction processing, serialization, signing operations, and RPC communications.
328
329
```python { .api }
330
class SignerError(Exception): ...
331
class BincodeError(Exception): ...
332
class SerdeJSONError(Exception): ...
333
class SanitizeError(Exception): ...
334
class TransactionError(Exception): ...
335
class ParseHashError(Exception): ...
336
```
337
338
[Error Handling](./error-handling.md)