Registry / http-networking / wsgiproxy2

wsgiproxy2

JSON →
library0.5.1pypypi✓ verified 87d ago

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 wsgiproxy2
INSTALL
IMPORT
SIG · WSGIPROXY2
W
wsgiproxy2
http-networkingpythonv0.5.1
Install
1.6s avg
Import
211ms
Disk
17MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.5.1 · 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
musl
py 3.103.920 runs
installs and imports cleanly · install 0.0s · import 0.217s · 18.8MB
glibc
py 3.103.920 runs
installs and imports cleanly · install 1.6s · import 0.204s · 19MB
17MB installed
● package 17MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

Proxy
from wsgiproxy import Proxy
from wsgiproxy2 import Proxy
The package name is 'wsgiproxy2', but the main 'Proxy' class is imported from the 'wsgiproxy' module.

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.

from wsgiproxy import Proxy from werkzeug.serving import run_simple import os # Configure the target URI for the proxy TARGET_URI = os.environ.get('WSGIPROXY_TARGET_URI', 'http://localhost:8000') # Create a Proxy instance, mapping '/proxy-path' to TARGET_URI # All requests to '/proxy-path' will be forwarded to TARGET_URI application = Proxy( '/proxy-path', TARGET_URI ) if __name__ == '__main__': print(f"Proxying requests from http://localhost:5000/proxy-path to {TARGET_URI}") # Run the WSGI application using Werkzeug's development server run_simple('localhost', 5000, application)
Debug
Known issues
gotchaThe package is installed as `wsgiproxy2` but the primary class `Proxy` is imported from the `wsgiproxy` module. Using `from wsgiproxy2 import Proxy` will result in a `ModuleNotFoundError` or `AttributeError`.
fix
Always import the `Proxy` class using `from wsgiproxy import Proxy`.
affects: All versions
gotchaWhile `requests` is installed by default as the backend, to use `urllib3` or `httpx`, you must install `wsgiproxy2` with the corresponding extra dependencies (e.g., `pip install wsgiproxy2[httpx]`).
fix
Specify the desired backend during installation: `pip install wsgiproxy2[urllib3]` or `pip install wsgiproxy2[httpx]`.
affects: All versions
gotchaBy default, `wsgiproxy2` will propagate backend errors (e.g., connection refused, 404 from target) as the proxy's response. For more robust applications, you may need to implement custom error handling or retry logic using middleware.
fix
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).
affects: All versions
Errors
Common errors & fixes
ModuleNotFoundError: No module named 'wsgiproxy2'
Attempting to import `Proxy` directly from the `wsgiproxy2` package name, instead of the correct `wsgiproxy` module name.
fix
Change the import statement to `from wsgiproxy import Proxy`.
TypeError: __init__() missing 1 required positional argument: 'target_uri'
The `Proxy` class constructor requires at least two arguments: the local path to proxy, and the target URI.
fix
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')`.
requests.exceptions.ConnectionError: HTTPConnectionPool(host='localhost', port=8000): Max retries exceeded with url: / (Caused by NewConnectionError('<urllib3.connection.HTTPConnection object at ...>: Failed to establish a new connection: [Errno 111] Connection refused'))
The `target_uri` specified for the proxy is unreachable, or the backend server is not running/listening on the specified address and port.
fix
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.
Upgrade
Version history
0.5.1latest on PyPI · released Aug 26, 2021
Audit
Dependencies
werkzeugrequiredRequired for basic functionality and commonly used with WSGI apps.
requestsrequiredDefault HTTP client backend, installed by default.
urllib3optionalOptional HTTP client backend, installed via `wsgiproxy2[urllib3]`.
httpxoptionalOptional HTTP client backend, installed via `wsgiproxy2[httpx]`.
Agent activity
27 hits · last 30 days
node
22
OpenAI (training)
1
Resources
wsgiproxy2 — pip install wsgiproxy2 · libregistry