Ecosyste.ms: Awesome
An open API service indexing awesome lists of open source software.
https://github.com/amor71/solpyb
Pythonic Bridge to running and getting responses from Solana Programs
https://github.com/amor71/solpyb
blockchain blockchain-technology python python3 solana solana-program
Last synced: 5 days ago
JSON representation
Pythonic Bridge to running and getting responses from Solana Programs
- Host: GitHub
- URL: https://github.com/amor71/solpyb
- Owner: amor71
- License: lgpl-2.1
- Created: 2022-09-14T12:03:53.000Z (over 2 years ago)
- Default Branch: master
- Last Pushed: 2023-01-31T14:22:35.000Z (about 2 years ago)
- Last Synced: 2025-01-05T13:48:02.498Z (about 1 month ago)
- Topics: blockchain, blockchain-technology, python, python3, solana, solana-program
- Language: Python
- Homepage:
- Size: 115 KB
- Stars: 3
- Watchers: 2
- Forks: 0
- Open Issues: 3
-
Metadata Files:
- Readme: README.md
- License: LICENSE
- Security: SECURITY.md
Awesome Lists containing this project
README
[![Upload Python Package](https://github.com/amor71/solpyb/actions/workflows/python-publish.yml/badge.svg)](https://github.com/amor71/solpyb/actions/workflows/python-publish.yml)
[![codecov](https://codecov.io/gh/amor71/solpyb/branch/master/graph/badge.svg?token=gUJ78Gdh6q)](https://codecov.io/gh/amor71/solpyb)# solpyb
Pythonic Bridge to Solana Programs. Inspired by [Pydantic](https://pydantic-docs.helpmanual.io/)
## Overview
The project simplifies executing and getting responses from Solana Programs (a.k.a *Smart Contracts*), that are running on the Solana [Blockchain](https://solana.com/).
## Setup
`pip install solpyb`
## A Simple Example: Calculate *Linear Regression* on-chain
```python
import asyncio
from solpyb import SolBase, load_walletclass MyProgram(SolBase):
slope: float
intercept: floatcontract = MyProgram(
program_id="64ZdvpvU73ig1NVd36xNGqpy5JyAN2kCnVoF7M4wJ53e", payer=load_wallet()
)
if asyncio.run(contract([10.5, 20.7, 30.8, 40.12, 50.20, 60.0])):
print(f"slope: {contract.slope} intercept {contract.intercept}")
```*(This script is complete, it should run "as is")*
What's going on here:
* "64ZdvpvU73ig1NVd36xNGqpy5JyAN2kCnVoF7M4wJ53e" is a Solana Program (a.k.a *Smart Contract*) that performs a [Linear regression](https://en.wikipedia.org/wiki/Linear_regression) on set of points and returns the slope and intercept as floats.
* load_wallet() loads the default wallet keys (`.config/solana/id.json`), as the payer for the transaction.
* *MyProgram* class implement a Pythonic wrapper class. Calling the call creates a transaction on chain and result is returned,
* *SolBase* populates `slope` and `intercept` with the values returned from the Blockchain.