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
  • near-cli-rs for NEAR Protocol interactions

Platform support

Currenly Linux (including WSL) and MacOS are supported with more platforms planned for the future.

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.

NEAR ABI support

Currenly a minimal version of NEAR WASM ABI is implemented via near module:

  • near.input(index) retrieves the specified 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-py-tool new-generated project for more details.

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

TODO

  • Proper Python exception support (currently any thrown exception will log the exception message and terminate the contract execution)
  • Tests and CI
  • NEAR ABI metadata generation
  • More platform support & automatic dependency installation

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.16.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.16-py3-none-any.whl (11.7 MB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for near_py_tool-0.1.16.tar.gz
Algorithm Hash digest
SHA256 a5ebd5897068f9549bea3ac9fb88d5f0e7bc88f346c5138215922481d3a73ff4
MD5 8820efda12fb5ec95fac8eccc30e3168
BLAKE2b-256 a3c6ad9d93aa26bd6a0868510009c179ba2eb64ae5d50382c69cfd0b0d812da7

See more details on using hashes here.

File details

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

File metadata

File hashes

Hashes for near_py_tool-0.1.16-py3-none-any.whl
Algorithm Hash digest
SHA256 b5c732619839d4c5ecdac58ac34fa65480c36a54ebc3f7542e46d3e189f7296d
MD5 62c08e5261bfb214745d6bdf67cc10a3
BLAKE2b-256 9259f5caffbcc6d82d0210fd8fdca111c95cfba358dfb2eda12d07f1df01d0e2

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