Skip to main content

Actions Status PyPI version Codecov License: MIT Code style: black

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.

Latest Documentation.

⚓︎ 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

  1. Install poetry
  2. Install dev dependencies:
poetry install
  1. 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

Release files for solana-sdk 0.25.6

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for solana-sdk 0.25.6
File Size Uploaded
solana-sdk-0.25.6.tar.gz 72.7 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for solana-sdk 0.25.6
File Interpreter ABI Platform
solana_sdk-0.25.6-py3-none-any.whl Python 3 none any Details

Total release size: 160.2 kB

Release files / solana-sdk-0.25.6.tar.gz

Download URL solana-sdk-0.25.6.tar.gz
Size 72.7 kB
Tags Source
SHA-256 checksum
How to use checksums
6df0d248e8631962eae91ce4953257f658dc9ea741c3056eaeae6f84ad766c6a
BLAKE2b-256 checksum
How to use checksums
c204d9cb28052028caa5f00d8fa856ba37f79bc004b132b1d224de54a501c06e
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.0 CPython/3.10.4 Linux/5.15.6-051506-generic

Release files / solana_sdk-0.25.6-py3-none-any.whl

Download URL solana_sdk-0.25.6-py3-none-any.whl
Size 87.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
1e40a72e585e863f9bb0ec11589d3f72ab568e6d66ce9119147d9fd32f214b1f
BLAKE2b-256 checksum
How to use checksums
34a09d7a1ea5caccf2c8643013303fc908c1bbe1ada7409500a1cf5bd0fb35f4
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.2.0 CPython/3.10.4 Linux/5.15.6-051506-generic

Release history Release notifications | RSS feed

This release

0.25.6 This release

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page