Install & Compatibility
Where this runs
tested against v0.1.11 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
muslpy 3.10–3.920 runs
installs and imports cleanly · install 0.0s · import 0.000s · 17.8MB
glibcpy 3.10–3.920 runs
installs and imports cleanly · install 1.6s · import 0.000s · 18MB
16MB installed
● package 16MB
Code
Verified usage
Verified import paths — ran on the pinned version, not inferred.
SocketSwapContext
✓ from SocketSwap import SocketSwapContext
✗ from SocketSwap import ProxySwapContext
context_manager
✓ from SocketSwap import context_manager
start_local_proxy
✓ from SocketSwap import start_local_proxy
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.
import socket
import logging
import threading
import time
from SocketSwap import ProxySwapContext
# Configure SocketSwap logging for visibility
socket_swap_logger = logging.getLogger("SocketSwap")
socket_swap_logger.addHandler(logging.StreamHandler())
socket_swap_logger.setLevel(logging.DEBUG)
# --- Dummy Remote Server (what ProxySwap will eventually connect to) ---
def dummy_remote_server(host, port):
server_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
server_socket.setsockopt(socket.SOL_SOCKET, socket.SO_REUSEADDR, 1)
server_socket.bind((host, port))
server_socket.listen(1)
print(f"Dummy Remote Server listening on {host}:{port}")
try:
conn, addr = server_socket.accept()
with conn:
print(f"Dummy Remote Server: Connected by {addr}")
data = conn.recv(1024)
if data:
print(f"Dummy Remote Server: Received {data.decode()}")
conn.sendall(b"Hello from Remote Server")
except Exception as e:
print(f"Dummy Remote Server error: {e}")
finally:
server_socket.close()
# --- Socket Factory for ProxySwapContext ---
def create_remote_socket(target_host, target_port):
remote_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
remote_socket.connect((target_host, target_port))
return remote_socket
# --- Main application logic using ProxySwapContext ---
def main():
REMOTE_HOST = "127.0.0.1"
REMOTE_PORT = 54321 # Port for the dummy remote server
LOCAL_PROXY_HOST = "127.0.0.1"
LOCAL_PROXY_PORT = 22222 # Port for the local proxy
# Start the dummy remote server in a separate thread
server_thread = threading.Thread(target=dummy_remote_server, args=(REMOTE_HOST, REMOTE_PORT))
server_thread.daemon = True # Allow main program to exit even if server thread is running
server_thread.start()
time.sleep(0.5) # Give server a moment to start
print(f"Starting ProxySwapContext on {LOCAL_PROXY_HOST}:{LOCAL_PROXY_PORT}")
try:
with ProxySwapContext(
socket_factory=create_remote_socket,
socket_factory_args=(REMOTE_HOST, REMOTE_PORT),
local_proxy_host=LOCAL_PROXY_HOST,
local_proxy_port=LOCAL_PROXY_PORT
):
print("ProxySwapContext is active. Connecting client to local proxy...")
# --- Dummy Client connecting to the local proxy ---
client_socket = socket.socket(socket.AF_INET, socket.SOCK_STREAM)
client_socket.connect((LOCAL_PROXY_HOST, LOCAL_PROXY_PORT))
client_socket.sendall(b"Hello via ProxySwap")
response = client_socket.recv(1024)
print(f"Client received from local proxy (and ultimately remote server): {response.decode()}")
client_socket.close()
print("Client activity complete.")
print("ProxySwapContext exited.")
except Exception as e:
print(f"An error occurred during ProxySwap operation: {e}")
if __name__ == "__main__":
main()
Upgrade
Version history
0.1.11latest on PyPI · released Sep 29, 2023
Audit
Dependencies
No dependency data recorded yet.