{"library":"socketswap","title":"SocketSwap","type":"library","description":"SocketSwap is a Python package designed to proxy traffic from any third-party libraries through a local TCP SOCKS5 Proxy. It is especially useful for applications and libraries that do not offer native proxying capabilities. The current version, 0.1.11, was released on September 29, 2023, and the project is generally considered stable.","language":"python","status":"active","last_verified":"Sun May 17","install":{"commands":["pip install socketswap"],"cli":null},"imports":["from SocketSwap import ProxySwapContext"],"auth":{"required":false,"env_vars":[]},"links":{"homepage":null,"github":"https://github.com/fyx99/SocketSwap","docs":null,"changelog":null,"pypi":"https://pypi.org/project/socketswap/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null},"quickstart":{"code":"import socket\nimport logging\nimport threading\nimport time\nfrom SocketSwap import ProxySwapContext\n\n# Configure SocketSwap logging for visibility\nsocket_swap_logger = logging.getLogger(\"SocketSwap\")\nsocket_swap_logger.addHandler(logging.StreamHandler())\nsocket_swap_logger.setLevel(logging.DEBUG)\n\n# --- Dummy Remote Server (what ProxySwap will eventually connect to) ---\ndef dummy_remote_server(host, port):\n    server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n    server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)\n    server_socket.bind((host, port))\n    server_socket.listen(1)\n    print(f\"Dummy Remote Server listening on {host}:{port}\")\n    try:\n        conn, addr = server_socket.accept()\n        with conn:\n            print(f\"Dummy Remote Server: Connected by {addr}\")\n            data = conn.recv(1024)\n            if data:\n                print(f\"Dummy Remote Server: Received {data.decode()}\")\n                conn.sendall(b\"Hello from Remote Server\")\n    except Exception as e:\n        print(f\"Dummy Remote Server error: {e}\")\n    finally:\n        server_socket.close()\n\n# --- Socket Factory for ProxySwapContext ---\ndef create_remote_socket(target_host, target_port):\n    remote_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n    remote_socket.connect((target_host, target_port))\n    return remote_socket\n\n# --- Main application logic using ProxySwapContext ---\ndef main():\n    REMOTE_HOST = \"127.0.0.1\"\n    REMOTE_PORT = 54321 # Port for the dummy remote server\n    LOCAL_PROXY_HOST = \"127.0.0.1\"\n    LOCAL_PROXY_PORT = 22222 # Port for the local proxy\n\n    # Start the dummy remote server in a separate thread\n    server_thread = threading.Thread(target=dummy_remote_server, args=(REMOTE_HOST, REMOTE_PORT))\n    server_thread.daemon = True # Allow main program to exit even if server thread is running\n    server_thread.start()\n    time.sleep(0.5) # Give server a moment to start\n\n    print(f\"Starting ProxySwapContext on {LOCAL_PROXY_HOST}:{LOCAL_PROXY_PORT}\")\n    try:\n        with ProxySwapContext(\n            socket_factory=create_remote_socket,\n            socket_factory_args=(REMOTE_HOST, REMOTE_PORT),\n            local_proxy_host=LOCAL_PROXY_HOST,\n            local_proxy_port=LOCAL_PROXY_PORT\n        ):\n            print(\"ProxySwapContext is active. Connecting client to local proxy...\")\n            # --- Dummy Client connecting to the local proxy ---\n            client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)\n            client_socket.connect((LOCAL_PROXY_HOST, LOCAL_PROXY_PORT))\n            client_socket.sendall(b\"Hello via ProxySwap\")\n            response = client_socket.recv(1024)\n            print(f\"Client received from local proxy (and ultimately remote server): {response.decode()}\")\n            client_socket.close()\n            print(\"Client activity complete.\")\n\n        print(\"ProxySwapContext exited.\")\n    except Exception as e:\n        print(f\"An error occurred during ProxySwap operation: {e}\")\n\nif __name__ == \"__main__\":\n    main()","lang":"python","description":"This quickstart demonstrates how to initialize and use `ProxySwapContext`. It sets up a local TCP proxy that redirects traffic to a 'dummy remote server'. A client then connects to the local proxy, and its traffic is routed to the remote server via SocketSwap. Logging is also configured for better visibility into the proxy's operations.","tag":null,"tag_description":null,"last_tested":null,"results":[]},"compatibility":{"tag":null,"tag_description":null,"last_tested":"2026-05-17","installed_version":"0.1.11","pypi_latest":"0.1.11","is_stale":false,"summary":{"python_range":"3.10–3.9","success_rate":100,"avg_install_s":1.5,"avg_import_s":null,"wheel_type":"wheel"},"results":[{"runtime":"python:3.10-alpine","python_version":"3.10","os_libc":"alpine (musl)","variant":"socketswap","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"17.8M"},{"runtime":"python:3.10-slim","python_version":"3.10","os_libc":"slim (glibc)","variant":"socketswap","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":1.6,"import_time_s":null,"mem_mb":null,"disk_size":"18M"},{"runtime":"python:3.11-alpine","python_version":"3.11","os_libc":"alpine (musl)","variant":"socketswap","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"19.7M"},{"runtime":"python:3.11-slim","python_version":"3.11","os_libc":"slim (glibc)","variant":"socketswap","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":1.6,"import_time_s":null,"mem_mb":null,"disk_size":"20M"},{"runtime":"python:3.12-alpine","python_version":"3.12","os_libc":"alpine (musl)","variant":"socketswap","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"11.6M"},{"runtime":"python:3.12-slim","python_version":"3.12","os_libc":"slim (glibc)","variant":"socketswap","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":1.4,"import_time_s":null,"mem_mb":null,"disk_size":"12M"},{"runtime":"python:3.13-alpine","python_version":"3.13","os_libc":"alpine (musl)","variant":"socketswap","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"11.3M"},{"runtime":"python:3.13-slim","python_version":"3.13","os_libc":"slim (glibc)","variant":"socketswap","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":1.4,"import_time_s":null,"mem_mb":null,"disk_size":"12M"},{"runtime":"python:3.9-alpine","python_version":"3.9","os_libc":"alpine (musl)","variant":"socketswap","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":null,"import_time_s":null,"mem_mb":null,"disk_size":"17.3M"},{"runtime":"python:3.9-slim","python_version":"3.9","os_libc":"slim (glibc)","variant":"socketswap","exit_code":0,"wheel_type":"wheel","failure_reason":null,"import_side_effects":"broken","install_time_s":1.7,"import_time_s":null,"mem_mb":null,"disk_size":"18M"}]}}