Python NEAR contract build/deploy tool
Project description
Minimal build/deploy tool for Python NEAR smart contracts
This is a work-in-progress build/deploy tool for Python NEAR smart contracts.
Python source files are compiled into the WASM binary via MicroPython and Emscripten and then deployed via near-cli-rs tool.
near-py-tool CLI is modelled after cargo-near with most of the
command-line options compatible (not all are implemented yet).
Dependencies
near-py-tool expects the following dependencies installed:
- Python>=3.9
- essential build tools like
makeand C compiler - Emscripten for compiling Python into WASM via MicroPython (can be installed automatically by
near-py-tool, if desired) - near-cli-rs for NEAR Protocol interactions
Platform support
Currenly Linux, MacOS and Windows (native/MSYS2/WSL) platforms are supported
Python library support
Most of the MicroPython standard library is included and should be functional where applicable to WASM runtime environment.
External Python package are supported as long as they don't require native compiled code to work. near-py-tool will download any packages referenced
via pyproject.toml and will try to compile them into the WASM binary alongside the main contract.py file.
Unneeded modules from the MicroPython stdlib can be excluded from the build by adding the following section to pyproject.toml:
[tool.near-py-tool]
exclude-micropython-stdlib-packages = [...]
NEAR ABI support
Everything from https://github.com/near/near-sdk-rs/blob/master/near-sys/src/lib.rs should be available via near module, for example:
near.input()retrieves contract input asbytesnear.value_return(value)returns a value (strorbytes) from the contractnear.log_utf8(message)logs a message (str)
Contract methods to be exported from the WASM binary should be decorated with @near.export
See the NEAR-ABI.md for a complete list of available methods and their type signatures.
Benchmarks
See GAS-PROFILE-REPORT.md for gas statistics from the test runs
Stats for similar Rust/JS contracts are available here
Getting started
- install
near-py-toolviapip install near-py-tool - run
near-py-tool new test-projectto create a minimal Python smart contract project cd ./test-project- run
near-py-tool buildto produce a standalone WASM file - run
near-py-tool create-dev-accountto create a testnet account if you don't have one already - run
near-py-tool deployto deploy the smart contract
TODO
- NEAR ABI metadata generation
- porting of a few popular/useful contracts from Rust to Python
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file near_py_tool-0.1.26.tar.gz.
File metadata
- Download URL: near_py_tool-0.1.26.tar.gz
- Upload date:
- Size: 8.6 MB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
05e73f013c246508aea7cb7f7761f898033d84b431976592798dfc109130dacb
|
|
| MD5 |
5c84c00c69d0292089c9405b0ab00019
|
|
| BLAKE2b-256 |
daf6840be763704355b7d66817f54989b226f150c462f6c008d0a91b73dd68f2
|
File details
Details for the file near_py_tool-0.1.26-py3-none-any.whl.
File metadata
- Download URL: near_py_tool-0.1.26-py3-none-any.whl
- Upload date:
- Size: 11.8 MB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: uv/0.6.3
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
4a5ae7cee8e57cca938d3cd336d71263b654ba12f8d73984915a80e34588add9
|
|
| MD5 |
7f887308e83742dadd4715ecfbcabbfd
|
|
| BLAKE2b-256 |
59ef1680eb91c2f1f79c6997b3f4c26991e82384148c35b10264253e46abc928
|