# 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

  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(conn)

    called when the connection is established

  on_disconnect(conn)

    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

  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

  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.

  on_connect(conn)

    called when the connection is established

class rpyc.core.service.FakeSlaveService

  VoidService that can be used for connecting to peers that operate a `MasterService`, `ClassicService`, or the old `SlaveService` (pre v3.5) without exposing any functionality to them.

class rpyc.core.service.MasterService

  Peer for a new-style (>=v3.5) `SlaveService`. Use this service if you want to connect to a `SlaveService` without exposing any functionality to them.

  on_connect(conn)

    called when the connection is established

class rpyc.core.service.ClassicService

  Full duplex master/slave service, i.e. both parties have full control over the other. Must be used by both parties.

class rpyc.core.service.ClassicClient

  MasterService that can be used for connecting to peers that operate a `MasterService`, `ClassicService` without exposing any functionality to them.