Python
Task Preparation
To execute Function tasks, you need to perform additional steps before deploying them. Please refer to the following instructions to create a Function task in Python.
Supported Libraries
We support most of the Python's Standard Library. Please read about using the Python standard library on WebAssembly platforms. Additionally, we are limited by requirements for determinism. Therefore, modules for threading, multiprocessing, subprocesses, or sockets are not supported.
Truebit includes some built-in libraries for you to use in your programs. We will be adding more built-in libraries, so please keep checking this page for updates.
Include external files
To include your external files, you need to use the TAR utility to pack them together. In this manner files will be packaged into a single file and can also be easily referenced from your code.
Setup TAR
Creating the TAR file
To create a single fs.tar
file that includes all the folders and files you want, simply run the following command:
In this example, the tar command will generate a file called fs.tar
which contains all the files found in the modules directory.
Considerations
fs.tar
is a reserved name for tar files in Truebit. You must always name the file in that way.The files included in the
fs.tar
file are read-only.
Input data files
You can use your own external data files in your function task. To include your data files, you need to use the TAR utility to pack them together and then, reference those files in your source code.
Modules
Import external modules
To import external modules, pack them all together into an fs.tar
file, then reference them in your Python code like this:
Import external functions
To import external functions, pack them all together into an fs.tar
file, then reference them in your Python code like this:
In the previous example, there's a function called fibonacci
in the modules/fibonacci.py
file, and another function called run_task
in the modules/reverse.py
file.
Import standard
To use pure python code, just import the stardard set of libraries
Import Built-in
To include the built-in libraries provided by Truebit, you will need to import them in the following way
Last updated
Was this helpful?