From 2422a64c5fa5ff37842fb983d4e7449126e12807 Mon Sep 17 00:00:00 2001 From: smartgoo Date: Sat, 26 Oct 2024 08:43:20 -0400 Subject: [PATCH] readme and wheel --- python/README.md | 36 +++++++++++++++++++++++++++--------- python/pyproject.toml | 22 ++++++++++++++++++++++ 2 files changed, 49 insertions(+), 9 deletions(-) create mode 100644 python/pyproject.toml diff --git a/python/README.md b/python/README.md index dbc4534a94..4b165f2c71 100644 --- a/python/README.md +++ b/python/README.md @@ -2,19 +2,37 @@ Rusty-Kaspa/Rust bindings for Python, using [PyO3](https://pyo3.rs/v0.20.0/) and [Maturin](https://www.maturin.rs). The result is a Python package that exposes rusty-kaspa/rust source for use in Python programs. # Building from Source -1. Ensure Python 3.8 or higher (`python --version`) is installed. [*TODO validate 3.8 or higher is correct*]. Python installers can be found on [python.org](https://www.python.org). -2. `cd ./python` -3. Create Python virtual environment: `python -m venv env` -4. Activate Python virtual env: -- Unix-based systems: `source env/bin/activate` +1. Ensure Python 3.9 or higher (`python --version`) is installed. +2. Clone Python SDK source: `git clone -b python https://github.com/aspectron/rusty-kaspa.git` +3. `cd rusty-kaspa` +4. `cd python` (Python SDK crate) +5. Create Python virtual environment with `python -m venv env` or your preferred env tool. +6. Activate Python virtual environment: +- Unix-like systems: `source env/bin/activate` - Windows: `env/scripts/activate.bat` -5. Install `maturin` build tool: `pip install maturin` +5. Install Maturin build tool: `pip install maturin` 6. Build Python package with Maturin: -- For local development, build and install in active Python virtual env: `maturin develop --release --features py-sdk` -- To build source and built (wheel) distributions: `maturin build --release --strip --sdist --features py-sdk` +- Build & install in current active virtual env: `maturin develop --release --features py-sdk` +- Build source and built (wheel) distributions: `maturin build --release --strip --sdist --features py-sdk`. The resulting wheel (.whl file) location will be printed `Built wheel for CPython 3.x to `. The `.whl` file can be copied to another location or machine and installed there with `pip install <.whl filepath>` # Usage from Python -See Python files in `./python/examples`. + +The Python SDK module name is `kaspa`. The following example shows how to connect an RPC client to Kaspa's PNN (Public Node Network). + +```python +import asyncio +from kapsa import Resolver, RpcClient + +async def main(): + resolver = Resolver() + client = RpcClient(resolver) + print(await client.get_server_info()) + +if __name__ == "__main__": + asyncio.run(main()) +``` + +More detailed examples can be found in `./examples`. # Project Layout The Python package `kaspa` is built from the `kaspa-python` crate, which is located at `./python`. diff --git a/python/pyproject.toml b/python/pyproject.toml new file mode 100644 index 0000000000..1c48184a7c --- /dev/null +++ b/python/pyproject.toml @@ -0,0 +1,22 @@ +[build-system] +requires = ["maturin>=1.0,<2.0"] +build-backend = "maturin" + +[project] +name = "kaspa" +version = "0.0.1" +description = "Kaspa Python SDK" +license = "ISC" +classifiers = [ + "Programming Language :: Python", + "Programming Language :: Rust", +] +dependencies = [] + +[package.metadata.maturin] +name = "kaspa" +description = "Kaspa Python SDK" + +[tool.maturin] +name = "kaspa" +features = ["pyo3/extension-module"] \ No newline at end of file