Skip to main content

Solana Python API

Project description


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

Project details


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 details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

solana_sdk-0.25.6-py3-none-any.whl (87.5 kB view details)

Uploaded Python 3

File details

Details for the file solana-sdk-0.25.6.tar.gz.

File metadata

  • Download URL: solana-sdk-0.25.6.tar.gz
  • Upload date:
  • Size: 72.7 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.0 CPython/3.10.4 Linux/5.15.6-051506-generic

File hashes

Hashes for solana-sdk-0.25.6.tar.gz
Algorithm Hash digest
SHA256 6df0d248e8631962eae91ce4953257f658dc9ea741c3056eaeae6f84ad766c6a
MD5 cfb78352d69f1d3124121d87efc48f5f
BLAKE2b-256 c204d9cb28052028caa5f00d8fa856ba37f79bc004b132b1d224de54a501c06e

See more details on using hashes here.

File details

Details for the file solana_sdk-0.25.6-py3-none-any.whl.

File metadata

  • Download URL: solana_sdk-0.25.6-py3-none-any.whl
  • Upload date:
  • Size: 87.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.2.0 CPython/3.10.4 Linux/5.15.6-051506-generic

File hashes

Hashes for solana_sdk-0.25.6-py3-none-any.whl
Algorithm Hash digest
SHA256 1e40a72e585e863f9bb0ec11589d3f72ab568e6d66ce9119147d9fd32f214b1f
MD5 db11d63450e57476d961ecca3d96836c
BLAKE2b-256 34a09d7a1ea5caccf2c8643013303fc908c1bbe1ada7409500a1cf5bd0fb35f4

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page