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

classic-mode.mddocs/

Classic Mode

Classic RPyC functionality providing direct remote Python execution, module access, and file transfer capabilities. Classic mode enables transparent remote code execution and filesystem operations, making the remote Python interpreter accessible as if it were local.

Capabilities

Connection Functions

Classic mode connection functions that automatically use ClassicService for remote Python execution.

def connect(host, port=18812, ipv6=False, keepalive=False):
    """
    Connect to classic RPyC server.
    
    Parameters:
    - host (str): Server hostname or IP address
    - port (int): Server port (default 18812)
    - ipv6 (bool): Use IPv6 if True
    - keepalive (bool): Enable TCP keepalive
    
    Returns:
    Connection: Classic RPyC connection with remote Python access
    """

def ssl_connect(host, port=18821, keyfile=None, certfile=None, ca_certs=None,
               cert_reqs=None, ssl_version=None, ciphers=None, ipv6=False, keepalive=False):
    """
    Connect to classic RPyC server over SSL.
    
    Parameters:
    - host (str): Server hostname or IP address  
    - port (int): Server SSL port (default 18821)
    - 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_version: SSL version to use
    - ciphers (str): Cipher suites to use
    - ipv6 (bool): Use IPv6 if True
    - keepalive (bool): Enable TCP keepalive
    
    Returns:
    Connection: Secure classic RPyC connection
    """

def unix_connect(path):
    """
    Connect to classic RPyC server via Unix socket.
    
    Parameters:
    - path (str): Path to Unix socket file
    
    Returns:
    Connection: Classic RPyC connection over Unix socket
    """

def ssh_connect(remote_machine, remote_port):
    """
    Connect to classic RPyC server through SSH tunnel.
    
    Parameters:  
    - remote_machine: SSH connection object
    - remote_port (int): Remote port number
    
    Returns:
    Connection: Classic RPyC connection through SSH
    """

def connect_subproc(server_file=None):
    """
    Start classic RPyC server as subprocess and connect.
    
    Parameters:
    - server_file (str): Path to server script (optional)
    
    Returns:
    Connection: Classic RPyC connection to subprocess
    """

def connect_thread():
    """
    Create in-thread classic RPyC connection.
    
    Returns:
    Connection: Classic RPyC connection in thread
    """

Remote Code Execution

Direct execution of Python code on the remote interpreter.

# Connection methods for code execution
def execute(self, code):
    """
    Execute Python code on remote interpreter.
    
    Parameters:
    - code (str): Python code to execute
    
    Returns:
    None
    
    Note: Access via conn.execute(code)
    """

def eval(self, expression):
    """
    Evaluate Python expression on remote interpreter.
    
    Parameters:
    - expression (str): Python expression to evaluate
    
    Returns:
    Result of expression evaluation
    
    Note: Access via conn.eval(expression)
    """

Remote Module Access

Access to remote Python modules and built-in functions.

# Connection properties for module access
@property
def modules(self):
    """
    Access to remote Python modules.
    
    Returns:
    ModuleNamespace: Proxy to remote sys.modules
    
    Usage:
    - conn.modules.os.listdir('/tmp')
    - conn.modules['xml.dom.minidom'].parseString('<root/>')
    """

@property  
def builtin(self):
    """
    Access to remote built-in functions.
    
    Returns:
    ModuleNamespace: Proxy to remote builtins
    
    Usage:
    - conn.builtin.open('/path/file', 'r')
    - conn.builtin.len([1, 2, 3])
    """

@property
def builtins(self):
    """Alias for builtin property"""

File Transfer Operations

High-level file and directory transfer between local and remote systems.

def upload(conn, localpath, remotepath, filter=None, ignore_invalid=False, chunk_size=8192):
    """
    Upload files or directories to remote system.
    
    Parameters:
    - conn: RPyC connection
    - localpath (str): Local file or directory path
    - remotepath (str): Remote destination path
    - filter (callable): Optional filter function for files
    - ignore_invalid (bool): Skip invalid files if True
    - chunk_size (int): Transfer chunk size in bytes
    """

def upload_file(conn, localpath, remotepath, chunk_size=8192):
    """
    Upload single file to remote system.
    
    Parameters:
    - conn: RPyC connection
    - localpath (str): Local file path
    - remotepath (str): Remote file path
    - chunk_size (int): Transfer chunk size in bytes
    """

def upload_dir(conn, localpath, remotepath, filter=None, chunk_size=8192):
    """
    Upload directory to remote system.
    
    Parameters:
    - conn: RPyC connection
    - localpath (str): Local directory path
    - remotepath (str): Remote directory path  
    - filter (callable): Optional filter function for files
    - chunk_size (int): Transfer chunk size in bytes
    """

def download(conn, remotepath, localpath, filter=None, ignore_invalid=False, chunk_size=8192):
    """
    Download files or directories from remote system.
    
    Parameters:
    - conn: RPyC connection
    - remotepath (str): Remote file or directory path
    - localpath (str): Local destination path
    - filter (callable): Optional filter function for files
    - ignore_invalid (bool): Skip invalid files if True
    - chunk_size (int): Transfer chunk size in bytes
    """

def download_file(conn, remotepath, localpath, chunk_size=8192):
    """
    Download single file from remote system.
    
    Parameters:
    - conn: RPyC connection
    - remotepath (str): Remote file path
    - localpath (str): Local file path
    - chunk_size (int): Transfer chunk size in bytes
    """

def download_dir(conn, remotepath, localpath, filter=None, chunk_size=8192):
    """
    Download directory from remote system.
    
    Parameters:
    - conn: RPyC connection
    - remotepath (str): Remote directory path
    - localpath (str): Local directory path
    - filter (callable): Optional filter function for files
    - chunk_size (int): Transfer chunk size in bytes
    """

Package and Object Transfer

Transfer Python packages and objects between local and remote systems.

def upload_package(conn, module, remotepath=None, chunk_size=8192):
    """
    Upload Python package to remote system.
    
    Parameters:
    - conn: RPyC connection
    - module: Python module to upload
    - remotepath (str): Remote destination path (optional)
    - chunk_size (int): Transfer chunk size in bytes
    """

def obtain(proxy):
    """
    Transfer remote object to local system.
    
    Parameters:
    - proxy: Remote object proxy (netref)
    
    Returns:
    Local copy of remote object
    """

def deliver(conn, localobj):
    """
    Transfer local object to remote system.
    
    Parameters:
    - conn: RPyC connection
    - localobj: Local object to transfer
    
    Returns:
    Remote proxy to transferred object
    """

def teleport_function(conn, func, globals=None, def_=True):
    """
    Transfer function to remote system for execution.
    
    Parameters:
    - conn: RPyC connection
    - func: Function to transfer
    - globals (dict): Global variables for function
    - def_ (bool): Define function remotely if True
    
    Returns:
    Remote proxy to transferred function
    """

Interactive Features

Interactive debugging and development tools.

def redirected_stdio(conn):
    """
    Context manager redirecting stdin/stdout to remote system.
    
    Parameters:
    - conn: RPyC connection
    
    Returns:
    Context manager for stdio redirection
    
    Usage:
    with redirected_stdio(conn):
        # Local print() outputs to remote stdout
        print("This appears on remote system")
    """

def interact(conn, namespace=None):
    """
    Start interactive session with remote Python interpreter.
    
    Parameters:
    - conn: RPyC connection
    - namespace (dict): Local namespace for interaction
    """

def pm(conn):
    """
    Start post-mortem debugging session on remote system.
    
    Parameters:
    - conn: RPyC connection
    """

Examples

Basic Remote Execution

import rpyc.classic as rpyc

# Connect to classic server
conn = rpyc.connect('remote-host')

# Execute Python code
conn.execute('x = 5 * 10')
conn.execute('import math')
conn.execute('y = math.sqrt(x)')

# Evaluate expressions
result = conn.eval('y')
print(f"Result: {result}")  # Result: 7.07...

conn.close()

Remote Module Access

import rpyc.classic as rpyc

conn = rpyc.connect('remote-host')

# Access remote modules
files = conn.modules.os.listdir('/tmp')
print("Remote /tmp contents:", files)

# Use remote built-ins
remote_file = conn.builtin.open('/etc/hostname', 'r')
hostname = remote_file.read().strip()
remote_file.close()
print("Remote hostname:", hostname)

# Work with remote data structures
remote_dict = conn.eval("{'key': 'value', 'number': 42}")
print("Remote dict keys:", list(remote_dict.keys()))

conn.close()

File Transfer Operations

import rpyc.classic as rpyc

conn = rpyc.connect('remote-host')

# Upload files
rpyc.upload(conn, 'local_file.txt', '/tmp/remote_file.txt')
rpyc.upload_dir(conn, 'local_dir/', '/tmp/remote_dir/')

# Download files  
rpyc.download(conn, '/etc/passwd', 'downloaded_passwd.txt')
rpyc.download_dir(conn, '/var/log/', 'local_logs/')

# Upload Python package
import json
rpyc.upload_package(conn, json, '/tmp/json_module/')

conn.close()

Object Transfer

import rpyc.classic as rpyc

conn = rpyc.connect('remote-host')

# Create remote object
conn.execute('data = [1, 2, 3, 4, 5]')
remote_list = conn.eval('data')

# Bring remote object local
local_copy = rpyc.obtain(remote_list)
print("Local copy:", local_copy)

# Send local object to remote
local_dict = {'name': 'Alice', 'age': 30}
remote_proxy = rpyc.deliver(conn, local_dict)

# Use remote proxy
conn.execute('print("Remote dict:", delivered_dict)')

conn.close()

Interactive Development

import rpyc.classic as rpyc

conn = rpyc.connect('remote-host')

# Redirect local output to remote
with rpyc.redirected_stdio(conn):
    print("This appears on remote stdout")
    user_input = input("Enter something on remote: ")

# Start interactive session
rpyc.interact(conn, namespace={'myvar': 42})

# In case of remote errors, debug
try:
    conn.execute('1/0')  # This will cause error
except:
    rpyc.pm(conn)  # Start post-mortem debugging

conn.close()

Function Teleportation

import rpyc.classic as rpyc

conn = rpyc.connect('remote-host')

# Define function to teleport
def process_data(data):
    return [x * 2 for x in data if x > 0]

# Teleport function to remote
remote_func = rpyc.teleport_function(conn, process_data)

# Use function remotely
conn.execute('test_data = [-1, 2, -3, 4, 5]')
result = conn.eval('process_data(test_data)')
print("Remote processing result:", list(result))

conn.close()

Constants

DEFAULT_SERVER_PORT = 18812        # Default classic server port
DEFAULT_SERVER_SSL_PORT = 18821    # Default classic SSL server port
STREAM_CHUNK = 8192               # Default chunk size for file transfers

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