Proxy.py

2.4.10 · active · verified Wed Apr 15

Proxy.py is a lightweight, dependency-optional, and pluggable framework for building fast proxy servers, web servers, and pub/sub systems. It supports HTTP, HTTPS, TLS interception, DNS-over-HTTPS, and can function as a reverse or forward proxy. Currently at version 2.4.10, the library maintains an active release cadence with frequent updates and new features.

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to programmatically start a basic HTTP forward proxy on `127.0.0.1:8899` using `proxy.py`. The `Proxy.main()` method is used with a list of arguments, mimicking command-line input. The `with` statement ensures proper resource management. The `time.sleep` loop keeps the main thread alive while the proxy runs in its own threads, allowing it to handle requests until a `KeyboardInterrupt` (Ctrl+C) is received.

import os
from proxy.py import Proxy

if __name__ == '__main__':
    # Example: Run a basic HTTP proxy on localhost:8899
    args = [
        '--hostname', '127.0.0.1',
        '--port', '8899',
        '--num-workers', '1', # For a simple quickstart
        '--disable-web-server', # Disable built-in web server if only proxy is needed
        '--plugins', 'proxy.py.http.proxy.HttpProxyPlugin' # Explicitly enable HTTP proxy
    ]

    print(f"Starting HTTP proxy on 127.0.0.1:8899...")
    print("Use Ctrl+C to stop.")

    try:
        # Proxy.main() takes arguments similar to command-line execution
        with Proxy.main(args):
            # The proxy runs in separate worker threads within the context manager.
            # Keep the main thread alive to allow the proxy to run.
            import time
            while True:
                time.sleep(1) 
    except KeyboardInterrupt:
        print("\nProxy stopped.")
    except Exception as e:
        print(f"An error occurred: {e}")

view raw JSON →