Skip to content

Creating a Kelvin App

The following commands require a session

Check the Quickstart guide on how to login.

Creating a Kelvin App

Apps are created with the kelvin app create command.

  • This command takes the following arguments:
    • app-name, the name of the app to be created.

Info

The app-name must meet the following criteria (Letters, Numbers, no spaces, no special characters except for '-')

  • And the following options:
    • --app-type, 'kelvin', 'bridge' or 'docker', the type of the application to be created. Kelvin by default.
    • --flavour, 'default' or 'pubsub', the base template for the application. 'pubsub' is only available for kelvin apps.

Flavours

The application flavour defines the template for the python source code.

  • default, the main template for kelvin apps, it controls the application lifecycle, and the user only needs to handle the incoming data.
  • pubsub, the kelvin-sdk-pubsub template where the user controls the app's lifecycle. The data handlers are managed by the user using the pubsub library.

To consult the available app languages, and app types, check the Choose an application type and What is a Kelvin App.

Creating an app

# kelvin app create app-name --app-type=<app_type> --flavour=<flavour>
kelvin app create my-app

The apps' creation output:

[kelvin.sdk][2021-01-11 18:49:05][I] Creating new application "my-app"                                                                                                                                                                                    
[kelvin.sdk][2021-01-11 18:49:05][I] Retrieving the latest schema version                                                                                                                                                                                 
[kelvin.sdk][2021-01-11 18:49:11][R] Successfully created new application: "my-app".                                                                                                                                                                      

    Continue its configuration using "studio". Refer to "kelvin studio --help" for more information.

Application Structure

The application tree has the following structure:

.                                                                                                                                                                                                                                                         
├── .dockerignore                                                                                                                                                                                                                                              
├── .gitignore                                                                                                                                                                                                                                         
├── app.yaml                                                                                                                                                                                                                                              
├── build/                                                                                                                                                                                                                                                 
├── data/                                                                                                                                                                                                                                                  
├── datatype/                                                                                                                                                                                                                                             
├── docs/                                                                                                                                                                                                                                                  
├── my_app/                                                                                                                                                                                                                                                
    ├── __init__.py                                                                                                                                                                                                                                       
    └── my_app.py                                                                                                                                                                                                                                         
├── requirements.txt                                                                                                                                                                                                                                               
├── setup.py                                                                                                                                                                                                                                              
├── tests/                                                                                                                                                                                                                                                 
    ├── __init__.py                                                                                                                                                                                                                                       
    └── test_application.py                                                                                                                                                                                                                                
└── wheels/            

Its source code will be included as:

from kelvin.app import DataApplication

class App(DataApplication):
    """Application."""

    def init(self) -> None:
        """
        Initialization method
        """
        # 1 - To access the complete application configuration file, i.e. the contents of the 'app.yaml':
        # self.app_configuration

        # 2 - To access the inputs and outputs, respectively:
        # self.interface.inputs
        # and
        # self.interface.outputs
        self.logger.info("Initialising")

    def process(self) -> None:
        """Process data."""
        # 1 - To access the input data:
        # self.data

        # 2 - Considering your data is defined in the inputs as 'my_var', you can access it with:
        # my_var = self.data.my_var
        # or
        # my_var = self.data.get('my_var')

        # 3 - Build a message to emit:
        self.logger.info("Data", data=self.data)
        message = self.make_message(
            "raw.float32",
            name="my_new_var",
            value=1.0,
            time_of_validity=int(1 * 1e9),
            emit=False
        )

        # 4 - Emit the message
        # self.emit(message)

Structure in detail

Source code

  • The my-app directory hosts all source code and package defining files. This is the code that is going to be executed.

Configuration Files

  • The app.yaml is the configuration file where all the app details and configurations will be specified.

Setup files

  • The requirements.txt is a python-only file that allows the specification of python packages as dependencies.
  • The setup.py is a python-only file that allows the apps to also be interpreted as a python project and ultimately packaged as a dependency.