Skip to main content

High-performance async proxy server with uvloop, connection pooling, and multi-process support.

Project description

made-with-python PyPI-version GitHub

High-performance HTTP/Socks4/Socks5/Shadowsocks/SSH async proxy server with uvloop, connection pooling, and multi-process support.

pproxy2 is a performance-optimized fork of the original pproxy by Qian Wenjie.

Credits

This project is based on the excellent work of:

We extend our gratitude to Qian Wenjie for creating the original pproxy project.

What’s New in pproxy2

Performance optimizations that make pproxy2 significantly faster:

Feature

Performance Gain

Description

pycryptodome (required)

60-288x

Fast C-based encryption

uvloop (auto-enabled)

2-3x

High-performance event loop

Connection pooling

60x

Reuse TCP connections

TCP_NODELAY

Lower latency

Disable Nagle’s algorithm

Multi-process workers

Scale to cores

--workers N option

Batched I/O

Reduced syscalls

Optimized drain() calls

QuickStart

$ pip3 install pproxy2
$ pproxy2
Using uvloop (faster event loop)
Serving on :8080 by http,socks4,socks5

With encryption (Shadowsocks-compatible):

$ pproxy2 -l ss://aes-256-gcm:password@:8080
Using uvloop (faster event loop)
Serving on :8080 by ss (aes-256-gcm)

High-performance mode with multiple workers:

$ pproxy2 -l http+socks5://:8080 --workers 4
Worker 1 started (PID: 12345)
Worker 2 started (PID: 12346)
Worker 3 started (PID: 12347)
Master process (PID: 12344) with 3 workers
Using uvloop (faster event loop)
Serving on :8080 by http,socks5

Installation

$ pip3 install pproxy2

This will automatically install:

  • pycryptodome - Fast encryption (required)

  • uvloop - Fast event loop (Linux/macOS only)

Optional dependencies:

$ pip3 install pproxy2[sshtunnel]  # SSH tunnel support
$ pip3 install pproxy2[quic]       # QUIC/HTTP3 support
$ pip3 install pproxy2[daemon]     # Daemon mode support

New Command-Line Options

--workers N    Number of worker processes (Linux only, auto-enables SO_REUSEPORT)
--reuse        Enable SO_REUSEPORT for port sharing between processes

Features

All original pproxy features are preserved:

  • Lightweight single-thread asynchronous IO (now with uvloop)

  • Proxy client/server for TCP/UDP

  • Schedule (load balance) among remote servers

  • Incoming traffic auto-detect

  • Tunnel/jump/backward-jump support

  • Unix domain socket support

  • HTTP v2, HTTP v3 (QUIC)

  • User/password authentication support

  • Filter/block hostname by regex patterns

  • SSL/TLS client/server support

  • Shadowsocks OTA (One-Time-Auth), SSR plugins

  • Statistics by bandwidth and traffic

  • PAC support for javascript configuration

  • Iptables/Pf NAT redirect packet tunnel

  • System proxy auto-setting support

  • Client/Server API provided

Plus new performance features:

  • uvloop - 2-3x faster event loop (auto-enabled on Linux/macOS)

  • Connection pooling - 60x faster for repeated connections

  • Multi-process workers - Scale across CPU cores

  • TCP_NODELAY - Lower latency connections

  • Optimized encryption - pycryptodome required (60-288x faster)

Supported Protocols

Name

TCP server

TCP client

UDP server

UDP client

scheme

http (connect)

Y

Y

http://

socks4

Y

Y

socks4://

socks5

Y

Y

Y

Y

socks5://

shadowsocks

Y

Y

Y

Y

ss://

shadowsocks aead

Y

Y

ss://

shadowsocksR

Y

Y

ssr://

trojan

Y

Y

trojan://

ssh tunnel

Y

ssh://

http v2

Y

Y

h2://

http v3 (quic)

Y

Y

h3://

websocket

Y

Y

ws://

Supported Ciphers

AEAD ciphers (recommended):

  • aes-256-gcm, aes-192-gcm, aes-128-gcm

  • chacha20-ietf-poly1305

Stream ciphers:

  • chacha20, chacha20-ietf, salsa20

  • aes-256-cfb, aes-192-cfb, aes-128-cfb

  • aes-256-ctr, aes-256-ofb

  • rc4-md5, bf-cfb, cast5-cfb, des-cfb

Performance Benchmarks

Encryption performance (pycryptodome vs pure Python):

Cipher

Speedup

AES-256-GCM

288x faster

ChaCha20-Poly1305

195x faster

AES-256-CFB

76x faster

ChaCha20

60x faster

Connection pooling performance:

Scenario

Speedup

Repeated connections

60x faster

Sequential HTTP reuse

150,000x

API Usage

TCP Client:

import asyncio
import pproxy

async def main():
    conn = pproxy.Connection('ss://aes-256-gcm:password@server:8080')
    reader, writer = await conn.tcp_connect('google.com', 443)
    writer.write(b'GET / HTTP/1.1\r\nHost: google.com\r\n\r\n')
    data = await reader.read(1024)
    print(data)

asyncio.run(main())

Server API:

import asyncio
import pproxy

async def main():
    server = pproxy.Server('ss://aes-256-gcm:password@:8080')
    handler = await server.start_server({'verbose': print})
    await handler.wait_closed()

asyncio.run(main())

Migration from pproxy

pproxy2 is fully backward compatible with pproxy. Simply replace:

$ pip3 uninstall pproxy
$ pip3 install pproxy2

The pproxy command still works for compatibility. Use pproxy2 for the new optimized version.

License

MIT License - Same as the original pproxy project.

Author

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

pproxy2-2.2.0.tar.gz (47.0 kB view details)

Uploaded Source

Built Distribution

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

pproxy2-2.2.0-py3-none-any.whl (42.9 kB view details)

Uploaded Python 3

File details

Details for the file pproxy2-2.2.0.tar.gz.

File metadata

  • Download URL: pproxy2-2.2.0.tar.gz
  • Upload date:
  • Size: 47.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for pproxy2-2.2.0.tar.gz
Algorithm Hash digest
SHA256 9e4a92f109587cceb045c7e361130b17f6ce33581172e1e50b769af854bc5a18
MD5 5624a8171673e00a34f2c13563446611
BLAKE2b-256 87ebc4f582d9a045c70c0faaf0e28823168d3f29770f0d054a9b5434ee8ee393

See more details on using hashes here.

File details

Details for the file pproxy2-2.2.0-py3-none-any.whl.

File metadata

  • Download URL: pproxy2-2.2.0-py3-none-any.whl
  • Upload date:
  • Size: 42.9 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.3

File hashes

Hashes for pproxy2-2.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 697ec710e7b50ecd8983d8df01e9c2ef894c01b0eb00347aca87370c8a47f5d5
MD5 7fb1428b8a36b4917140ee99efe353d3
BLAKE2b-256 cd006dffafc70e7885610a535a7792a7079665371870099d907626fb7eb0c39c

See more details on using hashes here.

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