Metadata-Version: 2.4
Name: rotating-mitmproxy
Version: 1.3.0
Summary: Smart proxy rotator built on mitmproxy with health monitoring and failover
Author-email: importal <xychen@msn.com>
Maintainer-email: importal <xychen@msn.com>
License: MIT
Project-URL: Homepage, https://github.com/xychenmsn/rotating-mitmproxy
Project-URL: Documentation, https://github.com/xychenmsn/rotating-mitmproxy#readme
Project-URL: Repository, https://github.com/xychenmsn/rotating-mitmproxy
Project-URL: Bug Tracker, https://github.com/xychenmsn/rotating-mitmproxy/issues
Project-URL: Changelog, https://github.com/xychenmsn/rotating-mitmproxy/blob/main/CHANGELOG.md
Keywords: proxy,mitmproxy,rotation,load-balancing,web-scraping,http-proxy,proxy-server
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: License :: OSI Approved :: MIT License
Classifier: Operating System :: OS Independent
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: 3.8
Classifier: Programming Language :: Python :: 3.9
Classifier: Programming Language :: Python :: 3.10
Classifier: Programming Language :: Python :: 3.11
Classifier: Programming Language :: Python :: 3.12
Classifier: Topic :: Internet :: Proxy Servers
Classifier: Topic :: Internet :: WWW/HTTP
Classifier: Topic :: Software Development :: Libraries :: Python Modules
Classifier: Topic :: System :: Networking
Requires-Python: >=3.8
Description-Content-Type: text/markdown
License-File: LICENSE
Requires-Dist: mitmproxy>=10.0.0
Requires-Dist: click>=8.0.0
Requires-Dist: colorama>=0.4.0
Requires-Dist: requests>=2.25.0
Provides-Extra: dev
Requires-Dist: pytest>=7.0.0; extra == "dev"
Requires-Dist: pytest-cov>=4.0.0; extra == "dev"
Requires-Dist: pytest-asyncio>=0.21.0; extra == "dev"
Requires-Dist: black>=22.0.0; extra == "dev"
Requires-Dist: isort>=5.10.0; extra == "dev"
Requires-Dist: flake8>=5.0.0; extra == "dev"
Requires-Dist: mypy>=1.0.0; extra == "dev"
Requires-Dist: pre-commit>=2.20.0; extra == "dev"
Provides-Extra: docs
Requires-Dist: mkdocs>=1.4.0; extra == "docs"
Requires-Dist: mkdocs-material>=8.5.0; extra == "docs"
Requires-Dist: mkdocstrings[python]>=0.19.0; extra == "docs"
Provides-Extra: test
Requires-Dist: pytest>=7.0.0; extra == "test"
Requires-Dist: pytest-cov>=4.0.0; extra == "test"
Requires-Dist: pytest-asyncio>=0.21.0; extra == "test"
Requires-Dist: requests-mock>=1.9.0; extra == "test"
Dynamic: license-file

# Rotating MitmProxy

A smart proxy rotator built on mitmproxy that automatically rotates through multiple upstream proxies with health monitoring and failover.

## Features

- **Smart Proxy Rotation**: Round-robin, random, fastest, and smart selection strategies
- **Health Monitoring**: Real-time proxy health scoring and automatic failover
- **High Concurrency**: Handles 100+ concurrent requests efficiently
- **Multiple Formats**: Supports HTTP/SOCKS proxies with authentication
- **Web Dashboard**: Real-time statistics and monitoring interface

## Installation

```bash
pip install rotating-mitmproxy
```

## Quick Start

### 1. Create a proxy list file

```text
# proxy_list.txt
proxy1.example.com:8080
proxy2.example.com:8080
user:pass@proxy3.example.com:8080
socks5://proxy4.example.com:1080
```

### 2. Start the proxy server

```bash
python -m rotating_mitmproxy --proxy-list proxy_list.txt --port 3129
```

### 3. Use the proxy

```python
import requests

proxies = {
    'http': 'http://localhost:3129',
    'https': 'http://localhost:3129'
}

response = requests.get('https://httpbin.org/ip', proxies=proxies)
print(response.json())
```

## Command Line Options

```bash
python -m rotating_mitmproxy [OPTIONS]

Options:
  --proxy-list FILE     Path to proxy list file (required)
  --port PORT          Listen port (default: 3129)
  --strategy STRATEGY  Selection strategy: round-robin, random, fastest, smart (default: smart)
  --health-check       Enable health checking (default: enabled)
  --web-port PORT      Web dashboard port (default: 8081, 0 to disable)
  --verbose LEVEL      Verbosity: quiet, normal, verbose (default: normal)
```

## Proxy List Format

The proxy list file supports multiple formats:

```text
# HTTP proxies
proxy1.example.com:8080
user:pass@proxy2.example.com:8080

# SOCKS proxies  
socks5://proxy3.example.com:1080
socks5://user:pass@proxy4.example.com:1080

# With protocol specification
http://proxy5.example.com:8080
https://proxy6.example.com:8080
```

## Selection Strategies

- **round-robin**: Cycles through proxies in order
- **random**: Selects proxies randomly
- **fastest**: Prefers proxies with lowest response times
- **smart**: Combines health scoring with performance metrics (recommended)

## Web Dashboard

Access the web dashboard at `http://localhost:8081` to view:

- Real-time proxy statistics
- Health scores and response times
- Success/failure rates
- Active connections

## Programmatic Usage

```python
from rotating_mitmproxy import RotatingProxy

# Start proxy server
proxy = RotatingProxy(
    proxy_list_file="proxy_list.txt",
    port=3129,
    strategy="smart"
)

proxy.start()

# Use with requests
import requests
proxies = {'http': 'http://localhost:3129', 'https': 'http://localhost:3129'}
response = requests.get('https://httpbin.org/ip', proxies=proxies)

# Stop server
proxy.stop()
```

## Health Monitoring

The system automatically monitors proxy health by:

- Tracking response times and success rates
- Scoring proxies based on performance
- Temporarily disabling failed proxies
- Gradually re-enabling recovered proxies

## Configuration

Environment variables:

```bash
export ROTATING_PROXY_LIST="proxy_list.txt"
export ROTATING_PROXY_PORT="3129"
export ROTATING_PROXY_STRATEGY="smart"
export ROTATING_PROXY_WEB_PORT="8081"
```

## Testing

```bash
# Run tests
python -m pytest tests/ -v

# Test with example
python examples/basic_example.py
```

## License

MIT License - see LICENSE file for details.
