Skip to main content

A blazing-fast HTTP proxy for Python, powered by Go’s fasthttp library

Project description

pygofastproxy

A simple, fast, and secure HTTP reverse proxy for Python, powered by Go's fasthttp library.

Quick Start

  1. Install the package:

    pip install pygofastproxy
    
  2. Start your backend server (e.g., Flask) on port 4000.

  3. Run the proxy:

    from pygofastproxy import run_proxy
    
    run_proxy(target="http://localhost:4000", port=8080)
    
  4. Send requests to http://localhost:8080.

What is pygofastproxy?

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.

Installation

Install from PyPI:

pip install pygofastproxy

Requirements:

  • Python 3.8+
  • Go (for building the proxy binary)

Usage

Basic Example

from pygofastproxy import run_proxy

# Start the proxy (forwards :8080 to your backend at :4000)
run_proxy(target="http://localhost:4000", port=8080)

With Configuration

from pygofastproxy import run_proxy

run_proxy(
    target="http://localhost:4000",
    port=8080,
    rate_limit_rps=5000,
    allowed_origins="https://yourdomain.com"
)

Configuration Options

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

Environment Variables

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.com

Security Features

The 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_origins is set, only requests from those origins are permitted

Docker

Use the included Dockerfile and docker-compose.yml:

docker compose up --build

The 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).

Testing

Run the included test:

python test_functionality.py

Or test manually:

  1. Start a backend server: python3 -m http.server 4000
  2. Start the proxy: python -m pygofastproxy
  3. Test it: curl http://localhost:8080

Troubleshooting

"Go is not installed or not found in PATH"

Install Go from golang.org/dl

Rate limiting triggered

Increase rate_limit_rps or set to 0 for unlimited

CORS errors

Set allowed_origins to include your frontend domain

License

This project is licensed under the MIT License.

Credits

Powered by fasthttp by valyala.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

pygofastproxy-1.0.8.tar.gz (11.8 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

pygofastproxy-1.0.8-py3-none-any.whl (12.4 kB view details)

Uploaded Python 3

File details

Details for the file pygofastproxy-1.0.8.tar.gz.

File metadata

  • Download URL: pygofastproxy-1.0.8.tar.gz
  • Upload date:
  • Size: 11.8 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pygofastproxy-1.0.8.tar.gz
Algorithm Hash digest
SHA256 12eaa7b2dc5e1b8add189971885e6b3bbc711c3948e1be927ca727817f97547c
MD5 2b3edb8f0c05a9d70f8dc9518b4eb9ac
BLAKE2b-256 155187ba4428818ca87ffca834ac184e1e0beed8bd87e1236ad37c116633c54c

See more details on using hashes here.

Provenance

The following attestation bundles were made for pygofastproxy-1.0.8.tar.gz:

Publisher: python-publish.yml on 26zl/pygofastproxy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

File details

Details for the file pygofastproxy-1.0.8-py3-none-any.whl.

File metadata

  • Download URL: pygofastproxy-1.0.8-py3-none-any.whl
  • Upload date:
  • Size: 12.4 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? Yes
  • Uploaded via: twine/6.1.0 CPython/3.13.7

File hashes

Hashes for pygofastproxy-1.0.8-py3-none-any.whl
Algorithm Hash digest
SHA256 dfa3384889804699fd4818abb656fa0a2d09bebe9070ba181efcea0ce883feea
MD5 cc3085b7afadcdc953fcbfff032f80a0
BLAKE2b-256 0b2acbd559511a49debffbf17dcfeae9277d5c01bf7083117466b01fabaac69b

See more details on using hashes here.

Provenance

The following attestation bundles were made for pygofastproxy-1.0.8-py3-none-any.whl:

Publisher: python-publish.yml on 26zl/pygofastproxy

Attestations: Values shown here reflect the state when the release was signed and may no longer be current.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page