Skip to main content

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 make and C compiler
  • Emscripten for compiling Python into WASM via MicroPython (can be installed automatically by near-py-tool, if desired). Version 4.0.0 or above is recommended as there are issues with building some contracts on 3.x
  • 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 as bytes
  • near.value_return(value) returns a value (str or bytes) from the contract
  • near.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-tool via pip install near-py-tool
  • run near-py-tool new test-project to create a minimal Python smart contract project
  • cd ./test-project
  • run near-py-tool build to produce a standalone WASM file
  • run near-py-tool create-dev-account to create a testnet account if you don't have one already
  • run near-py-tool deploy to deploy the smart contract

Examples

While there is still plenty of work ahead of us, there are already some small yet useful apps implemented using this project:

TODO

  • NEAR ABI metadata generation
  • porting of a few popular/useful contracts from Rust to Python

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

near_py_tool-0.1.27.tar.gz (8.6 MB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

near_py_tool-0.1.27-py3-none-any.whl (11.8 MB view details)

Uploaded Python 3

File details

Details for the file near_py_tool-0.1.27.tar.gz.

File metadata

  • Download URL: near_py_tool-0.1.27.tar.gz
  • Upload date:
  • Size: 8.6 MB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: uv/0.6.3

File hashes

Hashes for near_py_tool-0.1.27.tar.gz
Algorithm Hash digest
SHA256 458a38fe23e8d475ae134d18759bbde3d7e251b67e2914941588bdd67cd62c06
MD5 1ba193a1cfbb1318ed51c97c892c6700
BLAKE2b-256 4aa579e9647820619c71f4391c27377a48afd1b3c0df25d3e4393c7642a3f14c

See more details on using hashes here.

File details

Details for the file near_py_tool-0.1.27-py3-none-any.whl.

File metadata

File hashes

Hashes for near_py_tool-0.1.27-py3-none-any.whl
Algorithm Hash digest
SHA256 11cc2d406b19652b068ab70e2fd9f994736f2bbb33a995b9b260572d2c71b928
MD5 34817af8abe229da177d37888eb5c02e
BLAKE2b-256 4951e737691cc0322eb3c66cffd643c5e518a5b9ea5aae92cfb84eefb2708814

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page