Skip to content

Main file

The main file is a python file that uses if __name__ == "__main__" to start the server. It enables SDK capabilities such as environment variables, authentication, global hooks and importing modules.

Note

Testing pipelines should not use the main file to start the server. For using hooks and other features consider splitting the files.

Creating the main file

It can have any name. In this example is named main.py.

from zapy import server
# (optional) setup authentication
# (optional) setup environment variables

if __name__ == "__main__":
    # only required when using GUI
    server.start_server({
        'reload': True
    })

Over the function server.start_server() it starts a uvicorn server. This function allows uvicorn uvicorn.run() arguments such as:

  • reload (default: False) which enables debug output and auto reload.

See more uvicorn run arguments here.

Warning

The server should only be started under if __name__ == "__main__":. Otherwise, it will raise an RuntimeError: The "freeze_support()" line can be omitted if the program is not going to be frozen to produce an executable.

Start server

On the top right click on offline. Under Main (optional), click on the Python icon to select the main file. Finally, click on Start server.

setup

What happens behind

One of the following commands is executed on a VSCode terminal.

If a Main file is specified

python my_main_file.py

otherwise

zapy start_server