{"id":8514,"library":"pyro4","title":"Pyro4","description":"Pyro4 is a robust and mature distributed object middleware for Python, enabling remote method calls (RPC) between Python applications. It reached its last major release with 4.82 in August 2020 and is now in a maintenance-only mode, with active development having shifted to its successor, Pyro5. Pyro4 offers features like name server discovery, object exposure, and various serialization options, making it suitable for creating distributed systems, but users should be aware of its end-of-life status for new feature development.","status":"maintenance","version":"4.82","language":"en","source_language":"en","source_url":"https://github.com/irmen/Pyro4","tags":["RPC","distributed","middleware","networking","legacy"],"install":[{"cmd":"pip install Pyro4","lang":"bash","label":"Install stable version"}],"dependencies":[],"imports":[{"symbol":"Daemon","correct":"from Pyro4 import Daemon"},{"symbol":"Proxy","correct":"from Pyro4 import Proxy"},{"symbol":"expose","correct":"from Pyro4 import expose"},{"symbol":"locateNS","correct":"from Pyro4 import locateNS"},{"symbol":"URI","correct":"from Pyro4 import URI"},{"symbol":"errors","correct":"from Pyro4 import errors"}],"quickstart":{"code":"import Pyro4\nimport threading\nimport time\n\n# --- Server Code (run in a separate thread/process) ---\n@Pyro4.expose\nclass GreetingMaker(object):\n    def get_fortune(self, name):\n        return f\"Hello, {name}. This is your fortune from Pyro4!\"\n\ndef run_server():\n    # In a real scenario, you'd run 'pyro4-ns' in a separate terminal\n    # For this example, we mock the Name Server interaction locally.\n    # Or, you'd start the Name Server programmatically:\n    # ns_thread = threading.Thread(target=Pyro4.naming.startNsLoop, daemon=True)\n    # ns_thread.start()\n    # time.sleep(1) # Give it a moment to start\n    \n    print(\"Pyro4 server starting...\")\n    daemon = Pyro4.Daemon()\n    # We'll use a local registration for this quickstart without needing pyro4-ns to be separately run\n    # In a real app, you'd use ns = Pyro4.locateNS() and ns.register()\n    # For simplicity, we just register directly with the daemon and use its URI.\n    uri = daemon.register(GreetingMaker, \"example.greeting\")\n    print(f\"Object registered with URI: {uri}\")\n    print(\"Server ready. Waiting for calls...\")\n    daemon.requestLoop()\n\n# --- Client Code ---\ndef run_client(server_uri):\n    print(\"Pyro4 client connecting...\")\n    try:\n        # Use the URI obtained from the server directly\n        with Pyro4.Proxy(server_uri) as greeter:\n            print(\"Client got proxy.\")\n            print(greeter.get_fortune(\"World\"))\n            print(greeter.get_fortune(\"Pythonista\"))\n    except Exception as e:\n        print(f\"Client error: {e}\")\n\nif __name__ == \"__main__\":\n    # To make this runnable as a single script for quickstart:\n    # 1. Run the Name Server manually in a separate terminal: pyro4-ns\n    # 2. Then, run this script. The server will register itself.\n    # For this quickstart, we'll demonstrate a simplified local interaction\n    # without explicitly starting a separate Name Server process within the script.\n    # In a real distributed setup, `pyro4-ns` is essential.\n\n    # Simplified local setup: Server registers object, client connects directly to its URI\n    daemon = Pyro4.Daemon() # start a new Pyro daemon\n    server_uri = daemon.register(GreetingMaker, \"example.greeting\") # register the object\n    print(f\"Server object URI: {server_uri}\")\n\n    server_thread = threading.Thread(target=daemon.requestLoop, daemon=True)\n    server_thread.start()\n    time.sleep(0.5) # Give the server a moment to start\n\n    run_client(server_uri)\n\n    print(\"Demonstration complete.\")\n    daemon.shutdown()\n","lang":"python","description":"This quickstart demonstrates a basic Pyro4 remote procedure call (RPC). It shows a server exposing a `GreetingMaker` object and a client connecting to it to call a remote method. For a fully distributed setup, you would typically run `pyro4-ns` (the Pyro4 Name Server) in a separate terminal, and both server and client would interact with it via `Pyro4.locateNS()` for discovery. This example simplifies by sharing the URI directly for self-contained execution."},"warnings":[{"fix":"Choose either Pyro4 or Pyro5 for your entire project. For new development, prefer Pyro5. For existing Pyro4 systems, stick to Pyro4 or plan a full migration.","message":"Pyro4 is not backward compatible with Pyro5. If migrating or starting a new project, consider using Pyro5 as it's the actively developed version. Do not mix Pyro4 and Pyro5 components.","severity":"breaking","affected_versions":"All Pyro4 versions when interacting with Pyro5"},{"fix":"For new projects, strongly consider using Pyro5. For existing Pyro4 projects, be aware that support is limited to critical issues.","message":"Pyro4 is in maintenance mode; active development has shifted to Pyro5. No new features will be added to Pyro4, only critical bug fixes.","severity":"deprecated","affected_versions":"4.x"},{"fix":"Ensure objects passed between Pyro4 components are serializable by 'serpent' or configure Pyro4 to use a different serializer (e.g., `Pyro4.config.SERIALIZER = 'pickle'`) at the start of both server and client applications. Be aware of pickle's security implications.","message":"By default, Pyro4 uses its internal 'serpent' serializer, which is more restrictive than 'pickle'. If you need to pass complex custom objects or objects with unpicklable components, you might encounter serialization errors.","severity":"gotcha","affected_versions":"All 4.x"},{"fix":"Implement your own security layer (e.g., VPN, SSH tunnels, IP whitelisting) around Pyro4 communication, or upgrade to Pyro5 which offers more security features.","message":"Pyro4 does not provide authentication or authorization by default. Exposing Pyro objects on public networks without proper security measures is highly risky.","severity":"gotcha","affected_versions":"All 4.x"},{"fix":"Ensure `pyro4-ns` is running and accessible (check firewall rules, IP address, and port). You can start it from the command line: `pyro4-ns -n your_ip_address` or `pyro4-ns` for localhost.","message":"The Pyro Name Server (pyro4-ns) is crucial for object discovery but must be run separately. Clients and servers will fail to locate objects if the Name Server isn't running or isn't accessible.","severity":"gotcha","affected_versions":"All 4.x"}],"env_vars":null,"last_verified":"2026-04-16T00:00:00.000Z","next_check":"2026-07-15T00:00:00.000Z","problems":[{"fix":"Start the Name Server in a separate terminal: `pyro4-ns`. Ensure firewall rules allow connections on the Name Server's port (default 9090).","cause":"The Pyro Name Server (`pyro4-ns`) is not running or the client/server cannot connect to it.","error":"Pyro4.errors.NamingError: no name server found"},{"fix":"Verify the server application is running. Check firewall settings on both client and server machines to allow traffic on the Pyro daemon's port. Ensure the IP address/hostname used for connection is correct.","cause":"The Pyro daemon (server) is not running at the specified address and port, or a firewall is blocking the connection.","error":"socket.error: [Errno 111] Connection refused"},{"fix":"Decorate all methods intended for remote access with `@Pyro4.expose` in the server-side object definition. Ensure the method name is correct and not a private method (starting with `_` or `__`).","cause":"The method 'my_method' on the remote object was not exposed using `@Pyro4.expose` or `Pyro4.expose()` for classes/functions, or the client is trying to call a private method.","error":"AttributeError: 'Proxy' object has no attribute 'my_method'"},{"fix":"Either refactor the object to remove unserializable parts, or configure Pyro4 to use a more permissive serializer if appropriate (e.g., `Pyro4.config.SERIALIZER = 'pickle'`). If using pickle, ensure all parts of the object are picklable.","cause":"You are trying to pass an object that cannot be serialized by the current serializer (e.g., 'serpent' or 'pickle' with unpicklable components) between client and server.","error":"TypeError: cannot pickle '_thread.RLock' object"}]}