Skip to main content
Skip table of contents

Server-Side Python Mapping for Interfaces

Skeleton Classes

On the server side, interfaces map to skeleton classes. A skeleton is an abstract base class from which you derive your servant class and define a method for each operation on the corresponding interface. For example, consider our Slice definition for the Node interface:

SLICE
module Filesystem
{
    interface Node
    {
        idempotent string name();
    }
    // ...
}

The Python mapping generates the following definition for this interface:

PY
class Node(Ice.Object, ABC):
    @abstractmethod
    def name(self, current: Current) -> str | Awaitable[str]:
        pass

The important points to note here are:

  • As for the client side, Slice modules are mapped to Python packages with the same name, so the skeleton class definitions are part of the Filesystem package.

  • The name of the skeleton class is the same as the Slice interface (Node).

  • The skeleton class is an abstract base class with an abstract method for each operation defined in the Slice interface.

  • The skeleton class inherits from Ice.Object (which forms the root of the Ice object hierarchy).

Ice.Object Servant Base Class

The Slice pseudo-interface Object is mapped to the Ice.Object class in Python.

Servant Classes

In order to provide an implementation for an Ice object, you must create a servant class that inherits from the corresponding skeleton class. For example, to create a servant for the Node interface, you could write:

PY
from Filesystem import Node
import Ice

class MNode(Node):
    def __init__(self, name: str):
        self._name = name
      
    def name(self, _: Ice.Current) -> str:
        return self._name

Note that MNode implements Node, the skeleton class.

As far as Ice is concerned, the MNode class must implement only a single method: the abstract method name. This makes the servant class a concrete class that you can instantiate. You can add other methods and attributes as you see fit to support your implementation. For example, in the preceding definition, we added a _name instance attribute and an initializer.

JavaScript errors detected

Please note, these errors can depend on your browser setup.

If this problem persists, please contact our support.