Monkeypatch the standard library to use a default proxy
masterYou can force the entire Python standard library (and many third-party modules) to use a specific proxy by setting a default proxy and overriding the global socket.socket class.
Warning: Monkeypatching is generally considered an anti-pattern in Python and may not work for all modules.
import socket
import socks
# Set the default proxy for new socksockets
socks.set_default_proxy(socks.SOCKS5, "localhost")
# Override the standard socket class
socket.socket = socks.socksocket