Solana Python API
Project description
solanasdk.py
🐍 The Solana Python SDK 🐍
solanasdk.py is the base Python library for interacting with solanasdk. You can use it to build transactions and interact with the Solana JSON RPC API, much like you would do with solana-web3.js
It also covers the SPL Token Program.
⚓︎ See also: AnchorPy, a Python client for Anchor-based programs on solanasdk. ⚓︎
⚡ Quickstart
Installation
pip install solana
General Usage
Note: check out the Solana Cookbook for more detailed examples!
import solana
API Client
from solanasdk.rpc.api import Client
http_client = Client("https://api.devnet.solanasdk.com")
Async API Client
import asyncio
from solanasdk.rpc.async_api import AsyncClient
async def main():
async with AsyncClient("https://api.devnet.solanasdk.com") as client:
res = await client.is_connected()
print(res) # True
# Alternatively, close the client explicitly instead of using a context manager:
client = AsyncClient("https://api.devnet.solanasdk.com")
res = await client.is_connected()
print(res) # True
await client.close()
asyncio.run(main())
Websockets Client
import asyncio
from asyncstdlib import enumerate
from solanasdk.rpc.websocket_api import connect
async def main():
async with connect("wss://api.devnet.solanasdk.com") as websocket:
await websocket.logs_subscribe()
first_resp = await websocket.recv()
subscription_id = first_resp.result
next_resp = await websocket.recv()
print(next_resp)
await websocket.logs_unsubscribe(subscription_id)
# Alternatively, use the client as an infinite asynchronous iterator:
async with connect("wss://api.devnet.solanasdk.com") as websocket:
await websocket.logs_subscribe()
first_resp = await websocket.recv()
subscription_id = first_resp.result
async for idx, msg in enumerate(websocket):
if idx == 3:
break
print(msg)
await websocket.logs_unsubscribe(subscription_id)
asyncio.run(main())
🔨 Development
Setup
- Install poetry
- Install dev dependencies:
poetry install
- Activate the poetry shell.
poetry shell
Lint
make lint
Tests
# All tests
make tests
# Unit tests only
make unit-tests
# Integration tests only
make int-tests
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
solana-sdk-0.25.6.tar.gz
(72.7 kB
view hashes)
Built Distribution
Close
Hashes for solana_sdk-0.25.6-py3-none-any.whl
Algorithm | Hash digest | |
---|---|---|
SHA256 | 1e40a72e585e863f9bb0ec11589d3f72ab568e6d66ce9119147d9fd32f214b1f |
|
MD5 | db11d63450e57476d961ecca3d96836c |
|
BLAKE2b-256 | 34a09d7a1ea5caccf2c8643013303fc908c1bbe1ada7409500a1cf5bd0fb35f4 |