A simple, fast, and secure HTTP reverse proxy for Python, powered by Go's fasthttp library.
-
Install the package:
pip install pygofastproxy
-
Start your backend server (e.g., Flask) on port 4000.
-
Run the proxy:
from pygofastproxy import run_proxy run_proxy(target="http://localhost:4000", port=8080)
-
Send requests to
http://localhost:8080.
pygofastproxy is a reverse proxy that sits in front of your Python web application to provide:
- Fast performance using Go's fasthttp library
- Built-in security with automatic security headers
- CORS handling for frontend applications
- Rate limiting to protect your backend
- Simple setup with zero configuration required
Client → pygofastproxy:8080 → Your Backend:4000
The proxy receives all client requests, adds security protections, and forwards them to your backend server.
Install from PyPI:
pip install pygofastproxyRequirements:
- Python 3.8+
- Go (for building the proxy binary)
from pygofastproxy import run_proxy
# Start the proxy (forwards :8080 to your backend at :4000)
run_proxy(target="http://localhost:4000", port=8080)from pygofastproxy import run_proxy
run_proxy(
target="http://localhost:4000",
port=8080,
rate_limit_rps=5000,
allowed_origins="https://yourdomain.com"
)| Parameter | Type | Default | Description |
|---|---|---|---|
target |
str | "http://localhost:4000" |
Backend server URL to proxy to |
port |
int | 8080 |
Port for proxy to listen on |
max_conns_per_host |
int | 1000 |
Maximum concurrent connections per host |
read_timeout |
str | "10s" |
Read timeout (e.g., "10s", "1m") |
write_timeout |
str | "10s" |
Write timeout (e.g., "10s", "1m") |
rate_limit_rps |
int | 1000 |
Requests per second limit (0 = unlimited) |
max_request_body_size |
int | 10485760 |
Max request body size in bytes (10MB default) |
allowed_origins |
str | None |
Comma-separated CORS origins |
You can also configure the proxy using environment variables:
PY_BACKEND_TARGET=http://localhost:4000
PY_BACKEND_PORT=8080
PROXY_MAX_CONNS_PER_HOST=2000
PROXY_READ_TIMEOUT=30s
PROXY_WRITE_TIMEOUT=30s
PROXY_RATE_LIMIT_RPS=5000
PROXY_MAX_REQUEST_BODY_SIZE=20971520
ALLOWED_ORIGINS=https://yourdomain.comThe proxy automatically adds security headers and protections:
- Request size limits - Prevents memory exhaustion attacks (default: 10MB)
- Security headers - Adds X-Content-Type-Options, X-Frame-Options, X-XSS-Protection, Cache-Control
- Input validation - Validates all URLs and ports
- Rate limiting - Token bucket rate limiting to prevent backend overload
- CORS protection - When
allowed_originsis set, only requests from those origins are permitted
Use the included Dockerfile and docker-compose.yml:
docker compose up --buildThe compose file builds the proxy. Make sure your backend server is accessible at the URL specified in PY_BACKEND_TARGET (default: http://host.docker.internal:4000 for accessing host services from Docker).
Run the included test:
python test_functionality.pyOr test manually:
- Start a backend server:
python3 -m http.server 4000 - Start the proxy:
python -m pygofastproxy - Test it:
curl http://localhost:8080
Install Go from golang.org/dl
Increase rate_limit_rps or set to 0 for unlimited
Set allowed_origins to include your frontend domain
This project is licensed under the MIT License.