Skip to main content

Custom Functions

You can create your own functions and then call them inside our NoCode table, just like a built-in function. Here is a guide on how to write, deploy and call these functions. Under the hood, we use AWS Lambda at the moment to run our custom functions so many of these steps might seem familiar to you.

Code

You can write a function for our platform in python (3.8), nodejs (16.x) and go (1.x).

Priceloop-CLI

The easiest way to deploy our custom functions is to use our CLI. Let’s install it via npm:

npm install -g @priceloop/cli

Python

We recommend to create a Python environment first by using virtualenv or conda:

conda create -n my_example python=3.8
source activate my_example

Then create a folder my_example with a file called function.py.

my_example
├── function.py

The function.py should contain something like this:

# event = {'BatchedArgs': [['<col1>', '<col2>'], ['<col1>', '<col2>'], 'Authentication': {'AmazonSellerPartnerRefreshToken': '***'}}
def handler(event, context):
return list(map(lambda row: "Hello " + row[0], event["BatchedArgs"]))

⚠️ You can also have custom dependencies in your function. Just add a requirements.txt file for your dependencies in the same directory. Our CLI will take care of this as well. If you need to use numpy or pandas, you should use the runtime python_numpy or python_pandas instead of python in the CLI when you are creating the custom function.

Now let’s login and then create the function via the CLI:

priceloop login-credentials --username "nocode_username" --password "nocode_password"
priceloop create-external-function --function "my_example" --runtime "python" --return-type "string" --parameter-types "string"

Once we have it we can deploy the function:

priceloop update-external-function --function "my_example" --directory "my_example"

Usage

After these steps, your new function will be available inside the specified workspace in NoCode.

Go to the app, create a new column and add a new formula: \my_example('World'). It should return “Hello World”.

Alternative way to deploy our custom function

Create a function.py like above and create a zip file containing this python file:

zip app.zip function.py

This app package is now ready to be deployed to NoCode.

Dependencies

To have custom dependencies in your function, just add a requirements.txt file for your dependencies in the same directory. Then install them in the current directory:

pip install --target . -r requirements.txt

Then create your app package including all requirements:

zip app.zip -r .

API

Check out our API Docs for NoCode: https://api.alpha.priceloop.ai/.

It also contains all the information for creating/updating/deleting custom functions.

Register Function

Let’s first register a new function with a name and a signature, i.e. return and parameter types.

You can do it like this on the command line (see API Docs):

curl -X POST \
-H 'Authorization: Bearer <xxx>' \
'https://api.alpha.priceloop.ai/api/v1.0/workspaces/<my-workspace>/external-functions/my_example?runtime=python&returnType=string&paramType=string'

This request will return a URL. You can upload your function code to this URL like this:

curl -X PUT -T app.zip '<url>'

Update Function Code

You can always update your function code:

curl -X PUT \
-H 'Authorization: Bearer <xxx>' \
'https://api.alpha.priceloop.ai/api/v1.0/workspaces/<my-workspace>/external-functions/my_example?runtime=python&returnType=string&paramType=string'

Then you get back a URL again to upload your code just like before. After the update, existing formulas with this function will lazily be recalculated for you.