Skip to content

Service initialization

Please read our concept of services first before developing one.

A service can be used to create:

  • API endpoints
  • Internal functionality to use in other services or states
  • Cronjobs
  • Directoryperseus
    • Directoryservices
      • Directorycustom/ Directory for custom services
        • __init__.py
        • Template.py Tip: Use the template to speed up the process
      • __init__.py
      • BaseService.py Base service (parent class) for a custom service
  1. Add a new file

    Start by adding a new file to your custom service directory and name it like you want, for example MyService.py.

    custom/MyService.py
    from typing import Any
    from ..BaseService import BaseService
    class Template(BaseService):
    @classmethod
    def initialize(cls):
    ...
    @classmethod
    def handle_get(cls, path: str, **kwargs) -> dict[str, Any]:
    ...
    @classmethod
    def handle_post(cls, path: str, **kwargs) -> dict[str, Any]:
    ...
    @classmethod
    def handle_delete(cls, path: str, **kwargs) -> dict[str, Any]:
    ...

    All methods will be explained in the step-by-step guide.

  2. Register custom service

    To allow PERSEUS to use the service you will have to import it to the __init__.py file in the custom service directory. To do this, add the following line to that file:

    custom/__init__.py
    from .MyService import MyService

The class method initialize() will be executed when PERSEUS is starting up.

  1. Add permissions

    First, you need to set the permissions for the new service by using its add_permission() method. Add all roles that should have access to this service. You can view a list of all roles here.

    custom/MyService.py
    from ..BaseService import BaseService
    from perseus.security import CoreRoleName
    class MyService(BaseService):
    @classmethod
    def initialize(cls):
    MyService.add_permission(CoreRoleName.OWNER)
    MyService.add_permission(CoreRoleName.SUPPORT_L1)
  2. Add a frontend menu item

Next, let’s create some API endpoints.