{"library":"mitogen","title":"Mitogen","description":"Mitogen is a library for writing distributed self-replicating programs, designed to be fast, efficient, and flexible. It enables code execution on remote hosts with minimal overhead, making it ideal for automation and orchestration tasks. The current version is 0.3.46, and it sees regular minor releases, typically every few weeks or months, indicating active development.","language":"python","status":"active","last_verified":"Fri Apr 17","install":{"commands":["pip install mitogen"],"cli":null},"imports":["from mitogen.master import Router","from mitogen.master import ImportPolicy"],"auth":{"required":false,"env_vars":[]},"quickstart":{"code":"import mitogen.master\nimport os\nimport sys\nimport logging\n\nlogging.basicConfig(level=logging.INFO)\n\n# Connect to a remote host via SSH. For local testing, set MITOGEN_TARGET_HOSTNAME='localhost'\n# or configure your SSH client to allow localhost connections without password.\nrouter = mitogen.master.Router()\n\ntry:\n    hostname = os.environ.get('MITOGEN_TARGET_HOSTNAME', 'localhost')\n    if hostname == 'localhost' and not os.path.exists(os.path.expanduser('~/.ssh/id_rsa')):\n        logging.warning(\"No SSH key found for 'localhost'. Ensure SSH access is configured or use a different transport.\")\n\n    context = router.ssh(hostname=hostname)\n\n    # Run an operation on the remote host.\n    res = context.call(lambda: 'Hello from Python %s on %s' % (sys.version, os.uname()[1]))\n\n    # Print its return value.\n    print(f\"Remote execution result: {res}\")\n\nfinally:\n    router.shutdown()\n    router.join()","lang":"python","description":"This example demonstrates how to connect to a remote host (defaulting to localhost via SSH) and execute a simple Python function, returning its result. Ensure SSH is configured for the target host or choose a different transport (e.g., `router.fork()`).","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":null}