Skip to content

Templates for running Altair® IoT Studio™ functions locally using Python and Go

Notifications You must be signed in to change notification settings

altairengineering/iot-functions-sdk

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

1 Commit
 
 
 
 
 
 
 
 
 
 
 
 

Repository files navigation

Altair IoT Studio Local Development Templates

This repository provides templates for running serverless functions in Altair® IoT Studio™ using Python and Go. These templates allow users to run functions locally just as they would on IoT Studio, enabling the use of their preferred IDE, debugging, and rapid iteration.

Python Function Template

Prerequisites

  • Python 3.10+

Installation

To set up the environment, run the following command (if you are using the Makefile):

make install-python

Alternatively, you can run the following commands to install the dependencies (make sure you have Python 3.10+ installed):

cd python3-http
python3 -m venv env
source env/bin/activate    # (in Windows, use env\Scripts\activate)
pip install -r requirements.txt

This will create a Python environment in the python3-http/env directory and install the required dependencies.

Additional libraries

If your function requires additional libraries, you can add them to the requirements.txt file. After adding the libraries, run the installation command again.

Note: Add only libraries (and exact versions) that are supported by IoT Studio or you could face issues when deploying the function. You can check the supported libraries in the IoT Studio documentation.

Editing the Code

Edit the code in the python3-http/function/handler.py file. This is where the main logic for the Python function resides.

Running the Function

To run the function locally, use the following command:

make run-python

If you are not using the Makefile, you can run the following command:

cd python3-http
export _SECRETS_PATH=../variables   # (in Windows, use set _SECRETS_PATH=..\variables)
python index.py

The function will start a local server at http://localhost:8082 that you can use to test the function.

Go Function Template

Prerequisites

  • Go 1.19+

Installation

To set up the environment, run the following command (if you are using the Makefile):

make install-go

Alternatively, you can run the following commands to install the dependencies (make sure you have Go 1.19+ installed):

cd golang-http
go mod tidy

Additional libraries

If your function requires additional libraries, you can add them to the go.mod file. After adding the libraries, run the installation command again.

Note: Add only libraries (and exact versions) that are supported by IoT Studio or you could face issues when deploying the function. You can check the supported libraries in the IoT Studio documentation.

Editing the Code

Edit the code in the golang-http/function/handler.go file. This is where the main logic for the Go function resides.

Running the Function

To run the function locally, use the following command:

make run-go

If you are not using the Makefile, you can run the following command:

cd golang-http
export _SECRETS_PATH=../variables   # (in Windows, use set _SECRETS_PATH=..\variables)
go run .

The function will start a local server at http://localhost:8082 that you can use to test the function.

Variables

To use Variables locally as you would in IoT Studio, modify the variables/function-variables file to include the Variables your Function needs, with the same values and types as defined in IoT Studio.

The make commands will automatically set up the functions so that they can access Variables from this file. If you don't want to use the make commands, you can set the _SECRETS_PATH environment variable to the path of the function-variables file (e.g., export _SECRETS_PATH=variables/function-variables).

About this repository

Directory Structure

The repository contains the following directories:

  • python3-http/: Contains the Python function template.
  • golang-http/: Contains the Go function template.

Makefile Targets

Use the Makefile targets to easily set up the environment and develop and test your functions locally before deploying them to Altair IoT Studio. The Makefile contains the following targets:

  • install-python: Sets up the Python environment and installs dependencies.
  • install-go: Sets up the Go environment and installs dependencies.
  • run-python: Runs the Python function locally.
  • run-go: Runs the Go function locally.

📖 Documentation

Please refer to the IoT Studio documentation for more information on using these templates.

About

Templates for running Altair® IoT Studio™ functions locally using Python and Go

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published