Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Python bindings initial feature set #602

Open
wants to merge 50 commits into
base: master
Choose a base branch
from

Conversation

smartgoo
Copy link

Python Bindings for Rusty Kaspa - using PyO3 and Maturin to build a native Python extension module named kaspa.

This initial version exposes wRPC Client, transaction creation, and key management functionality to Python.

WASM interface is mirrored as much as possible.


Added workspace member crates:

  • kaspa-python - main entry point for building Python package, and example usage from Python
  • kaspa-python-core - custom types used for Python interface
  • kaspa-python-macros
  • kaspa-wrpc-python - Python wRPC client

Added external dependencies: pyo3, pyo3-async-runtimes, serde-pyobject

A (very) high-level overview of bindings:

  • All Python bindings code is gated behind feature flag py-sdk. This feature was added to multiple existing RK crates.
  • Structs (and Enums) exposed to Python have attribute #[pyclass].
  • Methods exposed to Python exist inside impl blocks that have attribute #[pymethods].
  • Functions are exposed to Python using attribute #[pyfunction].
  • Where possible, exposed existing RK native/WASM code (structs, enums, functions, etc.). Where not possible (due to Python interface limitations/requirements), separate Python-compatible implementations were added.
  • In situations where both python and wasm directories exist at same level, created bindings directory and moved both under that directory.

CI:

  • On release - builds Python wheels for matrix of OS, architecture, and Python versions. End result is single zip that contains all wheels that is part of release.
  • On push/pull - builds Python wheels for only Linux x86_64.

smartgoo and others added 30 commits June 28, 2024 23:01
* Prototype of WASM/Python bindings

* Updated note

* Cargo.toml merge

* Note update

* Address, PrivateKey, PublicKey wasm/py protos

* rpc, dir rename

* lints
* kaspa-python-macros

* cleanup + rename 'inner' to 'client'
* Python dictionary for request and response

* readme update

* to_keypair block moves
* change python package name to 'kaspa'

* Introduce Py wRPC client wrapping Inner struct that contains KaspaRpcClient

* scaffolding for Python wRPC client Inner struct

* Python wRPC subscribtions prototype

* Python wRPC subscription callback args/kwargs

* lint

* minor refactor, handling of UTXO change notification

* properly gate python code in kaspa-rpc-core

* Attempt to fix test suite CI failure

* Subscribe UTXOs Changed

* subscriptions

* wRPC client disconnect

* unregister callbacks

* fix failing kaspad build
* wRPC minor cleanup

* resolver scaffolding

* wRPC client failing to init due to resolver network issue

* wRPC client constructor accept Resolver, network id

* network null when using url

* connect options and resolver methods

* lints

* rpc.py example tn11

* set network id on client

* bubble errors where possible

* lint
* Feat: adding pyi file and testing first commit

* Feat: Added py interface file

* fix python IDE autocompletion and imports
* Expose Keypair struct to Python

* PublicKeyGenerator

* XPub and XPrv

* DerivationPath

* python method names

* PrivateKey to_hex method impl

* Address Python method restructure

* PY-NOTE comment clean up

* addresses example usage from Python

* pyi file

* clippy failures due to 1.80
* Prototype of WASM/Python bindings

* Updated note

* Cargo.toml merge

* Note update

* Address, PrivateKey, PublicKey wasm/py protos

* rpc, dir rename

* lints
* kaspa-python-macros

* cleanup + rename 'inner' to 'client'
* Python dictionary for request and response

* readme update

* to_keypair block moves
* change python package name to 'kaspa'

* Introduce Py wRPC client wrapping Inner struct that contains KaspaRpcClient

* scaffolding for Python wRPC client Inner struct

* Python wRPC subscribtions prototype

* Python wRPC subscription callback args/kwargs

* lint

* minor refactor, handling of UTXO change notification

* properly gate python code in kaspa-rpc-core

* Attempt to fix test suite CI failure

* Subscribe UTXOs Changed

* subscriptions

* wRPC client disconnect

* unregister callbacks

* fix failing kaspad build
* wRPC minor cleanup

* resolver scaffolding

* wRPC client failing to init due to resolver network issue

* wRPC client constructor accept Resolver, network id

* network null when using url

* connect options and resolver methods

* lints

* rpc.py example tn11

* set network id on client

* bubble errors where possible

* lint
* Feat: adding pyi file and testing first commit

* Feat: Added py interface file

* fix python IDE autocompletion and imports
* Expose Keypair struct to Python

* PublicKeyGenerator

* XPub and XPrv

* DerivationPath

* python method names

* PrivateKey to_hex method impl

* Address Python method restructure

* PY-NOTE comment clean up

* addresses example usage from Python

* pyi file

* clippy failures due to 1.80
* XPrv additional methods to match WASM

* XPub additional methods to match WASM

* Address getters

* PrivateKeyGenerator

* Keypair

* Resolver

* .pyi file

* Python wRPC client examples

* transaction submission, wRPC dict -> Request conversion

* rebase

* transaction example update

* wallet duplicate py blocks
* Python ScriptBuilder

* address_from_script_public_key py util fn

* remove unused

* tx examples

* .pyi file

* script builder comment

* lint
* generator checkpoint

* generator checkpoint

* bug fixes

* krc20 deploy comment

* .pyi

* rust 1.82

* krc20 deploy example cleanup
* kaspa-python-core and pybinary

* ScriptBuilder use PyBinary

* ScriptPublicKey constructor PyBinary

* Transaction PyBinary

* TransactionInput PyBinary

* Generator, PendingTransaction PyBinary

* create_transaction payload type

* example clean up
* NetworkId, NetworkType interface cleanup

* .pyi upate
* derivation example and required bug fixes

* clean/bug fix existing examples
* Python wallet message signing

* message signing example

* .pyi
* tx mass wallet fns

* .pyi

* fmt
* estimate transaction

* generator example

* simple_transaction file name

* single_transaction  file name
* cargo updates

* migration to 0.22.5 and py-async-runtimes

* ScriptBuilder &Bound<T>

* PyUtxoEntries generator & utils

* PyOutputs generator & utils

* lints and cleanup
* signers

* lint

* remove comment

* remove comment
* String vs. &str

* result type and bubble where possible

* rpc result type, subscription callback print stack trace

* pubkey
* bindings dir for python

* rpc/wrpc/wasm -> rpc/wrpc/bindings/wasm

* wallet/core/src/wasm -> wallet/core/src/bindings/wasm/

* crypto/txscript/src/wasm -> crypto/txscript/src/bindings/wasm

* rpc/core/src/wasm -> rpc/core/src/bindings/wasm
* PaymentDestination::Change in Generator

* py-note cleanup

* comment clean up

* example cleanup

* cleanup

* lint
ci.yaml:
Compile one Python wheel (built distribution) for Linux x86_64 as simple test.

deploy.yaml:
Build wheels for select OS/architecture/Python versions
Pull all wheels into one zip available for download release page
* RpcClient url bug

* future_into_py simplification
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

Successfully merging this pull request may close these issues.

3 participants