Skip to main content

OProxy

High-performance, transparent proxy that supports both TCP and UDP protocols.

OProxy

A high-performance, transparent proxy that supports both TCP and UDP protocols.

NOTE: This proxy has been designed with local API proxy in mind. Specifically, I used it to forward Ollama API requests to the remote Ollama server for applications that try to connect to the local Ollama server on localhost.

Features

  • Transparent TCP proxying
  • HTTP/HTTPS proxying without decrypting the traffic
  • Headers and other metadata fully preserved
  • Optional UDP support
  • Detailed logging capabilities
  • Configurable through environment variables
  • Support for both file and stdout logging
  • Data content logging (optional)
  • Performance optimizations with configurable buffer sizes
  • Real-time metrics monitoring
  • Automatic log rotation
  • Thread-safe metrics collection
  • Throughput and connection statistics
  • Supports standalone usage as well as being used as a Python module

IMPORTANT: The proxy will automatically log stuff to /var/log/oproxy.log if no log file is specified. Please make sure the user running the proxy has write permissions to this file or specify a different log file using the --log-file argument.

Requirements

  • Python 3.7+
  • python-dotenv
  • socket
  • threading

To build the package

  • hatchling
  • setuptools
  • wheel
  • build

Performance Features

Metrics Monitoring

The proxy now includes built-in metrics collection and monitoring:

  • Total connections tracking
  • Active connections monitoring
  • Bytes transferred counting
  • Real-time throughput calculation
  • Periodic metrics reporting (every 60 seconds)

Performance Optimizations

  • Optimized buffer sizes (65KB)
  • Non-blocking I/O using select
  • Socket buffer optimization
  • Thread-safe operations

Log Management

  • Automatic log rotation (10MB per file)
  • Up to 5 backup log files
  • UTF-8 encoding support
  • Compressed backup files

Installation

From source

  1. Clone the repository:
git clone https://github.com/tcsenpai/oproxy.git

cd oproxy
  1. Install dependencies:
pip install -r requirements.txt
  1. Copy the example environment file:
cp .env.example .env
  1. Edit the .env file with your configuration:
# Example: your Ollama server is running on 192.168.1.100:11434
PROXY_PORT=11434
TARGET_HOST=192.168.1.100
TARGET_PORT=11434

From PyPI

pip install oproxy

NOTE: Once installed through PyPI, you can use the oproxy command to start the proxy instead of python src/main.py. This is valid also for the following usage examples.

Usage

Basic TCP proxy:

python src/main.py

Customize the proxy port and/or target host and port:

python src/main.py --proxy-port 11435 --target-host 192.168.1.101 --target-port 11435

Enable logging to file:

python src/main.py --log-file=proxy.log

Enable data logging with debug level:

python src/main.py --log-file proxy.log --log-data --log-level DEBUG

Enable full data logging:

NOTE: This will log the entire payload of the request and response.

python src/main.py --log-file proxy.log --log-data --full-debug

Enable UDP support:

python src/main.py --enable-udp

View Metrics

Metrics are automatically logged to your configured log file or stdout. They include:

Performance Metrics: {
    'total_connections': 150,
    'active_connections': 3,
    'bytes_transferred': 1048576,
    'uptime_seconds': 3600,
    'bytes_per_second': 291.27
}

Command Line Arguments

  • --proxy-port: Port the proxy will listen on (default: 11434)
  • --target-host: Target host to forward traffic to (default: 192.168.1.100)
  • --target-port: Target port to forward traffic to (default: 11434)
  • --log-file: Path to the log file
  • --log-data: Enable logging of data content
  • --log-level: Set logging level (DEBUG, INFO, WARNING, ERROR, CRITICAL)
  • --enable-udp: Enable UDP proxy alongside TCP
  • --full-debug: Enable full data logging (entire payload)

Notes

  • TCP proxy runs on the port specified in .env
  • UDP proxy (if enabled) runs on PROXY_PORT + 1
  • Data logging should be used carefully as it may contain sensitive information
  • UDP support is experimental and runs as a daemon thread
  • HTTPS proxying is handled without decrypting the traffic

License

Apache-2.0 License. See the LICENSE file for details.

Metadata

Release files for oproxy 1.0.0

For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.

Source distribution (sdist)

Source distribution for oproxy 1.0.0
File Size Uploaded Provenance Actions
oproxy-1.0.0.tar.gz 1.3 MB Without provenance Details for oproxy-1.0.0.tar.gz

Release files / oproxy-1.0.0.tar.gz

Download URL oproxy-1.0.0.tar.gz
Size 1.3 MB
Tags Source
SHA-256 checksum
How to use checksums
666e2398eba1c809c664333322e9711b6a5ff98a0f681949b388a78d084577a6
BLAKE2b-256 checksum
How to use checksums
b9025c489b6c87c2f815ca8e5a035f1dba61027df2b9d994a056de65b676f693
Upload date
Uploaded using Trusted Publishing?
What is trusted publishing?
No
Uploaded via twine/5.1.1 CPython/3.10.12

Security for oproxy 1.0.0

Provenance

Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.

No provenance found

None of the files in this release were uploaded with provenance metadata.

A note on package security

PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.

To learn more about protecting yourself from malicious actors, visit our package security documentation.

Release history Release notifications | RSS feed

This release

1.0.0 This release

1 release file No provenance

Anthropic, PBC Visionary sponsor Bloomberg Visionary sponsor Hudson River Trading Visionary sponsor Meta Visionary sponsor NVIDIA Visionary sponsor Microsoft Sustainability sponsor Depot Continuous Integration AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Sentry Error logging StatusPage Status page