Introducing SmartPyBasic, a simple CLI to build Tezos smart contract in Python
3 min readSep 13, 2019

This document is now outdated. Please refer to our reference manual and installation instructions.

SmartPy is a Python library, accessible in an online editor, that comes together with its SmartML backend. It enables developers to define and analyse smart contracts. These smart contracts are compiled into Michelson, the Tezos virtual machine.

This is not the absolute go-to solution to use SmartPy in order to define smart contract on Tezos using Python. Users may want to automate non-regression tests, use their own editors, version control, etc.

We can now use a very simple yet effective tool called SmartPyBasic that brings the SmartPy to Michelson compilation to the desktop.

This is very preliminary and is proposed here to the community due to popular demand.

This document is now outdated. Please refer to our reference manual and installation instructions.


SmartPyBasic can be installed in a directory, say ~, by typing in a terminal:

sh <(curl -s local-install ~

It installs a few files:

~/SmartPyBasic/scripts         # A list of demo scripts (here, only # The SmartPy library # A helper module used by SmartPy, mostly in browser
smartmljs.bc.js # The SmartML library # A mock module to simulate a browser
smartmlbasic.js # A node JavaScript file to interact with SmartML # A helper library # A helper shell-script provides several useful entry points to the library.


SmartPyBasic depends on python3 and node.js.

A demo script

There is one demo script in SmartPyBasic: scripts/

Its code is the following:

## Copyright 2019 Smart Chain Arena LLC. ### To run this script, we need to setup a PYTHONPATH to the
# SmartPyBasic directory.
# If the SmartPyBasic directory is ~/SmartPyBasic, then
# PYTHONPATH=~/SmartPyBasic python3
# or
# ~/SmartPyBasic/ run
# should work.
import smartpy as spclass MyContract(sp.Contract):
def __init__(self, myParameter1, myParameter2):
self.init(myParameter1 = myParameter1,
myParameter2 = myParameter2)
def myEntryPoint(self, params):
sp.verify( <= 123) += params
# We evaluate a contract with parameters.
contract = MyContract(12, 13)
# We need to export the compile the contract.
# It can be done with the following.
import smartpybasic as spb
targetBaseFilename = /tmp/myContractDemo")
print("Contract compiled in /tmp/")

Direct use with Python

There are several possibilities, the simple one is to call python3 on a script after properly setting the PYTHONPATH.

For example, if we installed SmartPyBasic inside ~, we can do:

PYTHONPATH=~/SmartPyBasic python3 ~/SmartPyBasic/scripts/
ls -ltr /tmp/myContractDemo*

We can also do

~/SmartPyBasic/ run ~/SmartPyBasic/scripts/
ls -ltr /tmp/myContractDemo*

It then shows:

-rw-r--r--   ... myContractDemoExpression.smlse
-rw-r--r-- ...
-rw-r--r-- ...

These three files are:

  • .. .smlse: an internal expression between SmartPy and SmartML, kept for the record but not directly useful.
  • .. the Michelson representation of the storage.
  • .. the Michelson representation of the code.

The run command

SmartPy is a Python library that also uses some “syntactic sugar”.
In the editor, one can write:

sp.if, sp.else, sp.for, and sp.while.

In pure Python, for example with python3, these are not allowed.

They are currently replaced by the following constructions:

with sp.ifBlock(condition):
with sp.elseBlock():
with sp.forBlock('x', l) as x:
with sp.whileBlock(condition):

We can use the run argument of to recover the syntactic sugar.

~/SmartPyBasic/ run <>

The local-compile command

Another useful command is local-compile. It is similar ton run except that it takes a few extra arguments to call a class defined in a Python script.

~/SmartPyBasic/ local-compile "TicTacToe()" /tmp/tictactoe

It is also useful to directly call templates from for example.

Going further

SmartPyBasic is already quite useful but it is still early stage. We will provide in the future better Python integration in the desktop, better testing framework, etc.



An intuitive and effective smart contracts language and development platform for Tezos. In Python.