WSGIProxy2

0.5.1 · active · verified Fri Apr 17

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.

Common errors

Warnings

Install

Imports

Quickstart

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)

view raw JSON →