WSGIProxy2 is a Python library that provides a WSGI application to proxy HTTP requests to another server, supporting various HTTP client backends like requests, urllib3, or httpx. It allows for flexible routing and handling of incoming requests before forwarding them to a specified target URI. The current version is 0.5.1, and the project is maintained with infrequent but steady updates.
pip install wsgiproxy2Verified import paths — ran on the pinned version, not inferred.
This quickstart demonstrates how to set up a basic WSGI proxy using `wsgiproxy2` with `werkzeug.serving`. It creates a proxy application that forwards requests from '/proxy-path' on the local server to a specified target URI. Ensure your target server is running or set `WSGIPROXY_TARGET_URI` environment variable to a valid URL.
Always import the `Proxy` class using `from wsgiproxy import Proxy`.
Specify the desired backend during installation: `pip install wsgiproxy2[urllib3]` or `pip install wsgiproxy2[httpx]`.
Wrap the `Proxy` application with custom WSGI middleware to catch specific HTTP status codes or exceptions and handle them gracefully (e.g., return a custom error page, log, or retry).
Change the import statement to `from wsgiproxy import Proxy`.
Ensure you pass both the `local_path` and `target_uri` when instantiating the `Proxy` object, e.g., `application = Proxy('/my-path', 'http://example.com/api')`.Verify that the `target_uri` is correct and that the backend server it points to is actively running and accessible from where the `wsgiproxy2` application is hosted.