Giter Site home page Giter Site logo

dpguoming / solana-py Goto Github PK

View Code? Open in Web Editor NEW

This project forked from michaelhly/solana-py

0.0 0.0 0.0 4.08 MB

Solana Python SDK

Home Page: https://michaelhly.github.io/solana-py

License: MIT License

Python 99.41% Makefile 0.13% Shell 0.45%

solana-py's Introduction


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

Solana.py

๐Ÿ The Solana Python SDK ๐Ÿ

Solana.py is the base Python library for interacting with Solana. 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 Solana. โš“๏ธŽ

โšก Quickstart

Installation

pip install solana

General Usage

Note: check out the Solana Cookbook for more detailed examples!

import solana

API Client

from solana.rpc.api import Client

http_client = Client("https://api.devnet.solana.com")

Async API Client

import asyncio
from solana.rpc.async_api import AsyncClient

async def main():
    async with AsyncClient("https://api.devnet.solana.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.solana.com")
    res = await client.is_connected()
    print(res)  # True
    await client.close()

asyncio.run(main())

Websockets Client

import asyncio
from asyncstdlib import enumerate
from solana.rpc.websocket_api import connect

async def main():
    async with connect("wss://api.devnet.solana.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.solana.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

solana-py's People

Contributors

02agarwalt avatar abacus-x avatar broper2 avatar cherryman avatar crypt0miester avatar csjiang avatar dboures avatar diceroll123 avatar dpgry avatar dpguoming avatar drbh avatar gcrispino avatar gqln avatar jbn avatar joehowarth avatar johnheavey avatar kevinheavey avatar kuznetsov-m avatar leofisg avatar lucasbruder avatar manuelzander avatar michaelhly avatar pietrodn avatar sebastiantoh avatar somebodyli avatar tkzcm avatar ulmentflam avatar unordered-set avatar whdev1 avatar zb-polysign avatar

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    ๐Ÿ–– Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. ๐Ÿ“Š๐Ÿ“ˆ๐ŸŽ‰

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google โค๏ธ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.