# Service

Services are the heart of RPyC: each side of the connection exposes a service, which define the capabilities available to the other side.

Note that the services by both parties need not be symmetric, e.g., one side may exposed service A, while the other may expose service B. As long as the two can interoperate, you’re good to go.

class `rpyc.core.service.``Service`(conn)

  The service base-class. Derive from this class to implement custom RPyC services:

  - The name of the class implementing the `Foo` service should match the pattern `FooService` (suffixed by the word ‘Service’)

        class FooService(Service):
            pass

        FooService.get_service_name() # 'FOO'
        FooService.get_service_aliases() # ['FOO']

  - To supply a different name or aliases, use the `ALIASES` class attribute

        class Foobar(Service):
            ALIASES = ["foo", "bar", "lalaland"]

        Foobar.get_service_name() # 'FOO'
        Foobar.get_service_aliases() # ['FOO', 'BAR', 'LALALAND']

  - Override `on_connect()` to perform custom initialization

  - Override `on_disconnect()` to perform custom finalization

  - To add exposed methods or attributes, simply define them normally, but prefix their name by `exposed_`, e.g.

        class FooService(Service):
            def exposed_add(self, x, y):
                return x + y

  - All other names (not prefixed by `exposed_`) are local (not accessible to the other party)

  Note

  You can override `_rpyc_getattr`, `_rpyc_setattr` and `_rpyc_delattr` to change attribute lookup – but beware of possible security implications!

  `on_connect`()

    called when the connection is established

  `on_disconnect`()

    called when the connection had already terminated for cleanup (must not perform any IO on the connection)

  classmethod `get_service_aliases`()

    returns a list of the aliases of this service

  classmethod `get_service_name`()

    returns the canonical name of the service (which is its first alias)

  classmethod `exposed_get_service_aliases`()

    returns a list of the aliases of this service

  classmethod `exposed_get_service_name`()

    returns the canonical name of the service (which is its first alias)

class `rpyc.core.service.``VoidService`(conn)

  void service - an do-nothing service

class `rpyc.core.service.``ModuleNamespace`(getmodule)

  used by the `SlaveService` to implement the magical ‘module namespace’

class `rpyc.core.service.``SlaveService`(conn)

  The SlaveService allows the other side to perform arbitrary imports and execution arbitrary code on the server. This is provided for compatibility with the classic RPyC (2.6) modus operandi.

  This service is very useful in local, secure networks, but it exposes a major security risk otherwise.

  `exposed_execute`(text)

    execute arbitrary code (using `exec`)

  `exposed_eval`(text)

    evaluate arbitrary code (using `eval`)

  `exposed_getmodule`(name)

    imports an arbitrary module

  `exposed_getconn`()

    returns the local connection instance to the other side