{"id":4750,"library":"rpyc","title":"RPyC (Remote Python Call)","description":"RPyC (Remote Python Call) is a transparent and symmetric distributed computing library for Python. It allows remote objects to be manipulated as if they were local, making it a powerful tool for building distributed systems and remote execution. The library is actively maintained, with frequent releases addressing bug fixes, performance improvements, and security enhancements. The current version is 6.0.2.","status":"active","version":"6.0.2","language":"en","source_language":"en","source_url":"https://github.com/tomerfiliba-org/rpyc","tags":["remote procedure call","rpc","distributed computing","networking","inter-process communication"],"install":[{"cmd":"pip install rpyc","lang":"bash","label":"Install RPyC"}],"dependencies":[{"reason":"Requires Python 3.8 or higher.","package":"python","optional":false}],"imports":[{"symbol":"rpyc","correct":"import rpyc"},{"symbol":"rpyc.utils.server.ThreadedServer","correct":"from rpyc.utils.server import ThreadedServer"},{"note":"Custom services typically inherit from `rpyc.Service`.","symbol":"rpyc.Service","correct":"import rpyc\n\nclass MyService(rpyc.Service):\n    # ...\n"},{"note":"Used for 'classic' RPyC connections to directly access remote modules and built-ins.","symbol":"rpyc.classic.connect","correct":"import rpyc\n\nconn = rpyc.classic.connect('localhost', 18812)"}],"quickstart":{"code":"# server.py\nimport rpyc\nfrom rpyc.utils.server import ThreadedServer\n\nclass MathService(rpyc.Service):\n    def on_connect(self, conn):\n        print(\"Client connected!\")\n\n    def on_disconnect(self, conn):\n        print(\"Client disconnected!\")\n\n    def exposed_fib(self, n):\n        \"\"\"Calculates the Fibonacci sequence up to n.\"\"\"\n        seq = []\n        a, b = 0, 1\n        while a < n:\n            seq.append(a)\n            a, b = b, a + b\n        return seq\n\nif __name__ == '__main__':\n    # Using a fixed port for demonstration\n    port = 18812\n    print(f\"Starting MathService on port {port}...\")\n    ts = ThreadedServer(MathService, port=port)\n    ts.start()\n\n# --- Save the above as server.py and run: python server.py ---\n\n# client.py\nimport rpyc\nimport time\n\ndef run_client():\n    host = \"localhost\" # Replace with your server's address if remote\n    port = 18812\n    try:\n        conn = rpyc.connect(host, port)\n        print(f\"Connected to RPyC server at {host}:{port}\")\n\n        # Access an exposed method on the root object\n        result = conn.root.fib(1000)\n        print(f\"Fibonacci sequence up to 1000: {result}\")\n\n        # Example of accessing a remote module (classic RPyC behavior)\n        remote_sys_version = conn.modules.sys.version\n        print(f\"Remote Python version: {remote_sys_version.splitlines()[0]}\")\n\n        conn.close()\n        print(\"Connection closed.\")\n    except ConnectionRefusedError:\n        print(f\"Error: Connection refused. Is the server running on {host}:{port}?\")\n    except Exception as e:\n        print(f\"An error occurred: {e}\")\n\nif __name__ == '__main__':\n    # Optional: Give the server a moment to start if run immediately after\n    # time.sleep(1)\n    run_client()\n","lang":"python","description":"This quickstart demonstrates a simple RPyC client-server interaction. First, save the server code as `server.py` and run it in a terminal. Then, save the client code as `client.py` and run it in another terminal to connect to the server, call a remote method, and access a remote module."},"warnings":[{"fix":"Upgrade to RPyC 6.0.0 or later. If relying on `__array__` for NumPy integration, review usage patterns and potentially adapt to new serialization or exposure methods.","message":"RPyC 6.0.0 introduced a security fix for a Remote Code Execution (RCE) vulnerability related to the `__array__` attribute, which breaks backward compatibility for code relying on `numpy`'s usage of this attribute. The RCE was exploitable if the server-side explicitly called `np.array(x)` on a remote object.","severity":"breaking","affected_versions":">=4.x.x, fixed in 6.0.0"},{"fix":"Migrate all RPyC clients and servers to Python 3.8+ and RPyC 5.0.0 or later.","message":"RPyC 5.0.0 officially dropped support for Python 2, coinciding with its end-of-life. Attempting to connect Python 2 clients to Python 3 servers (or vice-versa) or using RPyC 5+ on Python 2 will lead to incompatibility issues due to fundamental differences in Python's object model and bytecode.","severity":"breaking","affected_versions":"<5.0.0 (for Python 2 support)"},{"fix":"Ensure client and server use the same Python version and RPyC library version when teleporting functions. For complex objects or closures, consider alternatives like external serialization libraries (e.g., `dill`) or refactoring.","message":"Teleporting functions (e.g., using `rpyc.utils.classic.teleport_function`) between different Python major versions or even different RPyC versions is not officially supported and can lead to errors due to Python bytecode differences. It is recommended to ensure both client and server run the same Python and RPyC versions when using this feature.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Bind the RPyC server to a specific IP address (e.g., `127.0.0.1` for local connections or a specific network interface) or use proper authentication and encryption (SSL/TLS, SSH) for production environments. Always review the exposed services and methods carefully.","message":"Running a classic RPyC server with `--host 0.0.0.0` (which was the default in older versions) exposes it to arbitrary code execution from any connecting client. This can be a significant security risk.","severity":"gotcha","affected_versions":"All versions, especially older defaults"},{"fix":"Upgrade to RPyC 5.3.1 or later. If you were using the experimental thread binding feature on older versions, be aware of potential changes in behavior.","message":"RPyC 5.3.1 included a fix for an experimental thread binding struct that, while fixing issues on some platforms, was not backward compatible. This primarily affects users experimenting with the thread binding feature.","severity":"breaking","affected_versions":"<5.3.1 (for experimental thread binding)"}],"env_vars":null,"last_verified":"2026-04-12T00:00:00.000Z","next_check":"2026-07-11T00:00:00.000Z"}