This command permanently deletes the UbiFunction, just like removing it through the platform, thus special care is advised.
List all UbiFunctions
List all UbiFunctions on your account.
Local development
The Ubidots CLI enables you to set up a fully-featured local development environment for UbiFunctions, replicating runtimes and their included libraries. As specified in the Installing section, Docker is required for this.
Before starting with local UbiFunctions development, remember to run the ubidots config command in order to properly set the environment's required configuration.
Create a local UbiFunction
Create a new local UbiFunction with the given runtime, method and other settings.
UbiFunction directory structure
Upon creating an UbiFunction, a directory named after it will be created in the current one. This directory will the following:
main file
The main file is the entry point to the UbiFunction, that is, the starting point from where your logic will start to execute.
The main file is mandatory, otherwise the UbiFunction won't work properly.
manifest file
The .manifest.yaml contains all the required configuration for UbiFunction. It looks like this:
By editing this file, you can can manually change the UbiFunction's settings; however, it's recommended to use the designated options for each command to make changes.
Start the local development environment
Start the local development environment in order to enable the UbiFunction's execution.
This command must be executed from the local UbiFunction's directory.
After executing, this command will output the following:
The displayed URL is where the local UbiFunction is exposed.
Push a local UbiFunction
Push a local UbiFunction to Ubidots cloud.
This command must be executed from the local UbiFunction's directory.
After executing this command and if the UbiFunction doesn't exists yet in the Ubidots cloud, it will prompt you for creating it:
On the other hand, if the function already exists in Ubidots, it will promp you for overwriting:
Pull an UbiFunction from Ubidots
This command is helpful when you've pushed a local UbiFunction to Ubidots, made further changes there, and now want to pull those updates back to your local environment.
Use this command with caution, as it will overwrite your local UbiFunction. Be sure to run it from within the local UbiFunction's directory.
Example
Create the local UbiFunction
This example creates a local UbiFunction named my-first-function with runtime python3.9:lite. Run the following command:
It will output something like:
Navigate to the UbiFunction's directory and open the main.py file with your preferred text editor. In the main function, locate the following lines:
Then add the following line just below del args['device']
The code should now look like this:
Starting the UbiFunction
Now save the changes and go back to the terminal. Then run the following command to start the local UbiFunction:
The output of that command will look like:
The displayed URL is where the UbiFunction is exposed, thus you can perform HTTP request to it in order to trigger the UbiFunction's execution.
Running the UbiFunction
Perform an HTTP POST request to the given URL by running:
It shoud output the following:
You can confirm proper execution by going to your Ubidots account and checking if there's a new device called first-device-cli containing a variable called temperature holding a value of 78.
Pushing the UbiFunction to Ubidots
After runing locally your UbiFunction and determining it's working as intended, you can deploy it to your production environment (Ubidots) by running:
This will prompt you for overwriting the changes in Ubidots. Upon confirmation, the local changes will be pushed to Ubidots.
Pulling the UbiFunction from Ubidots
If you need to make changes to the UbiFunction's production version and want to edit it from your local machine, you can pull the changes from Ubidots, make the necessary modifications locally, and then push the updates back to Ubidots. Start by pulling the changes by running:
After that, you can use the start, run and push commands as described before.
Usage: ubidots functions add [OPTIONS] NAME
โญโ Arguments โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ name TEXT The name of the function. [required] โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
โญโ Options โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ --label TEXT The label for the โ
โ function. โ
โ --runtime [python3.9:lite|pytho The runtime for the โ
โ n3.9:base|python3.9:f function. โ
โ ull|python3.11:lite|p [default: โ
โ ython3.11:base|python nodejs20.x:lite] โ
โ 3.11:full|nodejs20.x: โ
โ lite|nodejs20.x:base] โ
โ --raw --no-raw Flag to determine if โ
โ the output should be โ
โ in raw format. โ
โ [default: no-raw] โ
โ --token TEXT Optional โ
โ authentication token โ
โ to invoke the โ
โ function. โ
โ --methods TEXT The HTTP methods the โ
โ function will respond โ
โ to. โ
โ [default: GET] โ
โ --cors --no-cors Flag to enable โ
โ Cross-Origin Resource โ
โ Sharing (CORS) for the โ
โ function. โ
โ [default: no-cors] โ
โ --cron TEXT Cron expression to โ
โ schedule the function โ
โ for periodic โ
โ execution. โ
โ [default: * * * * *] โ
โ --environment TEXT environment in JSON โ
โ format. โ
โ [default: []] โ
โ --help Show this message and โ
โ exit. โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
Usage: ubidots functions get [OPTIONS]
โญโ Options โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ --id TEXT Unique identifier for the function. If both id โ and label are provided, the id takes precedence. โ
โ --label TEXT Descriptive label identifier for the function.
โ Ignored if id is provided. โ
โ --fields TEXT Comma-separated fields to process. e.g. โ
โ field1,field2,field3 โ
โ [default: id,label,name] โ
โ --help Show this message and exit. โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
Usage: ubidots functions update [OPTIONS]
โญโ Options โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ --id TEXT Unique identifier for the โ
โ function. If both id and label โ are provided, the id takes โ
โ precedence. โ
โ --label TEXT Descriptive label โ
โ identifier for the โ
โ function. Ignored if id is
โ provided. โ
โ --new-label TEXT The label for the device. โ
โ --new-name TEXT The name of the device. โ
โ --runtime [python3.9:lite|python3.9:bas The runtime for the function. โ
โ e|python3.9:full|python3.11:l [default: nodejs20.x:lite] โ
โ ite|python3.11:base|python3.1 โ
โ 1:full|nodejs20.x:lite|nodejs โ
โ 20.x:base] โ
โ --raw --no-raw Flag to determine if the โ
โ output should be in raw โ
โ format. โ
โ [default: no-raw] โ
โ --token TEXT Optional authentication token โ
โ to invoke the function. โ
โ --methods TEXT The HTTP methods the function โ
โ will respond to. โ
โ [default: GET] โ
โ --cors --no-cors Flag to enable Cross-Origin โ
โ Resource Sharing (CORS) for โ
โ the function. โ
โ [default: no-cors] โ
โ --cron TEXT Cron expression to schedule โ
โ the function for periodic โ
โ execution. โ
โ [default: * * * * *] โ
โ --environment TEXT environment in JSON format. โ
โ [default: []] โ
โ --help Show this message and exit. โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
Usage: ubidots functions delete [OPTIONS]
โญโ Options โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ --id TEXT Unique identifier for the function. If both id and label are
โ provided, the id takes precedence. โ
โ --label TEXT Descriptive label **identifier** for the function. Ignored if id is โ
โ provided. โ
โ --help Show this message and exit. โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
Usage: ubidots functions list [OPTIONS]
โญโ Options โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ --fields TEXT Comma-separated fields to process * e.g. field1,field2,field3. * โ
โ Available fields: (url, id, label, name, isActive, createdAt, โ
โ serverless, triggers, environment, zipFileProperties). โ
โ [default: id,label,name] โ
โ --filter TEXT Filter results by attributes. e.g. โ
โ 'key1=val1&key2__in=val20,val21' or โ
โ key1=val1\&key2__in=val20,val21 โ
โ --sort-by TEXT Attribute to sort the result set by. โ
โ --page-size INTEGER Defines the page number to be retrieved. โ
โ --page INTEGER Defines how many items per page are retrieved. โ
โ --format [table|json] [default: table] โ
โ --help Show this message and exit. โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
Usage: ubidots functions new [OPTIONS]
โญโ Options โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ --name TEXT The name of the project folder. โ
โ [default: my_function] โ
โ --runtime [python3.9:lite|python3.9:base|python3.9:f The runtime for the function. โ
โ ull|python3.11:lite|python3.11:base|python [default: nodejs20.x:lite] โ
โ 3.11:full|nodejs20.x:lite|nodejs20.x:base] โ
โ --cors --no-cors Flag to enable Cross-Origin Resource โ
โ Sharing (CORS) for the function. โ
โ [default: no-cors] โ
โ --cron TEXT Cron expression to schedule the function โ
โ for periodic execution. โ
โ [default: * * * * *] โ
โ --methods TEXT The HTTP methods the function will respond โ
โ to. โ
โ [default: GET] โ
โ --raw --no-raw Flag to determine if the output should be โ
โ in raw format. โ
โ [default: no-raw] โ
โ --interactive -i Enable interactive mode to select options โ
โ through prompts. โ
โ --verbose -v Enable verbose output. โ
โ --help Show this message and exit. โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
Usage: ubidots functions start [OPTIONS]
Initialize the function container environment for execution.
โญโ Options โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ --cors --no-cors Flag to enable Cross-Origin Resource Sharing (CORS) for the function. โ
โ [default: no-cors] โ
โ --cron TEXT Cron expression to schedule the function for periodic execution. โ
โ [default: * * * * *] โ
โ --methods TEXT The HTTP methods the function will respond to. [default: GET] โ
โ --raw --no-raw Flag to determine if the output should be in raw format. [default: no-raw] โ
โ --timeout INTEGER Maximum time (in seconds) the function is allowed to run before being terminated. โ
โ [max: 300] โ
โ [default: 10] โ
โ --token TEXT Optional authentication token to invoke the function. โ
โ --verbose -v Enable verbose output. โ
โ --help Show this message and exit. โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
------------------
Starting Function:
------------------
Name: prueba-python-push
Runtime: python3.9:base
Local label: lambda_fn_prueba-python-push_Bk2L4H5bKp
-------
INPUTS:
-------
Raw: False
Methods: GET
Token:
http://172.18.0.2:8042/lambda_fn_prueba-python-push_Bk2L4H5bKp
> [DONE]: Function started successfully.
Usage: ubidots functions push [OPTIONS]
Update and synchronize your local function code with the remote server.
โญโ Options โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ --yes -y Confirm file overwrite without prompt. โ
โ --verbose -v Enable verbose output. โ
โ --help Show this message and exit. โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
This function is not created. Would you like to create a new function and push it? [y/N]: y
> [DONE]: Function uploaded successfully.
Are you sure you want to overwrite the remote files? [y/N]: y
> [DONE]: Function uploaded successfully.
Usage: ubidots functions pull [OPTIONS]
Retrieve and update your local function code with the latest changes from the
remote server.
โญโ Options โโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฎ
โ --yes -y Confirm file overwrite without prompt. โ
โ --verbose -v Enable verbose output. โ
โ --help Show this message and exit. โ
โฐโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโโฏ
ubidots functions new --name my-first-function --runtime python3.9:base
ubidots functions new --name my-first-function --runtime python3.9:lite
> [DONE]: Project 'my-first-function' created in '/home/inumaki/test-cli/my-first-function'.
if token is None or device is None:
print("[ERROR] Please send your Ubidots Token and device label to update in your args")
return {"status": "error"}
del args['token']
del args['device']
del args['_auth_token']
if token is None or device is None:
print("[ERROR] Please send your Ubidots Token and device label to update in your args")
return {"status": "error"}
del args['token']
del args['device']
del args['_auth_token']
ubidots functions start --methods POST
------------------
Starting Function:
------------------
Name: my-first-function
Runtime: python3.9:base
Local label: lambda_fn_my-first-function_OWWTAWxPGi
-------
INPUTS:
-------
Raw: False
Methods: POST
Token:
URL: http://172.18.0.2:8042/lambda_fn_my-first-function_OWWTAWxPGi
> [DONE]: Function started successfully.