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[source]
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 patternFooService
(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 attributeclass Foobar(Service): ALIASES = ["foo", "bar", "lalaland"] Foobar.get_service_name() # 'FOO' Foobar.get_service_aliases() # ['FOO', 'BAR', 'LALALAND']
Override
on_connect()
to perform custom initializationOverride
on_disconnect()
to perform custom finalizationTo 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_disconnect(conn)[source]
called when the connection had already terminated for cleanup (must not perform any IO on the connection)
- classmethod get_service_name()[source]
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.ModuleNamespace(getmodule)[source]
used by the
SlaveService
to implement the magical ‘module namespace’
- class rpyc.core.service.SlaveService[source]
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.
- class rpyc.core.service.FakeSlaveService[source]
VoidService that can be used for connecting to peers that operate a
MasterService
,ClassicService
, or the oldSlaveService
(pre v3.5) without exposing any functionality to them.
- class rpyc.core.service.MasterService[source]
Peer for a new-style (>=v3.5)
SlaveService
. Use this service if you want to connect to aSlaveService
without exposing any functionality to them.
- class rpyc.core.service.ClassicService[source]
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[source]
MasterService that can be used for connecting to peers that operate a
MasterService
,ClassicService
without exposing any functionality to them.