Remote Python Call (RPyC) is a transparent and symmetric distributed computing library
npx @tessl/cli install tessl/pypi-rpyc@5.3.0Remote Python Call (RPyC) is a transparent and symmetric distributed computing library that enables distributed computing across processes and computers. It uses object-proxying techniques to leverage Python's dynamic nature, allowing remote objects to be manipulated as if they were local.
pip install rpycimport rpycCommon patterns for different use cases:
# For general connections
from rpyc import connect, connect_by_service, ssl_connect
# For classic mode
from rpyc import classic
# For services
from rpyc import Service, exposed
# For servers
from rpyc.utils.server import ThreadedServer, ThreadPoolServer, ForkingServer
# For registry and discovery
from rpyc.utils.registry import UDPRegistryServer, UDPRegistryClient
# For authentication
from rpyc.utils.authenticators import SSLAuthenticator
# For streams and channels
from rpyc.core import SocketStream, Channelimport rpyc
# Connect to an RPyC server
conn = rpyc.connect('hostname', 12345)
# Access remote objects through the root namespace
result = conn.root.some_remote_function('argument')
# Close the connection
conn.close()import rpyc
# Connect in classic mode for direct Python execution
conn = rpyc.classic.connect('hostname')
# Execute Python code remotely
conn.execute('x = 5 + 3')
# Evaluate expressions
result = conn.eval('x * 2') # Returns 16
# Access remote modules
files = conn.modules.os.listdir('/tmp')
# Access remote builtins
remote_file = conn.builtin.open('/path/to/file', 'r')
content = remote_file.read()
conn.close()import rpyc
from rpyc import exposed
class MyService(rpyc.Service):
@exposed
def get_data(self, key):
return f"Data for {key}"
@exposed
def process_list(self, items):
return [item.upper() for item in items]
# Run a server with the service
from rpyc.utils.server import ThreadedServer
server = ThreadedServer(MyService, port=12345)
server.start()RPyC's architecture is built around several key components:
The symmetric design means both sides of a connection can expose services to each other, enabling bidirectional remote procedure calls and distributed computing patterns.
Core connection functionality including TCP, SSL, Unix socket, SSH tunnel, subprocess, and service discovery connections. These functions provide the primary ways to establish RPyC connections.
def connect(host, port, service=VoidService, config={}, ipv6=False, keepalive=False): ...
def ssl_connect(host, port, keyfile=None, certfile=None, ca_certs=None, **kwargs): ...
def connect_by_service(service_name, host=None, registrar=None, timeout=2, **kwargs): ...
def discover(service_name, host=None, registrar=None, timeout=2): ...Connection and Factory Functions
Service classes for defining remote interfaces and protocol management for handling connections. Includes base service classes, specialized service types, and connection management.
class Service: ...
class VoidService(Service): ...
class SlaveService(Service): ...
class MasterService(Service): ...
class ClassicService(MasterService, SlaveService): ...
class Connection: ...Classic RPyC functionality providing direct remote Python execution, module access, and file transfer capabilities. This mode allows transparent remote code execution and filesystem operations.
def connect(host, port=18812, ipv6=False, keepalive=False): ...
def execute(code): ...
def eval(expression): ...
def upload(conn, localpath, remotepath, filter=None, **kwargs): ...
def download(conn, remotepath, localpath, filter=None, **kwargs): ...Multi-threaded, forking, and specialized server implementations for hosting RPyC services. Includes configuration options for different deployment scenarios.
class ThreadedServer(Server): ...
class ThreadPoolServer(Server): ...
class ForkingServer(Server): ...
class OneShotServer(Server): ...Additional utilities including asynchronous operations, timeouts, background threads, decorators, and low-level helpers for advanced RPyC usage.
def async_(proxy): ...
def timed(timeout, func): ...
class BgServingThread: ...
def exposed(func): ...
def restricted(obj, attrs, wattrs=None): ...Service registry and discovery system for automatic service location and management. Enables services to advertise availability and clients to discover services by name.
class UDPRegistryServer: ...
class TCPRegistryServer: ...
class UDPRegistryClient: ...
class TCPRegistryClient: ...
def discover(service_name): ...
def list_services(): ...Registry and Service Discovery
Authentication mechanisms and security features for securing RPyC connections and services. Includes SSL/TLS authentication, custom authenticators, and security configuration.
class SSLAuthenticator: ...
class Authenticator: ...
def create_secure_config(): ...
def restricted_service(): ...Command-line utilities for running RPyC servers and registries. Ready-to-use server implementations and registry services for deployment without custom code.
# Command-line tools:
# rpyc_classic [OPTIONS] - Classic RPyC server
# rpyc_registry [OPTIONS] - Registry server
# Server modes: stdio, threaded, forking, oneshot
# Registry modes: UDP, TCPLow-level transport mechanisms and communication channels for RPyC connections. Provides underlying transport layer for different communication methods.
class SocketStream: ...
class TunneledSocketStream: ...
class PipeStream: ...
class Channel: ...
class CompressedChannel: ...class BaseNetref:
"""Base class for network references (remote object proxies)"""
class AsyncResult:
"""Container for asynchronous operation results"""
def ready(self) -> bool: ...
def wait(self, timeout=None): ...
def value(self): ...
class AsyncResultTimeout(Exception):
"""Raised when async operations timeout"""
class GenericException(Exception):
"""Wrapper for remote exceptions"""
# Stream and Channel classes
class SocketStream: ...
class TunneledSocketStream: ...
class PipeStream: ...
class Channel: ...
class CompressedChannel: ...
class EncryptedChannel: ...
# Registry classes
class UDPRegistryServer: ...
class TCPRegistryServer: ...
class UDPRegistryClient: ...
class TCPRegistryClient: ...
# Authentication classes
class SSLAuthenticator: ...
class AuthenticationError(Exception): ...
# Configuration constants
DEFAULT_CONFIG: dict
SECURE_DEFAULT_CONFIG: dict
REGISTRY_PORT: int
DEFAULT_SSL_PORT: int