Skip to content

Commit

Permalink
README update (#111)
Browse files Browse the repository at this point in the history
  • Loading branch information
smartgoo authored Oct 26, 2024
1 parent 5d48525 commit 866e739
Show file tree
Hide file tree
Showing 2 changed files with 49 additions and 9 deletions.
36 changes: 27 additions & 9 deletions python/README.md
Original file line number Diff line number Diff line change
Expand Up @@ -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 <filepath>`. 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`.
Expand Down
22 changes: 22 additions & 0 deletions python/pyproject.toml
Original file line number Diff line number Diff line change
@@ -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"]

0 comments on commit 866e739

Please sign in to comment.