Smart proxy rotator built on mitmproxy with intelligent health monitoring and failover
Project description
๐ Rotating mitmproxy
A production-ready smart proxy rotator built on mitmproxy that automatically rotates through multiple upstream proxies with intelligent health monitoring, failover, and exceptional concurrency support.
โจ Key Features
๐ Exceptional Performance
- 100+ concurrent requests handled perfectly by single process
- Thread-safe proxy rotation with zero race conditions
- Manual proxy approach bypassing mitmproxy's upstream limitations
- Sub-second response times with intelligent proxy selection
๐ Smart Proxy Rotation
- 4 selection strategies: round-robin, random, fastest, smart
- Automatic health monitoring with real-time scoring
- Intelligent failover and gradual recovery
- Configurable thresholds for failure detection and timeouts
๐ Comprehensive Monitoring
- Real-time statistics with web dashboard
- Health scoring and performance metrics
- Success rate tracking and response time analysis
- JSON API endpoints for programmatic access
๐ก๏ธ Production Ready
- Robust error handling and recovery mechanisms
- Comprehensive logging with configurable verbosity levels
- Flexible configuration supporting multiple proxy formats
- Authentication support for HTTP/SOCKS proxies
๐ฆ Installation
From Source (Recommended)
git clone https://github.com/yourusername/rotating-mitmproxy.git
cd rotating-mitmproxy
pip install -e .
From PyPI (Coming Soon)
pip install rotating-mitmproxy
๐ Quick Start
1. Create Proxy List
Create a proxies.txt file with your proxy servers:
proxy1.example.com:8080
proxy2.example.com:8080
user:pass@proxy3.example.com:8080
socks5://proxy4.example.com:1080
2. Start the Server
# Basic usage - handles 100+ concurrent requests perfectly
rotating-mitmproxy --proxy-list proxies.txt --port 9090
# With web monitoring interface
rotating-mitmproxy --proxy-list proxies.txt --port 9090 --web-port 9091
# With different strategies
rotating-mitmproxy --proxy-list proxies.txt --port 9090 --strategy round_robin
rotating-mitmproxy --proxy-list proxies.txt --port 9090 --strategy smart
rotating-mitmproxy --proxy-list proxies.txt --port 9090 --strategy random
# Web interface mode (for development/debugging)
rotating-mitmproxy-web --proxy-list proxies.txt --port 9090 --web-port 9091
3. Monitor Performance
- Statistics API: http://localhost:9091/stats
- Health check: http://localhost:9091/health
- Web dashboard: http://localhost:9091 (web mode only)
4. Use the Proxy
# Test with curl
curl -x http://localhost:9090 https://httpbin.org/ip
# Set environment variables
export HTTP_PROXY=http://localhost:9090
export HTTPS_PROXY=http://localhost:9090
import requests
# Configure your HTTP client to use the rotating proxy
proxies = {
'http': 'http://localhost:9090',
'https': 'http://localhost:9090'
}
# All requests automatically rotate through your proxy list
response = requests.get('https://httpbin.org/ip', proxies=proxies)
print(response.json()) # Shows different IP each time!
๐ก Advanced Usage
Configuration Options
# Smart selection with custom health thresholds
rotating-mitmproxy \
--proxy-list proxies.txt \
--port 9090 \
--strategy smart \
--min-health 0.3 \
--failure-timeout 300 \
--max-failures 5 \
--enable-monitoring
# High-performance round-robin for load balancing
rotating-mitmproxy \
--proxy-list proxies.txt \
--port 9090 \
--strategy round_robin \
--web-port 9091 \
--log-level INFO
๐ Performance & Concurrency
Exceptional Concurrency Support
- โ 100+ concurrent requests handled perfectly by single process
- โ Thread-safe proxy rotation with zero race conditions
- โ Sub-second response times with intelligent caching
- โ Production tested with real-world traffic loads
Benchmark Results
# 100 concurrent requests test results:
โ
100/100 successful requests (100% success rate)
๐ 50+ unique proxy IPs used (perfect rotation)
โก Average response time: 1.2s
โฑ๏ธ Total completion time: 21s (true parallelism)
๐ Monitoring & Logging
Verbose Logging Levels
Control output detail with --verbose option:
--verbose quiet
- Production environments: Only errors and warnings
- Automated scripts: Minimal noise
--verbose stats (default)
- General monitoring: Periodic statistics every 30 seconds
๐ STATS: 45 requests, 91.1% success, 8/10 healthy proxies
#1 proxy1.com:8080: 0.95 health, 94.4% success
--verbose requests
- Development/debugging: Show each request/response
โ GET https://httpbin.org/ip via proxy1.com:8080
โ 200 https://httpbin.org/ip (0.45s)
--verbose debug
- Deep debugging: Everything including headers and internals
๐ ๏ธ Available Commands
| Command | Purpose | Use Case |
|---|---|---|
rotating-mitmproxy |
Main proxy server | Production, high-performance proxy rotation |
rotating-mitmproxy-web |
Web interface mode | Development, debugging, visual monitoring |
rotating-mitmproxy-stats |
Statistics display | Quick stats overview |
rotating-mitmproxy-validate |
Proxy validation | Test proxy list before deployment |
โ๏ธ Configuration Options
| Option | Description | Default |
|---|---|---|
--proxy-list |
Path to proxy list file (required) | Required |
--port |
Listen port | 9090 |
--strategy |
Selection strategy (round_robin, random, fastest, smart) | smart |
--web-port |
Web interface port | 9091 |
--min-health |
Minimum health score for proxy selection | 0.2 |
--failure-timeout |
Timeout before retrying failed proxy (seconds) | 300 |
--max-failures |
Max failures before proxy timeout | 5 |
--stats-interval |
Statistics logging interval (seconds) | 60 |
--enable-monitoring |
Enable detailed monitoring and logging | false |
--log-level |
Logging level (DEBUG, INFO, WARNING, ERROR) | INFO |
Proxy List Format
The proxy list file supports multiple formats:
# Simple format
proxy1.com:8080
proxy2.com:8080
# With authentication
user:pass@proxy3.com:8080
# With protocol specification
http://proxy4.com:8080
socks5://proxy5.com:1080
# Comments and empty lines are ignored
# proxy6.com:8080 (commented out)
๐ฏ Selection Strategies
Round Robin (Recommended for Load Balancing)
- Perfect for: Even distribution across all proxies
- Use case: Load balancing, fair usage distribution
- Performance: Excellent with 100+ concurrent requests
Random
- Perfect for: Unpredictable traffic patterns
- Use case: Avoiding detection, randomized requests
- Performance: Good randomization with healthy proxy filtering
Fastest
- Perfect for: Performance-critical applications
- Use case: Speed-optimized requests, latency-sensitive apps
- Performance: Automatically selects lowest-latency proxies
Smart (Default)
- Perfect for: Balanced performance and reliability
- Combines multiple factors:
- Health score (30%)
- Success rate (25%)
- Response time (20%)
- Recent performance (25%)
๐ Monitoring & APIs
Statistics API
# Get detailed proxy statistics
curl http://localhost:9091/stats
# Quick health check
curl http://localhost:9091/health
Web Interface
# Development/debugging mode with visual interface
rotating-mitmproxy-web --proxy-list proxies.txt --port 9090 --web-port 9091
- Statistics Dashboard: http://localhost:9091/stats
- Health Monitoring: http://localhost:9091/health
- mitmproxy Web UI: http://localhost:9091 (web mode only)
Detailed Request Logging
# Enable comprehensive monitoring with JSON logging
rotating-mitmproxy --proxy-list proxies.txt \
--port 9090 \
--enable-monitoring \
--monitoring-log detailed_requests.jsonl
๐ Production Deployment
Docker Deployment
FROM python:3.9-slim
WORKDIR /app
COPY . .
RUN pip install -e .
EXPOSE 9090 9091
CMD ["rotating-mitmproxy", "--proxy-list", "proxies.txt", "--port", "9090", "--web-port", "9091"]
Systemd Service
[Unit]
Description=Rotating mitmproxy
After=network.target
[Service]
Type=simple
User=proxy
WorkingDirectory=/opt/rotating-mitmproxy
ExecStart=/usr/local/bin/rotating-mitmproxy --proxy-list proxies.txt --port 9090
Restart=always
RestartSec=10
[Install]
WantedBy=multi-user.target
Performance Tuning
# High-performance production setup
rotating-mitmproxy \
--proxy-list proxies.txt \
--port 9090 \
--strategy round_robin \
--min-health 0.8 \
--max-failures 3 \
--failure-timeout 180 \
--log-level WARNING
## ๐งช Testing & Examples
### **Run Tests**
```bash
# Run all tests
python -m pytest tests/ -v
# Run with coverage
python -m pytest tests/ --cov=rotating_mitmproxy --cov-report=html
# Test specific components
python -m pytest tests/test_strategies.py -v # Strategy tests
python -m pytest tests/test_config.py -v # Configuration tests
Programmatic Access
import requests
# Get comprehensive proxy statistics
stats = requests.get('http://localhost:9091/stats').json()
print(f"Healthy proxies: {stats['healthy_proxies']}/{stats['total_proxies']}")
print(f"Success rate: {stats['success_rate']:.2%}")
# Monitor individual proxy performance
for proxy in stats['proxy_details']:
print(f"{proxy['id']}: {proxy['health_score']:.2f} health, "
f"{proxy['success_rate']:.2%} success")
Examples
See the examples/ directory for complete usage examples:
basic_usage.py- Simple proxy rotationhigh_concurrency_config.py- High-performance setupadvanced_monitoring.py- Comprehensive monitoringdebug_concurrency.py- Concurrency testingdemo_new_features.py- Feature demonstrationstest_verbose_levels.py- Logging level examples
๐ Requirements
- Python 3.8+
- mitmproxy 10.0+
- asyncio support
๐ค Contributing
Contributions welcome! Please see CONTRIBUTING.md for guidelines.
๐ License
MIT License - see LICENSE file for details.
๐ Support
- ๐ Documentation: Complete usage guide above
- ๐ Issues: GitHub Issues
- ๐ฌ Discussions: GitHub Discussions
๐ Rotating-mitmproxy: Production-ready proxy rotation with exceptional concurrency support! ๐
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
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 rotating_mitmproxy-1.0.1.tar.gz.
File metadata
- Download URL: rotating_mitmproxy-1.0.1.tar.gz
- Upload date:
- Size: 32.8 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
d69d219e11e8ac4cff3451be1eed3aead7088a7e391e3f159332da4ad8305152
|
|
| MD5 |
377f94afd75f573add4778f350138224
|
|
| BLAKE2b-256 |
0ba0d4c50bc0410ab9092476569325894e3dc9cc849b946d488653efba6d3890
|
File details
Details for the file rotating_mitmproxy-1.0.1-py3-none-any.whl.
File metadata
- Download URL: rotating_mitmproxy-1.0.1-py3-none-any.whl
- Upload date:
- Size: 26.0 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.1.0 CPython/3.13.5
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
35ff423396bd68e3071d2f4d853f09aeb6e433d2df71c6a8dea3fa6c66a7fabd
|
|
| MD5 |
62a6d4e6f27a3fbb5270bcc1e9b7d130
|
|
| BLAKE2b-256 |
2191b0709a199a4415f4719bbb636a95438dab6487fa047abdfdb383a30f208b
|