<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)
[![Python versions](https://img.shields.io/pypi/pyversions/solana.svg)]( https://pypi.python.org/pypi/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)
[![PyPI - Downloads](https://img.shields.io/pypi/dm/solana)](https://pypistats.org/packages/solana)
# 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-fork",
"maintainer": null,
"docs_url": null,
"requires_python": "<4.0,>=3.11",
"maintainer_email": null,
"keywords": "solana, blockchain, web3",
"author": "Michael Huang",
"author_email": "michaelhly@gmail.com",
"download_url": "https://files.pythonhosted.org/packages/b7/7a/82f7d31a2d5321021b04260d369cdb64558289bb5afe63af4303f0e426ca/solana_fork-0.36.1.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[![Python versions](https://img.shields.io/pypi/pyversions/solana.svg)]( https://pypi.python.org/pypi/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[![PyPI - Downloads](https://img.shields.io/pypi/dm/solana)](https://pypistats.org/packages/solana)\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",
"bugtrack_url": null,
"license": "MIT",
"summary": "Solana Python API",
"version": "0.36.1",
"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": "5d6145877302fe7c8a96169c1c6cbe917dca43699659395655a43bf37129ac53",
"md5": "363190fada6f0e3c109745b2c931b79d",
"sha256": "3cfe798a64971e940ca81978e594ee9f5aa24155dc816a6122b09fa48a6c6fd3"
},
"downloads": -1,
"filename": "solana_fork-0.36.1-py3-none-any.whl",
"has_sig": false,
"md5_digest": "363190fada6f0e3c109745b2c931b79d",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "<4.0,>=3.11",
"size": 62224,
"upload_time": "2024-12-13T02:46:47",
"upload_time_iso_8601": "2024-12-13T02:46:47.554060Z",
"url": "https://files.pythonhosted.org/packages/5d/61/45877302fe7c8a96169c1c6cbe917dca43699659395655a43bf37129ac53/solana_fork-0.36.1-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": "",
"digests": {
"blake2b_256": "b77a82f7d31a2d5321021b04260d369cdb64558289bb5afe63af4303f0e426ca",
"md5": "7d8114caea4c5b95068eaf2e5222d11b",
"sha256": "201126099b7774afea5ea2c14a1249814d590da76455050dc3ea7b2a2af76be8"
},
"downloads": -1,
"filename": "solana_fork-0.36.1.tar.gz",
"has_sig": false,
"md5_digest": "7d8114caea4c5b95068eaf2e5222d11b",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "<4.0,>=3.11",
"size": 52222,
"upload_time": "2024-12-13T02:46:50",
"upload_time_iso_8601": "2024-12-13T02:46:50.364626Z",
"url": "https://files.pythonhosted.org/packages/b7/7a/82f7d31a2d5321021b04260d369cdb64558289bb5afe63af4303f0e426ca/solana_fork-0.36.1.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2024-12-13 02:46:50",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "michaelhly",
"github_project": "solanapy",
"travis_ci": false,
"coveralls": false,
"github_actions": true,
"lcname": "solana-fork"
}