Multiple files
Overview
Supporting multiple files in UbiFunctions improves flexibility and scalability. When building serverless functions, splitting code into multiple files improves maintainability, enables reuse, and aligns with common software development practices.
UbiFunctions allows you to use multiple files such as:
Source files: These files contain code that can be executed.
Config files: These are typically
.json,.conf,.toml, or similar files. They do not contain executable code. Instead, they provide the data and parameters your logic needs to run with a particular behavior.Data files: These are files that store information in various formats, such as
.csv,.txt, or.json. They can contain structured, semi-structured, or unstructured data used as input for processing or analysis.Binary files: These are non-text files, such as machine learning models (
.tflite,.onnx), documents (.pdf,.xlsx), images, or databases (.sqlite). See Binary files.
Creating a file
To create a file in your UbiFunction root directory, click the + icon in the files pane, then select New file. Enter a name. The new file is added to your UbiFunction:


Creating a folder
Folders help you organize modules more effectively. To create a folder, click the + icon in the files pane, then select New folder. Enter a name. The new folder is added to your UbiFunction:


Creating files or folders within a folder
To create a file or folder inside an existing folder, hover over the folder, click the three-dot menu, and select New file or New folder.


File structure and imports
When you add files or folders to a UbiFunction, they behave like a directory on your local machine, with the root directory as the working directory. For example, if you add decoder.py|js alongside the main script, you can import it like this:
Similarly, if you create a folder utils and add a file parser.py or parser.js inside it, the structure behaves like a subdirectory on your computer. To import from it, use:
This means you can treat the UbiFunction file structure like a local project folder.
Data and config files
UbiFunctions let you include data and configuration files, such as .json, .conf, .txt, and .csv, to provide inputs or settings for your functions. To read a file, handle it the same way you would in a local script:
Uploading files
To upload a file from your computer, click the + icon in the files pane, then select Upload file. To upload it into a folder, hover over the folder, click the three-dot menu, and select Upload file.
Binary files
You can upload binary files and read them from your code. For example, you can bundle a trained model and run it with the ML Inference runtime. The file reaches your function exactly as you uploaded it.
The following binary file types are supported:
Machine learning models
.tflite, .onnx, .pb, .pt, .pth, .h5, .hdf5, .gguf, .ggml, .safetensors
Data
.parquet, .feather, .arrow, .sqlite, .db, .bin, .dat
Documents
PDF, Word, Excel, and PowerPoint files
Media
Images (PNG, JPEG, GIF, WebP, BMP, TIFF, AVIF, ICO), audio (MP3, WAV, OGG, FLAC), and video (MP4, AVI, MKV, WebM)
Other
Fonts (TTF, OTF, WOFF, WOFF2), WebAssembly (.wasm), and archives (.zip, .gz, .bz2)
For security reasons, the following file types are blocked:
Pickle and NumPy files:
.pkl,.pickle,.npy,.npz. Loading these files can run arbitrary code. Export your model to ONNX instead. See Models trained in other frameworks.Executables and native libraries, such as
.exe,.dll,.so,.dylib,.jar,.msi,.deb, and.rpm.Shell and system scripts, such as
.sh,.bash,.zsh,.bat,.cmd,.ps1, and.vbs.
Binary files with other extensions are rejected. Each file can be up to 5 MB. See Specs and Limits for the limit on the function's total size.
To read a binary file, open it in binary mode:
Example
Suppose you have several device types on an LNS sending data continuously. For each uplink, you need to decode the payload and forward it to the corresponding device in Ubidots.
You can solve this with a UbiFunction that uses separate scripts for each device type and calls them from the main function.
For this example, create:
A folder called modules. Inside it, create:
A Python script called s2100.py. This is the decoder for the s2100 device.
A Python script called s210x.py. This is the decoder for the s210x device.
A Python script called utils.py. This file contains shared utility functions.
A configuration file called device_config.json that stores the configuration for each device type.
It should look like this:

The following are the contents of each script:
s2100.py script
s210x.py script
utils.py script
device_config.json
main.py
If you execute this UbiFunction with the following test payload:
It should output something like this:
Last updated
Was this helpful?