Skip to main content

sapysol

sapysol is a Solana Python wrapper. It doesn't reinvent what solana-py, solders or AnchorPy do, but rather uses their power to create easy-to-use Python classes and wrappers to rapidly develop short and fast Python scripts to interact with Solana blockchain.

Like @solana/web3.js helps developers write JS code, sapysol will ease using blockchain technologies to more developers that prefer Python instead. More developers on board - better for the community and Solana.

sapysol can also serve as a base layer for other wrappers because it simplifies Pubkey/Keypair management, creating and sending transactions, tokens, instructions etc.

WARNING! sapysol is currently in alpha version, so, bugs, lack of tests and descriptions are expected. Some things may not work, future versions may bring breaking changes. It is a hard path for Python in Solana and I hope we hat a lot of friends along the way.

Installation

pip install sapysol

Note: Requires Python >= 3.10.

Usage

sapysol uses Client instead of AsyncClient for few reasons:

  • First - without async you can put more logic to Python constructors and other non-async functions;
  • Second - what is the point of async if you really use await in 100% of cases?

Please use threading if you need parallel execution.

# ========================================
# Sending SOL to another wallet
from solana.rpc.api import Client 
from sapysol        import *

connection: Client          = Client("https://api.mainnet-beta.solana.com")
wallet:     SapysolWallet   = SapysolWallet(connection=connection, keypair="path/to/file.json")
result:     SapysolTxStatus = wallet.SendSol(destinationAddress="11111111111111111111111111111111", amountSol=0.5)
assert(result==SapysolTxStatus.SUCCESS)

# ========================================
# Jupiter swap
from solana.rpc.api import Client
from sapysol        import *
from sapysol.jupag  import SapysolJupag

connection: Client = Client("https://api.mainnet-beta.solana.com")
quote = SapysolJupag.GetSwapQuote(connection    = connection,
                                  tokenFrom     = "So11111111111111111111111111111111111111112",
                                  tokenTo       = "DezXAZ8z7PnrnRJjz3wXBoRgixCa6xjnB7YaB1pPB263", # BONK
                                  inAmount      = 1 * LAMPORTS_PER_SOL)
txB64 = SapysolJupag.GetSwapTxBase64(walletAddress=wallet.KEYPAIR.pubkey(), coinQuote=quote)
tx: SapysolTx = SapysolTx(connection=connection, payer=wallet.KEYPAIR)
tx.FromBase64(txB64)
result: SapysolTxStatus = tx.SendAndWait()
assert(result==SapysolTxStatus.SUCCESS)

# ========================================
# TODO - other simple use cases

TODO

Contributing

All contributions are welcome! Although the devil is in the details:

  • One of the main requirements is to keep the same coding style for all future changes.
  • sapysol is designed as a wrapper, one layer above solders/solana-py, don't expect it to do very narrow or specific tasks. If you need custom behavior in your case just go one level down and implement that using solders/solana-py in your local scripts.

Tests

TODO

Contact

Telegram

Donations: SAxxD7JGPQWqDihYDfD6mFp7JWz5xGrf9RXmE4BJWTS

Disclaimer

Intended Purpose and Use

The Content is provided solely for educational, informational, and general purposes. It is not intended for use in making any business, investment, or legal decisions. Although every effort has been made to keep the information up-to-date and accurate, no representations or warranties, express or implied, are made regarding the completeness, accuracy, reliability, suitability, or availability of the Content.

Opinions and Views

The views and opinions expressed herein are those of Anton Platonov and do not necessarily reflect the official policy, position, or views of any other agency, organization, employer, or company. These views are subject to change, revision, and rethinking at any time.

Third-Party Content and Intellectual Property

Some Content may include or link to third-party materials. The User agrees to respect all applicable intellectual property laws, including copyrights and trademarks, when engaging with this Content.

Amendments

Anton Platonov reserves the right to update or change this disclaimer at any time without notice. Continued use of the Content following modifications to this disclaimer will constitute acceptance of the revised terms.

Release files for sapysol 0.6.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for sapysol 0.6.0
File Size Uploaded
sapysol-0.6.0.tar.gz 20.9 kB Details

Built distribution (wheel)

Table of built distributions (wheels) for sapysol 0.6.0
File Interpreter ABI Platform
sapysol-0.6.0-py3-none-any.whl Python 3 none any Details

Total release size: 46.4 kB

Release files / sapysol-0.6.0.tar.gz

Download URL sapysol-0.6.0.tar.gz
Size 20.9 kB
Tags Source
SHA-256 checksum
How to use checksums
7c92cb5080a0d7e8c0ece6c96626934c464122b57ed1985c650b265babbe5ef4
BLAKE2b-256 checksum
How to use checksums
6352e8f8367981c2df9e1c079d2fcc44015eddc6622608dbd0415a4b322a2234
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.11.8 Linux/6.6.10-1-MANJARO

Release files / sapysol-0.6.0-py3-none-any.whl

Download URL sapysol-0.6.0-py3-none-any.whl
Size 25.5 kB
Tags Python 3
SHA-256 checksum
How to use checksums
00799d0fc935fd229f7df70b15239503f5c7c44d27599506f4236ba05df9b737
BLAKE2b-256 checksum
How to use checksums
d1542d26ca09f6adfed3003964a7baf0be02f89560005c82ed513090515e38c0
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via poetry/1.8.2 CPython/3.11.8 Linux/6.6.10-1-MANJARO

Release history Release notifications | RSS feed

This release

0.6.0 This release

2 release files

0.5.0

2 release files

0.4.1

2 release files

0.4.0

2 release files

0.3.0

2 release files

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page