Skip to content

Installing the SDK

We've streamlined everything, so you don't have too.

Installation

We support a wide range of languages - find your language to get started with our SDK.

The JellyFaaS SDK Python package is available on PyPI:

pip install jellyfaas

The JellyFaaS SDK Node package is available on NPM:

npm install jellyfaas

Information

Java, Go, .Dotnet (including GODOT/Unity support) SDK's are coming soon

Quick Start

The JellyFaaS SDK simplifies working with the JellyFaaS API. It primarily provides a Client class which handles authentication and functions to simplify creating HTTP requests to the API.

API Credits

The cloud functions used in the examples below will not use your credits. Visit your profile page to get a secret key.

Below are some plug-and-play examples.

Get started with this easy python file.

main.py

import os
from  jellyfaas import Config, Client

query_params = {
    "rating": "PG",
    "score": "5.8"
}

config = Config(api_key="<JELLYFAAS_SECRET>")
client, result = Client(config).lookup_function("suggestmovie").set_function_query_params(query_params).invoke()

print(result.json())
More Info - Verbose Example

The above code example demonstrates how the entire JellyFaaS function calling workflow can be condensed down into a succinct one-liner. Of course, you may prefer a more a clear and verbose approach. The following code example demonstrates how you can improve code-clarity by expanding out this process.

import os
import logging
import jellyfaas

logging.basicConfig(level=logging.DEBUG) # When enabled, JellyFaaS logs at the DEBUG level

# It is usually recommended to set up your Secret key as an environment variable.
api_key = os.getenv("<JELLYFAAS_SECRET>")

# Initialize the client config with debug logs enabled
config = jellyfaas.Config(api_key=api_key, debug=True)

# Initialize the client. 
# Once you have an authenticated Client, you can reuse it for multiple lookups/invocations.
client = jellyfaas.Client(config)

# Lookup a function
client.lookup_function("helloworld")

# Set the request query params and JSON body (via a python dictionary)
# Once you've done this once, you can call `invoke()` on the client as many times as you want.
client.set_function_query_params(     # Set query parameters
    {"name": "tim"}                   
)
client.set_function_body(                    # Set request body
    {"order": ["ham", "jam", "spam"]} 
)

# Finally, call the cloud function
_, response = client.invoke()

print(response.content)
# Output: "Hello, Tim. You ordered 'ham', 'jam', and 'spam'."

Get started with this easy node.js file.

index.js

const {Config, Client} = require('jellyfaas')

query_params = {
    "rating": "PG",
    "score": "5.8"
}

new Config("<JELLYFAAS_SECRET>").then(config => {  // Construct Config
    new Client(config)                               // Construct Client
    .lookupFunction("suggestmovie").then(client => { // Lookup function
        client.setFunctionQueryParams(query_params)  // Set query params
        .invoke(null, false).then(resp => {          // invoke (overriding validation)
            console.log(resp)
        })
    })
})
More Info - Usage in Async Function

Depending on your use case, you may prefer to invoke functions from within an asynchronous function. See below for reference.

const {Config, Client} = require('jellyfaas')

query_params = {
    "rating": "PG",
    "score": "5.8"
}

async function run() {
    let config = await new Config("<JELLYFAAS_SECRET>") // Construct Config
    let client = await new Client(config)                 // Construct Client
    await client.lookupFunction("suggestmovie")           // Lookup function
    client.setFunctionQueryParams(query_params)           // Set query params
    let resp = await client.invoke(null, false)           // invoke (overriding validation)

    console.log(resp)        
}

run()

Next Steps