Generate a SiLA Server/Client package

Use the command sila2-codegen new-package to generate a SiLA Server/Client Python package.

Arguments (excerpt):

  • --package-name: Name of the generated Python package (required, must be a valid Python identifier)

  • --output-dir: Output directory (default: current directory)

  • feature_definitions: Feature definition files of the features you want to implement (.sila.xml files, optional)


Let’s build a SiLA Server which implements the GreetingProvider example feature.

1. Create the package

  1. Create a new directory and open it in a terminal

  2. If not done already: Install the sila2 library by running pip install sila2 (required Python >= 3.8)

  3. Download the feature definition file into this directory: GreetingProvider-v1_0.sila.xml

  4. Generate the package by running sila2-codegen new-package --package-name my_sila2_package GreetingProvider-v1_0.sila.xml

Your current directory should now contain the following files and sub-directories:

├── GreetingProvider-v1_0.sila.xml
├── my_sila2_package
│   ├── feature_implementations
│   │   ├──
│   │   └── ...
│   ├── generated
│   │   ├── greetingprovider
│   │   │   └── ...
│   │   └── ...
│   ├──
│   └── ...
└── pyproject.toml

You can safely remove the file GreetingProvider-v1_0.sila.xml, it was copied to the generated package files.

  • The file pyproject.toml is required for installing the generated package

  • The package code itself is located in the my_sila2_package directory

  • The file defined the SiLA Server

  • The directory generated/greetingprovider contains multiple files required for implementing the GreetingProvider feature

  • The file feature_implementations/ is where you implement the feature

2. Set server information

Open the file It contains a class Server:

class Server(SilaServer):
    def __init__(self, server_uuid: Optional[UUID] = None):
        # TODO: fill in your server information

Replace the server name, type, version, description and vendor URL with appropriate values. This information will be available to all connected clients.

The default values ("TODO", …) are valid values for these fields, so if you are just experimenting with the SDK, you don’t need to do this.

3. Implement the GreetingProvider feature

The GreetingProvider feature defines the command SayHello and the property StartYear:

  • SayHello expects a String parameter “Name” and returns the String “Greeting”

  • StartYear returns the year when the SiLA Server has been started

To implement the feature, open the file my_sila2_package/feature_implementations/

It contains a few imports and the following class:

class GreetingProviderImpl(GreetingProviderBase):
    def get_StartYear(self, *, metadata: Dict[FullyQualifiedIdentifier, Any]) -> int:
        raise NotImplementedError  # TODO

    def SayHello(self, Name: str, *, metadata: Dict[FullyQualifiedIdentifier, Any]) -> SayHello_Responses:
        raise NotImplementedError  # TODO

We can ignore the metadata arguments for now. See Implementing SiLA features for instructions on how to work with SiLA Client Metadata.

To implement the StartYear property, the method get_StartYear must return an int. You can simply replace raise NotImplementedError  # TODO with return 2022.

The command SayHello is specified to return a SayHello_Responses object. That class is imported from the file my_sila2_package/generated/greetingprovider/greetingprovider_types, where it is defined like this:

class SayHello_Responses(NamedTuple):
    Greeting: str

The parameter Name is given as a str object. Replace raise NotImplementedError  # TODO with return SayHello_Responses(Greeting="Hello " + Name).

Congratulations, you have now implemented a the GreetingProvider feature and can start the server.