Files

Files are where you implement functions for your worklets' Code and Decision blocks.

Let's write some code! Files are where you implement functions for your worklets' Code and Decision blocks. The development environment inserts a fully featured text editor with the same syntax highlighting and keyboard shortcuts as Visual Studio Code into the application development platform.

You can manage files in the bottom-left menu. Create a file with the "+" button, and use the three-dot menu next to each file to rename or delete it. The files main.py and requirements.txt cannot be renamed or deleted.

Console

You don't need to build a worklet to test the functions you implement in files. Instead, use the console tab at the bottom of the screen to bring up a familiar Python interface.

To run a function from a file, simply import that file by its name without the .py extension. For example, if your main.py contains the function passthrough() you'd enter in the console:

import main

main.passthrough({"arg": 1}, None, None)

And, just like in a Jupyter notebook, you'd receive the output of the last line:

{'arg': 1}

If your Python code needs custom pip packages, wheels, or system packages, you can add them to your Python environment.

You can also access the context variable that functions use in the console. However, note that each cell in the console has a separate session. So the following lines of code work when in the same cell, but not when in different cells.

context.session.add_all([Test(), Test()])
context.session.commit()

Editor settings

In the upper-right corner of the files tab, you can adjust your editor settings.

  • Auto-save: By default, your files are automatically saved as you work on them. Use this toggle to disable auto-saving.

  • Font size: Make the editor easier on the eyes.

  • Tab size: Baseten officially does not take a position on what tab size is the best ... but the default is four spaces (hides behind a printout of PEP 8).

Last updated