# Python

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:

• blockchain.py: A library for blockchain specific operations;
• factori_types.py: A library of types and functions used by all imported interfaces;
• my_contract_code.json: the Micheline code of your contract (useful for deployment);
• my_contract_python_interface.py: 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/scenario.py, you can also directly run:

python <dir>/python_sdk/scenario.py


## Description of the interface file

The interface file (my_contract_python_interface.py 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).