In order to use the Python Interface generation feature of Factori, you will need to have pytezos installed on your machine.

The Python SDK can be found in the src/python_sdk subfolder of your Factori project directory.

It is generated by activating the --python option of the factori import kt1 or factori import michelson commands, as seen below:

factori import kt1 <dir> KT1...XXX --network mainnet --name my_contract --python

<dir> is the working directory (it may be relative, such as .), and KT1...XXX is the address of the contract.

will create the directory <dir>/src/python_sdk where the following files and directories will appear:

  • A library for blockchain specific operations;
  • A library of types and functions used by all imported interfaces;
  • my_contract_code.json: the Micheline code of your contract (useful for deployment);
  • the Python interface to your contract, described below.

The command also creates a Makefile with useful commands such as:

make python-static-check

which will typecheck all code (generated and custom added) using mypy and/or pyright (you can comment whichever line you don't want).

make python-compile

which will run python on all files of the interface, but also on any scenario which you may find yourself writing inside <dir>/src/python_sdk/. If you created a <dir>/src/python_sdk/, you can also directly run:

python <dir>/python_sdk/

Description of the interface file

The interface file ( using the convention from above) consists of both

  1. Types
  2. Functions

The types describe the contract's storage as well as all the input types of the contract's entrypoints (and any intermediate types which may need to be defined in the process). The functions are (mainly) of three kinds:

  1. A deploy function deploy_my_contract;
  2. Calling functions for each entrypoint, of the form call_<entrypoint_name>.
  3. Utility functions for manipulating types, so that in principle, you never have to use Micheline or Michelson directly:
    • Encoding functions from a type to Micheline (<type name>_encode);
    • Decoding functions from Micheline to a type (<type name>_decode);
    • Random generation of elements of the type (<type name>_generator).

Note about Pytezos

Factori's Python generation uses the awesome Pytezos library. Please note that although there are many similarities between the kind of storage that Pytezos accepts for a given contract and that generated by Factori, they are not the same and it is not advised to mix them. Pytezos generates a dynamic interface (you generally can't look at it until you have retrieved a storage and looked at it), while Factori generates a static interface (you know its exact structure in advance).