<div align="center">
<img src="https://raw.githubusercontent.com/michaelhly/solana-py/master/docs/img/solana-py-logo.jpeg" width="25%" height="25%">
</div>
---
[![Actions
Status](https://github.com/michaelhly/solanapy/workflows/CI/badge.svg)](https://github.com/michaelhly/solanapy/actions?query=workflow%3ACI)
[![PyPI version](https://badge.fury.io/py/solana.svg)](https://badge.fury.io/py/solana)
[![Codecov](https://codecov.io/gh/michaelhly/solana-py/branch/master/graph/badge.svg)](https://codecov.io/gh/michaelhly/solana-py/branch/master)
[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/michaelhly/solana-py/blob/master/LICENSE)
[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/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](https://docs.solana.com/apps/jsonrpc-api),
much like you would do with
[solana-web3.js](https://github.com/solana-labs/solana-web3.js/)
It also covers the
[SPL Token Program](https://spl.solana.com/token).
[Latest Documentation](https://michaelhly.github.io/solana-py/).
Note: This library uses many core types from the [Solders](https://github.com/kevinheavey/solders) package which used to be provided by `solana-py` itself. If you are upgrading from an old version and you're looking for something that was deleted, it's probably in `solders` now.
**⚓︎ See also: [AnchorPy](https://github.com/kevinheavey/anchorpy),**
**a Python client for**
**[Anchor](https://project-serum.github.io/anchor/getting-started/introduction.html)-based**
**programs on Solana. ⚓︎**
## ⚡ Quickstart
### Installation
1. Install [Python bindings](https://kevinheavey.github.io/solders/) for the [solana-sdk](https://docs.rs/solana-sdk/latest/solana_sdk/).
```sh
pip install solders
```
2. Install this package to interact with the [Solana JSON RPC API](https://solana.com/docs/rpc).
```sh
pip install solana
```
### General Usage
Note: check out the
[Solana Cookbook](https://solanacookbook.com/)
for more detailed examples!
```py
import solana
```
### API Client
```py
from solana.rpc.api import Client
http_client = Client("https://api.devnet.solana.com")
```
### Async API Client
```py
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
```py
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[0].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[0].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](https://python-poetry.org/docs/#installation)
2. Install dev dependencies:
```sh
poetry install
```
3. Activate the poetry shell.
```sh
poetry shell
```
### Lint
```sh
make lint
```
### Tests
```sh
# All tests
make tests
# Unit tests only
make unit-tests
# Integration tests only
make int-tests
```
Raw data
{
"_id": null,
"home_page": "https://github.com/michaelhly/solanapy",
"name": "solana-py",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.8",
"maintainer_email": null,
"keywords": "solana, blockchain, web3",
"author": "Michael Huang",
"author_email": "michaelhly@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/83/0b/f75a5014cf541aa4787d3ca667856f91d1e6fc84392de53f2934f7d23a16/solana_py-0.34.5.tar.gz",
"platform": null,
"description": "<div align=\"center\">\n <img src=\"https://raw.githubusercontent.com/michaelhly/solana-py/master/docs/img/solana-py-logo.jpeg\" width=\"25%\" height=\"25%\">\n</div>\n\n---\n\n[![Actions\nStatus](https://github.com/michaelhly/solanapy/workflows/CI/badge.svg)](https://github.com/michaelhly/solanapy/actions?query=workflow%3ACI)\n[![PyPI version](https://badge.fury.io/py/solana.svg)](https://badge.fury.io/py/solana)\n[![Codecov](https://codecov.io/gh/michaelhly/solana-py/branch/master/graph/badge.svg)](https://codecov.io/gh/michaelhly/solana-py/branch/master)\n[![License: MIT](https://img.shields.io/badge/License-MIT-yellow.svg)](https://github.com/michaelhly/solana-py/blob/master/LICENSE)\n[![Code style: black](https://img.shields.io/badge/code%20style-black-000000.svg)](https://github.com/psf/black)\n\n# Solana.py\n\n**\ud83d\udc0d The Solana Python SDK \ud83d\udc0d**\n\nSolana.py is the base Python library for interacting with Solana.\nYou can use it to build transactions and interact\nwith the\n[Solana JSON RPC API](https://docs.solana.com/apps/jsonrpc-api),\nmuch like you would do with\n[solana-web3.js](https://github.com/solana-labs/solana-web3.js/)\n\nIt also covers the\n[SPL Token Program](https://spl.solana.com/token).\n\n[Latest Documentation](https://michaelhly.github.io/solana-py/).\n\nNote: This library uses many core types from the [Solders](https://github.com/kevinheavey/solders) package which used to be provided by `solana-py` itself. If you are upgrading from an old version and you're looking for something that was deleted, it's probably in `solders` now.\n\n**\u2693\ufe0e See also: [AnchorPy](https://github.com/kevinheavey/anchorpy),**\n**a Python client for**\n**[Anchor](https://project-serum.github.io/anchor/getting-started/introduction.html)-based**\n**programs on Solana. \u2693\ufe0e**\n\n## \u26a1 Quickstart\n\n### Installation\n1. Install [Python bindings](https://kevinheavey.github.io/solders/) for the [solana-sdk](https://docs.rs/solana-sdk/latest/solana_sdk/).\n```sh\npip install solders\n```\n\n2. Install this package to interact with the [Solana JSON RPC API](https://solana.com/docs/rpc).\n```sh\npip install solana\n```\n\n### General Usage\n\nNote: check out the\n[Solana Cookbook](https://solanacookbook.com/)\nfor more detailed examples!\n\n```py\nimport solana\n```\n\n### API Client\n\n```py\nfrom solana.rpc.api import Client\n\nhttp_client = Client(\"https://api.devnet.solana.com\")\n```\n\n### Async API Client\n\n```py\nimport asyncio\nfrom solana.rpc.async_api import AsyncClient\n\nasync def main():\n async with AsyncClient(\"https://api.devnet.solana.com\") as client:\n res = await client.is_connected()\n print(res) # True\n\n # Alternatively, close the client explicitly instead of using a context manager:\n client = AsyncClient(\"https://api.devnet.solana.com\")\n res = await client.is_connected()\n print(res) # True\n await client.close()\n\nasyncio.run(main())\n```\n\n### Websockets Client\n\n```py\nimport asyncio\nfrom asyncstdlib import enumerate\nfrom solana.rpc.websocket_api import connect\n\nasync def main():\n async with connect(\"wss://api.devnet.solana.com\") as websocket:\n await websocket.logs_subscribe()\n first_resp = await websocket.recv()\n subscription_id = first_resp[0].result\n next_resp = await websocket.recv()\n print(next_resp)\n await websocket.logs_unsubscribe(subscription_id)\n\n # Alternatively, use the client as an infinite asynchronous iterator:\n async with connect(\"wss://api.devnet.solana.com\") as websocket:\n await websocket.logs_subscribe()\n first_resp = await websocket.recv()\n subscription_id = first_resp[0].result\n async for idx, msg in enumerate(websocket):\n if idx == 3:\n break\n print(msg)\n await websocket.logs_unsubscribe(subscription_id)\n\nasyncio.run(main())\n```\n\n## \ud83d\udd28 Development\n\n### Setup\n\n1. Install [poetry](https://python-poetry.org/docs/#installation)\n2. Install dev dependencies:\n\n```sh\npoetry install\n\n```\n\n3. Activate the poetry shell.\n\n```sh\npoetry shell\n```\n\n### Lint\n\n```sh\nmake lint\n```\n\n### Tests\n\n```sh\n# All tests\nmake tests\n# Unit tests only\nmake unit-tests\n# Integration tests only\nmake int-tests\n```\n\n",
"bugtrack_url": null,
"license": "MIT",
"summary": "Solana Python API",
"version": "0.34.5",
"project_urls": {
"Documentation": "https://michaelhly.github.io/solana-py/",
"Homepage": "https://github.com/michaelhly/solanapy"
},
"split_keywords": [
"solana",
" blockchain",
" web3"
],
"urls": [
{
"comment_text": "",
"digests": {
"blake2b_256": "bb09ae4b0fc149c92a51889480955a964bea5d8fdf9e74fb8b2b80eb9667ca8c",
"md5": "d9f0cbf9ad1a2369ebc16c8c6b7bd370",
"sha256": "ded5bc15a7e3a75c1dc123d648890d482b26387ce637a4497d0015d87a99c769"
},
"downloads": -1,
"filename": "solana_py-0.34.5-py3-none-any.whl",
"has_sig": false,
"md5_digest": "d9f0cbf9ad1a2369ebc16c8c6b7bd370",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.8",
"size": 66552,
"upload_time": "2024-08-04T17:57:54",
"upload_time_iso_8601": "2024-08-04T17:57:54.009315Z",
"url": "https://files.pythonhosted.org/packages/bb/09/ae4b0fc149c92a51889480955a964bea5d8fdf9e74fb8b2b80eb9667ca8c/solana_py-0.34.5-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "830bf75a5014cf541aa4787d3ca667856f91d1e6fc84392de53f2934f7d23a16",
"md5": "0494c17b53e4aa50f1074dcb87930006",
"sha256": "bb90168d3290046f099d7991b7261065a6c8873ce2d0d080e71d2dfc0ec5c070"
},
"downloads": -1,
"filename": "solana_py-0.34.5.tar.gz",
"has_sig": false,
"md5_digest": "0494c17b53e4aa50f1074dcb87930006",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.8",
"size": 53819,
"upload_time": "2024-08-04T17:57:55",
"upload_time_iso_8601": "2024-08-04T17:57:55.397105Z",
"url": "https://files.pythonhosted.org/packages/83/0b/f75a5014cf541aa4787d3ca667856f91d1e6fc84392de53f2934f7d23a16/solana_py-0.34.5.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-08-04 17:57:55",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "michaelhly",
"github_project": "solanapy",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "solana-py"
}