A blazing-fast HTTP proxy for Python, powered by Go’s fasthttp library
Project description
pygofastproxy
A high-performance HTTP reverse proxy for Python, powered by Go's fasthttp. Three lines of Python to put a Go-speed proxy with built-in security in front of your app.
from pygofastproxy import run_proxy
run_proxy(target="http://localhost:4000", port=8080)
┌────────┐ ┌──────────────────────┐ ┌──────────┐
│ │ │ pygofastproxy │ │ │
│ Client │──────▶│ (Go binary) │──────▶│ Backend │
│ │◀──────│ │◀──────│ (Flask, │
└────────┘ │ + Security headers │ │ Django, │
│ + Per-IP rate limit │ │ FastAPI)│
│ + CORS │ └──────────┘
│ + TLS termination │
└──────────────────────┘
Why pygofastproxy?
Python web frameworks are great for building apps, but they weren't designed to be internet-facing reverse proxies. The typical solution is deploying Nginx or Caddy alongside your app — but that means extra infrastructure, config files, and moving parts.
pygofastproxy gives you Go-level proxy performance from a pip install:
| pygofastproxy | proxy.py | Nginx | mitmproxy | |
|---|---|---|---|---|
pip install + 3 lines of code |
Yes | No (plugin system) | No (separate install) | No (inspection tool) |
| Performance | Go (fasthttp) | Python | C | Python |
| Security headers by default | Yes | No | No (manual config) | No |
| Per-IP rate limiting built-in | Yes | No | Module | No |
| CORS handling built-in | Yes | No | No | No |
| TLS termination | Yes | Yes | Yes | Yes |
| Zero Python dependencies | Yes | Yes | N/A | No |
Best for: Python developers who want a fast, secure reverse proxy without deploying separate infrastructure.
Not designed for: Traffic inspection/debugging (use mitmproxy), load balancing across multiple backends (use Nginx/Traefik), or HTTP/2/WebSocket proxying (fasthttp limitation).
Quick Start
-
Install:
pip install pygofastproxy
-
Start your backend (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— they'll be proxied to your backend with security headers, rate limiting, and CORS handling added automatically.
Requirements: Python 3.8+ and Go (for building the proxy binary on first run). The binary is cached and only rebuilt when source changes.
Configuration
Python API
run_proxy(
target="http://localhost:4000",
port=8080,
rate_limit_rps=5000,
allowed_origins="https://yourdomain.com,https://app.yourdomain.com",
tls_cert_file="/path/to/cert.pem",
tls_key_file="/path/to/key.pem",
)
| Parameter | Type | Default | Description |
|---|---|---|---|
target |
str | "http://localhost:4000" |
Backend URL to proxy to |
port |
int | 8080 |
Proxy listen port |
rate_limit_rps |
int | 1000 |
Per-IP requests/sec (0 = unlimited) |
max_conns_per_host |
int | 1000 |
Max concurrent backend connections |
read_timeout |
str | "10s" |
Read timeout (e.g., "30s", "1m") |
write_timeout |
str | "10s" |
Write timeout |
max_idle_conn_duration |
str | "60s" |
Idle connection TTL |
max_request_body_size |
int | 10485760 |
Max request body in bytes (10MB) |
allowed_origins |
str | None |
Comma-separated CORS origins |
cors_allow_credentials |
bool | False |
Enable Access-Control-Allow-Credentials |
tls_cert_file |
str | None |
TLS certificate path (enables HTTPS) |
tls_key_file |
str | None |
TLS private key path |
Environment Variables
All settings can also be configured via environment variables (useful for Docker and CLI usage):
PY_BACKEND_TARGET=http://localhost:4000
PY_BACKEND_PORT=8080
PROXY_RATE_LIMIT_RPS=5000
PROXY_MAX_CONNS_PER_HOST=2000
PROXY_MAX_CONN_WAIT_TIMEOUT=5s
PROXY_READ_TIMEOUT=30s
PROXY_WRITE_TIMEOUT=30s
PROXY_MAX_IDLE_CONN_DURATION=60s
PROXY_READ_BUFFER_SIZE=16384
PROXY_WRITE_BUFFER_SIZE=16384
PROXY_MAX_REQUEST_BODY_SIZE=20971520
ALLOWED_ORIGINS=https://yourdomain.com
PROXY_CORS_ALLOW_CREDENTIALS=false
PROXY_TLS_CERT_FILE=/path/to/cert.pem
PROXY_TLS_KEY_FILE=/path/to/key.pem
Run via CLI: python -m pygofastproxy
Security Features
All security features are enabled by default with zero configuration:
- Per-IP rate limiting — Token bucket algorithm, 1000 req/s per IP by default. Stale buckets are cleaned up automatically.
- Security headers — Every response gets
X-Content-Type-Options: nosniff,X-Frame-Options: DENY,X-XSS-Protection: 1; mode=block.Cache-Control: no-storeis added only if the backend didn't set its own. - Request size limits — Rejects bodies over 10MB by default (configurable).
- Hop-by-hop header stripping — Removes
Connection,Proxy-Authorization,Transfer-Encoding, and any additional headers listed in theConnectionheader value (RFC 7230). - X-Forwarded headers — Always overwrites
X-Forwarded-For,X-Forwarded-Proto, andX-Forwarded-Hostto prevent client spoofing. - CORS protection — When
allowed_originsis set, only listed origins get CORS headers. Thenullorigin is always rejected.Access-Control-Allow-Credentialsis off by default. - No information leakage — Internal backend URLs and error details are never exposed to clients.
- TLS termination — Optional HTTPS support via cert/key configuration.
- Private target warnings — Logs a warning if the backend target is a private/loopback address.
- Connection backpressure —
MaxConnWaitTimeoutprevents goroutine accumulation when the backend is slow.
Benchmarks
Run the included benchmark to measure throughput on your hardware:
pip install pygofastproxy
python benchmarks/benchmark.py
You can also use external tools for more rigorous testing:
# Using hey (https://github.com/rakyll/hey)
hey -n 10000 -c 50 http://localhost:8080/
# Using wrk (https://github.com/wg/wrk)
wrk -t4 -c50 -d10s http://localhost:8080/
The proxy uses Go's fasthttp library, which is designed for high throughput with minimal allocations. All header byte slices are pre-allocated, the rate limiter uses per-bucket locks instead of a global mutex, and CORS origins are refreshed on a timer rather than per-request.
Docker
docker compose up --build
The Dockerfile uses a multi-stage build (Go builder + slim Python runtime) and runs as a non-root user. Configure via environment variables in .env or docker-compose.yml.
Testing
pip install -e ".[test]"
pytest tests/ -v
The test suite covers proxy forwarding, HTTP methods, security headers, CORS, rate limiting, health endpoint, and configuration validation.
Architecture
pygofastproxy is a hybrid Python+Go project:
- Python layer (
pygofastproxy/) — Package API, CLI, Go binary lifecycle management. Python never touches HTTP traffic. - Go layer (
pygofastproxy/go/) — The actual proxy, built on fasthttp. Handles all request forwarding, security, rate limiting, and CORS.
The Go binary is compiled automatically on first use via runner.py and cached. It's only rebuilt when .go, go.mod, or go.sum files change. Go is only required at build time — if the binary already exists (e.g., in Docker), Go is not needed.
Roadmap
- Pre-compiled wheels — Ship platform-specific wheels with the Go binary already built, removing the Go requirement entirely. Pure
pip installwith no build step. (Track progress)
Contributing
See CONTRIBUTING.md for guidelines on reporting bugs, suggesting features, and submitting pull requests.
License
MIT — Copyright 2026 Laurent Zogaj
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file pygofastproxy-1.1.0.tar.gz.
File metadata
- Download URL: pygofastproxy-1.1.0.tar.gz
- Upload date:
- Size: 18.6 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
92ea09f356c6f63478269f8e0cf89b70f05e13ac91ebd440142b22d0d7e9c058
|
|
| MD5 |
3381678687232e9e79dca7ea84db1541
|
|
| BLAKE2b-256 |
f4a66efe733dde9df2750defd899c9b3f0aae717dc7def5cb0f5bc55a2549c7d
|
Provenance
The following attestation bundles were made for pygofastproxy-1.1.0.tar.gz:
Publisher:
python-publish.yml on 26zl/pygofastproxy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pygofastproxy-1.1.0.tar.gz -
Subject digest:
92ea09f356c6f63478269f8e0cf89b70f05e13ac91ebd440142b22d0d7e9c058 - Sigstore transparency entry: 936061598
- Sigstore integration time:
-
Permalink:
26zl/pygofastproxy@8d743eb16d1d5fb0c4094783a44ac9be00bdad19 -
Branch / Tag:
refs/tags/1.1.0 - Owner: https://github.com/26zl
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@8d743eb16d1d5fb0c4094783a44ac9be00bdad19 -
Trigger Event:
release
-
Statement type:
File details
Details for the file pygofastproxy-1.1.0-py3-none-any.whl.
File metadata
- Download URL: pygofastproxy-1.1.0-py3-none-any.whl
- Upload date:
- Size: 16.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.13.7
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
53667865efdbb47e18344188b9f54f83aa38a67d24580e1c3eb086f5f892d6c1
|
|
| MD5 |
be0dcda75da529c8c4dc19416fa32553
|
|
| BLAKE2b-256 |
0ac4f94922154d3b59c31432b03c2a2d9de54d4a3af40e3c8ad60203b67db34a
|
Provenance
The following attestation bundles were made for pygofastproxy-1.1.0-py3-none-any.whl:
Publisher:
python-publish.yml on 26zl/pygofastproxy
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
pygofastproxy-1.1.0-py3-none-any.whl -
Subject digest:
53667865efdbb47e18344188b9f54f83aa38a67d24580e1c3eb086f5f892d6c1 - Sigstore transparency entry: 936061728
- Sigstore integration time:
-
Permalink:
26zl/pygofastproxy@8d743eb16d1d5fb0c4094783a44ac9be00bdad19 -
Branch / Tag:
refs/tags/1.1.0 - Owner: https://github.com/26zl
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
python-publish.yml@8d743eb16d1d5fb0c4094783a44ac9be00bdad19 -
Trigger Event:
release
-
Statement type: