CtrlK
BlogDocsLog inGet started
Tessl Logo

tessl/pypi-rpyc

Remote Python Call (RPyC) is a transparent and symmetric distributed computing library

Pending
Overview
Eval results
Files

connection-factory.mddocs/

Connection and Factory Functions

Core connection functionality providing multiple ways to establish RPyC connections including TCP, SSL, Unix sockets, SSH tunnels, subprocesses, and service discovery. These functions form the foundation for all RPyC distributed computing operations.

Capabilities

TCP Connections

Standard TCP socket connections for network-based RPyC communication.

def connect(host, port, service=VoidService, config={}, ipv6=False, keepalive=False):
    """
    Connects to an RPyC server over TCP.
    
    Parameters:
    - host (str): Server hostname or IP address
    - port (int): Server port number  
    - service (Service): Local service to expose (default VoidService)
    - config (dict): Configuration dictionary
    - ipv6 (bool): Use IPv6 if True
    - keepalive (bool): Enable TCP keepalive
    
    Returns:
    Connection: RPyC connection object
    """

SSL/TLS Connections

Secure connections using SSL/TLS encryption for protected communication.

def ssl_connect(host, port, keyfile=None, certfile=None, ca_certs=None, 
               cert_reqs=None, ssl_version=None, ciphers=None,
               service=VoidService, config={}, ipv6=False, keepalive=False):
    """
    Connects to an RPyC server over SSL/TLS.
    
    Parameters:
    - host (str): Server hostname or IP address
    - port (int): Server port number
    - keyfile (str): Path to private key file
    - certfile (str): Path to certificate file
    - ca_certs (str): Path to CA certificates file
    - cert_reqs: Certificate requirements (ssl.CERT_NONE, ssl.CERT_OPTIONAL, ssl.CERT_REQUIRED)
    - ssl_version: SSL version to use
    - ciphers (str): Cipher suites to use
    - service (Service): Local service to expose
    - config (dict): Configuration dictionary
    - ipv6 (bool): Use IPv6 if True
    - keepalive (bool): Enable TCP keepalive
    
    Returns:
    Connection: Secure RPyC connection object
    """

Unix Socket Connections

Local inter-process communication using Unix domain sockets.

def unix_connect(path, service=VoidService, config={}):
    """
    Connects to an RPyC server over Unix domain socket.
    
    Parameters:
    - path (str): Path to Unix socket file
    - service (Service): Local service to expose
    - config (dict): Configuration dictionary
    
    Returns:
    Connection: RPyC connection object
    """

SSH Tunnel Connections

Remote connections through SSH tunnels for secure remote access.

def ssh_connect(remote_machine, remote_port, service=VoidService, config={}):
    """
    Connects to an RPyC server through SSH tunnel.
    
    Parameters:
    - remote_machine: SSH connection object or remote machine spec
    - remote_port (int): Remote port number on the SSH server
    - service (Service): Local service to expose
    - config (dict): Configuration dictionary
    
    Returns:
    Connection: RPyC connection through SSH tunnel
    """

Subprocess Connections

Connections to RPyC servers running as subprocesses.

def connect_subproc(args, service=VoidService, config={}):
    """
    Spawns RPyC server as subprocess and connects to it.
    
    Parameters:
    - args (list): Command line arguments for subprocess
    - service (Service): Local service to expose
    - config (dict): Configuration dictionary
    
    Returns:
    Connection: RPyC connection to subprocess
    """

Thread and Process-based Connections

In-process and multi-process connections for local distributed computing.

def connect_thread(service=VoidService, config={}, remote_service=VoidService, remote_config={}):
    """
    Creates in-thread RPyC connection for local distributed computing.
    
    Parameters:
    - service (Service): Local service to expose
    - config (dict): Local configuration dictionary
    - remote_service (Service): Remote service to run in thread
    - remote_config (dict): Remote configuration dictionary
    
    Returns:
    Connection: RPyC connection to thread
    """

def connect_multiprocess(service=VoidService, config={}, remote_service=VoidService, remote_config={}, args={}):
    """
    Creates RPyC connection to a new process with shared memory support.
    
    Parameters:
    - service (Service): Local service to expose
    - config (dict): Local configuration dictionary
    - remote_service (Service): Remote service to run in new process
    - remote_config (dict): Remote configuration dictionary
    - args (dict): Dictionary of local variables to share with new process
    
    Returns:
    Connection: RPyC connection to new process
    """

Service Discovery

Automatic service discovery and connection through registry services.

def discover(service_name, host=None, registrar=None, timeout=2):
    """
    Discovers RPyC services on the network.
    
    Parameters:
    - service_name (str): Name of service to discover
    - host (str): Host to search on (None for broadcast)
    - registrar: Registry client object
    - timeout (float): Discovery timeout in seconds
    
    Returns:
    list: List of (host, port) tuples for discovered services
    """

def list_services(registrar=None, filter_host=None, timeout=2):
    """
    Lists all available RPyC services.
    
    Parameters:
    - registrar: Registry client object  
    - filter_host (str): Filter services by host
    - timeout (float): Query timeout in seconds
    
    Returns:
    dict: Dictionary mapping service names to (host, port) tuples
    """

def connect_by_service(service_name, host=None, registrar=None, timeout=2, 
                      service=VoidService, config={}):
    """
    Discovers and connects to a named service.
    
    Parameters:
    - service_name (str): Name of service to connect to
    - host (str): Host to search on (None for broadcast)
    - registrar: Registry client object
    - timeout (float): Discovery timeout in seconds
    - service (Service): Local service to expose
    - config (dict): Configuration dictionary
    
    Returns:
    Connection: RPyC connection to discovered service
    """

Low-level Connection Functions

Lower-level connection functions for custom transport mechanisms.

def connect_stream(stream, service=VoidService, config={}):
    """
    Creates connection over an existing stream.
    
    Parameters:
    - stream: Stream object (SocketStream, PipeStream, etc.)
    - service (Service): Local service to expose
    - config (dict): Configuration dictionary
    
    Returns:
    Connection: RPyC connection over stream
    """

def connect_channel(channel, service=VoidService, config={}):
    """
    Creates connection over an existing channel.
    
    Parameters:
    - channel: Channel object
    - service (Service): Local service to expose  
    - config (dict): Configuration dictionary
    
    Returns:
    Connection: RPyC connection over channel
    """

def connect_pipes(input, output, service=VoidService, config={}):
    """
    Creates connection over input/output pipes.
    
    Parameters:
    - input: Input pipe/file object
    - output: Output pipe/file object
    - service (Service): Local service to expose
    - config (dict): Configuration dictionary
    
    Returns:
    Connection: RPyC connection over pipes
    """

def connect_stdpipes(service=VoidService, config={}):
    """
    Creates connection over stdin/stdout pipes.
    
    Parameters:
    - service (Service): Local service to expose
    - config (dict): Configuration dictionary
    
    Returns:
    Connection: RPyC connection over standard pipes
    """

Examples

Basic TCP Connection

import rpyc

# Connect to RPyC server
conn = rpyc.connect('192.168.1.100', 12345)

# Use the connection
result = conn.root.remote_function()

# Clean up
conn.close()

SSL Connection with Certificates

import rpyc

# Secure connection with SSL
conn = rpyc.ssl_connect(
    'secure-server.com', 18821,
    certfile='/path/to/client.crt',
    keyfile='/path/to/client.key',
    ca_certs='/path/to/ca.crt'
)

# Use secure connection
data = conn.root.get_sensitive_data()
conn.close()

Service Discovery

import rpyc

# Discover available services
services = rpyc.list_services()
print("Available services:", services)

# Connect to a specific service by name
conn = rpyc.connect_by_service('CALCULATOR')
result = conn.root.add(5, 3)
conn.close()

SSH Tunnel Connection

import rpyc
from plumbum import SshMachine

# Create SSH connection
ssh = SshMachine('remote-server.com', user='myuser')

# Connect through SSH tunnel
conn = rpyc.ssh_connect(ssh, 12345)
result = conn.root.remote_computation()
conn.close()

Multiprocess Connection

import rpyc

# Connect to a new process with shared memory
conn = rpyc.connect_multiprocess(
    remote_service=MyService,
    args={'shared_data': some_shared_object}
)

# Access the remote service in the new process
result = conn.root.process_data()
conn.close()

Exceptions

class DiscoveryError(Exception):
    """Raised when service discovery fails"""

class ForbiddenError(Exception):
    """Raised when connection is forbidden by server"""

Install with Tessl CLI

npx tessl i tessl/pypi-rpyc

docs

authentication-and-security.md

classic-mode.md

cli-tools.md

connection-factory.md

index.md

registry-and-discovery.md

servers.md

services-protocols.md

streams-and-channels.md

utilities.md

tile.json