Skip to main content

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

Project description

pygofastproxy

A blazing-fast HTTP 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.runner import run_proxy
    run_proxy(target="http://localhost:4000", port=8080)
    
  4. Send requests to http://localhost:8080.

How it Works

pygofastproxy launches a Go-based HTTP proxy as a subprocess from Python. The Go proxy listens on the specified port and forwards all HTTP requests to your backend server. Configuration is handled via Python arguments or environment variables.


Overview

pygofastproxy is a Python package that provides a super-fast HTTP proxy, powered by Go, for use with Python web backends. It is ideal for scenarios where you want to:

  • Add a high-performance reverse proxy in front of your Python (Flask, FastAPI, Django, etc.) backend.
  • Integrate with frontend frameworks (like Next.js) that need to proxy API requests to a Python backend.
  • Use as a development tool to forward requests, add logging, or simulate production-like proxying locally.
  • Robust and Secure.

Features

  • Fast HTTP proxying using Go's fasthttp library
  • Simple Python API to launch and control the proxy
  • Automatic Go binary build if not present
  • Easily configurable target and port
  • Planned: Pre-built binaries for easier installation (coming soon!)
  • More features coming soon!

Installation

You can install from PyPI:

pip install pygofastproxy

Or, for local development:

pip install /path/to/pygofastproxy

Usage

As a Python Module

from pygofastproxy.runner import run_proxy

# Start the proxy (forwards :8080 to your backend at :4000)
run_proxy(target="http://localhost:4000", port=8080)
  • By default, the proxy will listen on localhost:8080 and forward to your backend at localhost:4000.
  • You can adjust the target and port as needed.

Environment Variables

You can control the proxy using these environment variables:

  • PY_BACKEND_TARGET: The backend server URL to forward requests to (default: http://localhost:4000).
  • PY_BACKEND_PORT: The port for the proxy to listen on (default: 8080).

Testing

To manually test the proxy:

  1. Start a backend server on port 4000 (e.g., python3 -m http.server 4000).
  2. Start the proxy as shown above.
  3. In another terminal, run:
    curl http://localhost:8080
    
    You should see the response from your backend, confirming the proxy is working.

Example: Use with Flask and Next.js (Dockerized)

Suppose you have a Flask backend and a Next.js frontend. You can use pygofastproxy as a reverse proxy between them:

  • Frontend (Next.js) sends API requests to localhost:8080
  • pygofastproxy forwards requests to Flask backend at localhost:4000

docker-compose.yml (simplified):

version: '3.8'
services:
  proxy:
    build: ./proxy
    ports:
      - "8080:8080"
    depends_on:
      - backend

  backend:
    build: ./backend
    ports:
      - "4000:4000"

  frontend:
    build: ./frontend
    ports:
      - "3000:3000"
    environment:
      - NEXT_PUBLIC_API_URL=http://localhost:8080

Use Cases

  • Development proxy: Quickly forward requests from a frontend to a Python backend, simulating production proxying.
  • Performance: Add a fast Go-based proxy in front of Python services for better throughput.
  • API Gateway: Use as a lightweight API gateway for microservices.
  • Testing: Intercept and forward requests for integration testing.

Requirements

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

License

This project is licensed under the MIT License.


Contributing

Contributions are welcome! Please open issues or submit pull requests for bug fixes, improvements, or new features. For major changes, please open an issue first to discuss what you would like to change.


Credits

  • This project is powered by the amazing fasthttp library by valyala. Huge thanks to the fasthttp contributors for their work on one of the fastest HTTP libraries for Go.

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.4.tar.gz (7.0 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.4-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

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

File metadata

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

File hashes

Hashes for pygofastproxy-1.0.4.tar.gz
Algorithm Hash digest
SHA256 d3fc093d178390b28f0ed10cf7f5ce482d5229133974ea8909d9d7efae3ee79e
MD5 6885dca2bdbfbd12d1b27d8641263100
BLAKE2b-256 cefc6fd6e27d8329477fbceaa53508582a7e26a5ef2651314a4d588069dd988f

See more details on using hashes here.

Provenance

The following attestation bundles were made for pygofastproxy-1.0.4.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.4-py3-none-any.whl.

File metadata

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

File hashes

Hashes for pygofastproxy-1.0.4-py3-none-any.whl
Algorithm Hash digest
SHA256 83141bab5830e34d0cc536afe1a4533814c5a6beda58fd4ae372cdb932cf4797
MD5 57ef1ea6c7fcffe2664f45019aac751a
BLAKE2b-256 9cd74298bdd764633716a3a6b5e1e2b6652773d56b64dea528995cf281d61d99

See more details on using hashes here.

Provenance

The following attestation bundles were made for pygofastproxy-1.0.4-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