proxywhirl.cli¶
Command-line interface for ProxyWhirl.
This module provides a Typer-based CLI for proxy rotation operations. Supports multiple output formats (text, JSON, CSV) with TTY-aware rendering.
Classes¶
Shared context for all CLI commands. |
|
Supported output formats for CLI commands. |
Functions¶
|
Audit proxy sources for broken or stale entries. |
|
Clean up stale and dead proxies from the database. |
|
Manage CLI configuration (show/get/set/init). |
|
Show database statistics. |
|
Export proxy data and statistics for web dashboard. |
|
Fetch proxies from configured sources. |
Get the current command context. |
|
|
Check health of all proxies in the pool. |
|
ProxyWhirl CLI - Advanced proxy rotation library. |
|
Manage the proxy pool (list/add/remove/test). |
|
Render data as CSV to stdout. |
|
Render data as JSON to stdout. |
|
Render output in the configured format. |
|
Render data as formatted text using Rich. |
|
Make an HTTP request through a rotating proxy. |
|
Setup GeoIP database for proxy geolocation. |
|
List and validate proxy sources. |
|
Show proxy pool statistics. |
|
Launch the interactive Terminal User Interface (TUI). |
|
Validate a target URL to prevent SSRF attacks. |
Module Contents¶
- class proxywhirl.cli.OutputFormat[source]¶
-
Supported output formats for CLI commands.
Initialize self. See help(type(self)) for accurate signature.
- proxywhirl.cli.audit(timeout=typer.Option(15.0, '--timeout', '-t', help='Timeout per source in seconds'), concurrency=typer.Option(20, '--concurrency', '-j', help='Maximum concurrent requests'), retries=typer.Option(3, '--retries', '-r', help='Number of retries for each source before marking as broken'), fix=typer.Option(False, '--fix', help='Remove broken sources from sources.py (creates backup)'), dry_run=typer.Option(False, '--dry-run', '-n', help='Show what would be removed without making changes (implies --fix)'), min_proxies=typer.Option(1, '--min-proxies', help='Minimum proxies required for a source to be considered healthy'), protocol=typer.Option(None, '--protocol', '-p', help='Only audit sources of specific protocol (http, socks4, socks5)'))[source]¶
Audit proxy sources for broken or stale entries.
Tests each source by fetching from it and checking if it returns valid proxies. A source is considered “broken” if:
It returns a non-200 status code
It times out after retries
It returns 0 proxies (or less than –min-proxies)
It returns malformed/unparseable content
Use –fix to automatically remove broken sources from sources.py. A backup file will be created before any modifications.
Examples
proxywhirl sources audit # Audit all sources proxywhirl sources audit –protocol http # Only HTTP sources proxywhirl sources audit –fix # Remove broken sources proxywhirl sources audit –dry-run # Preview what would be removed proxywhirl sources audit –retries 5 # More retries before marking broken proxywhirl sources audit -j 50 -t 30 # Higher concurrency, longer timeout
- proxywhirl.cli.cleanup(db=typer.Option(Path('proxywhirl.db'), '--db', help='Path to SQLite database'), stale_days=typer.Option(7, '--stale-days', help='Remove proxies not validated in N days'), execute=typer.Option(False, '--execute', help='Actually perform cleanup (dry run by default)'))[source]¶
Clean up stale and dead proxies from the database.
By default, performs a dry run showing what would be removed. Use –execute to actually perform the cleanup.
Examples
proxywhirl cleanup # Dry run proxywhirl cleanup –execute # Actually remove proxywhirl cleanup –stale-days 14 # Remove if not validated in 14 days
- Parameters:
db (pathlib.Path)
stale_days (int)
execute (bool)
- Return type:
None
- proxywhirl.cli.config(action=typer.Argument(..., help='Action: show, set, get, init'), key=typer.Argument(None, help='Config key (for get/set)'), value=typer.Argument(None, help='Config value (for set)'))[source]¶
Manage CLI configuration (show/get/set/init).
Examples
proxywhirl config show proxywhirl config get rotation_strategy proxywhirl config set rotation_strategy random proxywhirl config init
- proxywhirl.cli.db_stats(db=typer.Option(Path('proxywhirl.db'), '--db', help='Path to SQLite database'))[source]¶
Show database statistics.
Displays comprehensive statistics about the proxy database including counts by health status, protocol, and validation metrics.
Examples
proxywhirl db-stats proxywhirl db-stats –db custom.db
- Parameters:
db (pathlib.Path)
- Return type:
None
- proxywhirl.cli.export(output=typer.Option(Path('docs/proxy-lists'), '--output', '-o', help='Output directory for exported files'), db=typer.Option(Path('proxywhirl.db'), '--db', help='Path to SQLite database'), stats_only=typer.Option(False, '--stats-only', help='Only export statistics'), proxies_only=typer.Option(False, '--proxies-only', help='Only export proxy list'))[source]¶
Export proxy data and statistics for web dashboard.
Examples
proxywhirl export proxywhirl export –output ./exports proxywhirl export –stats-only proxywhirl export –proxies-only –db custom.db
- Parameters:
output (pathlib.Path)
db (pathlib.Path)
stats_only (bool)
proxies_only (bool)
- Return type:
None
- proxywhirl.cli.fetch(no_validate=typer.Option(False, '--no-validate', help='Skip proxy validation'), no_save_db=typer.Option(False, '--no-save-db', help="Don't save to database"), no_export=typer.Option(False, '--no-export', help="Don't export to files"), timeout=typer.Option(10, '--timeout', help='Validation timeout in seconds'), concurrency=typer.Option(100, '--concurrency', help='Concurrent validation requests'), revalidate=typer.Option(False, '--revalidate', '-R', help='Re-validate existing proxies in database instead of fetching new ones'), prune_failed=typer.Option(False, '--prune-failed', help='Delete failed proxies instead of marking them as DEAD (use with --revalidate)'), https_validate=typer.Option(True, '--https-validate/--no-https-validate', help='After fetching, test valid HTTP proxies for HTTPS/CONNECT support and add them as https:// entries'), https_timeout=typer.Option(8, '--https-timeout', help='Per-stage timeout in seconds for HTTPS CONNECT tests (default 8, higher = more found but slower)'), https_max=typer.Option(2000, '--https-max', help='Maximum HTTPS-capable proxies to collect during dual-validation (0 = unlimited)'))[source]¶
Fetch proxies from configured sources.
Examples
proxywhirl fetch proxywhirl fetch –no-validate proxywhirl fetch –timeout 5 –concurrency 50 proxywhirl fetch –revalidate –timeout 5 –concurrency 2000 proxywhirl fetch –revalidate –prune-failed proxywhirl fetch –no-https-validate proxywhirl fetch –https-timeout 10
- proxywhirl.cli.get_context()[source]¶
Get the current command context.
- Returns:
The active command context
- Return type:
- Raises:
typer.Exit – If context is not initialized
- proxywhirl.cli.health(continuous=typer.Option(False, '--continuous', '-C', help='Run continuously'), interval=typer.Option(None, '--interval', '-i', help='Check interval in seconds'), target_url=typer.Option(None, '--target-url', '-t', help='URL to test proxy connectivity against (http/https only)'), allow_private=typer.Option(False, '--allow-private', help='Allow testing against localhost/private IPs (use with caution)'))[source]¶
Check health of all proxies in the pool.
Examples
proxywhirl health proxywhirl health –continuous –interval 60 proxywhirl health -C -i 60 proxywhirl health –target-url https://api.example.com proxywhirl health –target-url http://localhost:8080 –allow-private
- proxywhirl.cli.main(ctx, config_file=typer.Option(None, '--config', '-c', help='Path to configuration file (TOML). Auto-discovered if not provided.', exists=True, dir_okay=False, resolve_path=True), format=typer.Option(OutputFormat.TEXT, '--format', '-f', help='Output format (text/json/csv)', case_sensitive=False), verbose=typer.Option(False, '--verbose', '-v', help='Enable verbose logging'), no_lock=typer.Option(False, '--no-lock', help='Disable file locking (use with caution)'))[source]¶
ProxyWhirl CLI - Advanced proxy rotation library.
Global options apply to all subcommands. Configuration is auto-discovered from:
Project directory: ./.proxywhirl.toml
User directory: ~/.config/proxywhirl/config.toml (Linux/Mac)
Defaults: In-memory configuration
- Parameters:
ctx (typer.Context)
config_file (pathlib.Path | None)
format (OutputFormat)
verbose (bool)
no_lock (bool)
- Return type:
None
- proxywhirl.cli.pool(action=typer.Argument(..., help='Action: list, add, remove, test'), proxy=typer.Argument(None, help='Proxy URL (for add/remove/test actions)'), username=typer.Option(None, '--username', '-u', help='Proxy username'), password=typer.Option(None, '--password', '-p', help='Proxy password'), target_url=typer.Option('https://httpbin.org/ip', '--target-url', help='Target URL for proxy testing (http/https only)'), allow_private=typer.Option(False, '--allow-private', help='Allow testing against localhost/private IPs (use with caution)'))[source]¶
Manage the proxy pool (list/add/remove/test).
Examples
proxywhirl pool list proxywhirl pool add http://proxy1.com:8080 proxywhirl pool remove http://proxy1.com:8080 proxywhirl pool test http://proxy1.com:8080 proxywhirl pool test http://proxy1.com:8080 –target-url https://api.example.com
- proxywhirl.cli.render_output(context, data)[source]¶
Render output in the configured format.
- Parameters:
context (CommandContext) – Command context with format settings
- Return type:
None
- proxywhirl.cli.request(url=typer.Argument(..., help='Target URL to request'), method=typer.Option('GET', '--method', '-X', help='HTTP method (GET/POST/etc)'), headers=typer.Option(None, '--header', '-H', help="Custom headers (format: 'Key: Value')"), data=typer.Option(None, '--data', '-d', help='Request body data'), proxy=typer.Option(None, '--proxy', '-p', help='Specific proxy URL (overrides rotation)'), max_retries=typer.Option(None, '--retries', help='Max retry attempts (overrides config)'), allow_private=typer.Option(False, '--allow-private', help='Allow requests to localhost/private IPs (use with caution)'))[source]¶
Make an HTTP request through a rotating proxy.
Examples
proxywhirl request https://api.example.com proxywhirl request -X POST -d ‘{“key”:”value”}’ https://api.example.com proxywhirl request -H “Authorization: Bearer token” https://api.example.com proxywhirl request http://localhost:8080 –allow-private
- proxywhirl.cli.setup_geoip(check=typer.Option(False, '--check', help='Check if GeoIP database is available'))[source]¶
Setup GeoIP database for proxy geolocation.
Examples
proxywhirl setup-geoip proxywhirl setup-geoip –check
- Parameters:
check (bool)
- Return type:
None
- proxywhirl.cli.sources_callback(ctx, validate=typer.Option(False, '--validate', '-v', help='Validate all sources and check for stale/broken ones'), timeout=typer.Option(15.0, '--timeout', '-t', help='Timeout per source in seconds'), concurrency=typer.Option(20, '--concurrency', '-j', help='Maximum concurrent requests'), fail_on_unhealthy=typer.Option(False, '--fail-on-unhealthy', '-f', help='Exit with error code if any sources are unhealthy (for CI)'))[source]¶
List and validate proxy sources.
By default, lists all configured proxy sources with their URLs. Use –validate to check which sources are working and which are stale.
Examples
proxywhirl sources # List all sources proxywhirl sources –validate # Validate all sources proxywhirl sources -v -f # Validate and fail if any unhealthy (CI mode) proxywhirl sources audit # Full audit with detailed results proxywhirl sources audit –fix # Audit and remove broken sources
- proxywhirl.cli.stats(retry=typer.Option(False, '--retry', help='Show retry metrics'), circuit_breaker=typer.Option(False, '--circuit-breaker', help='Show circuit breaker events'), hours=typer.Option(24, '--hours', '-r', help='Time window in hours'))[source]¶
Show proxy pool statistics.
Examples
proxywhirl stats proxywhirl stats –retry proxywhirl stats –circuit-breaker proxywhirl stats –hours 12
- proxywhirl.cli.tui()[source]¶
Launch the interactive Terminal User Interface (TUI).
- The TUI provides a full-featured dashboard for managing proxies with:
Real-time metrics and sparkline visualizations
Proxy table with filtering, sorting, and health status
Manual proxy management (add/remove)
Health checks with progress bars
Circuit breaker monitoring
Request testing with multiple HTTP methods
Export functionality with format preview
- Keyboard shortcuts:
j/k - Navigate up/down g/G - Jump to first/last Enter - View proxy details c - Copy proxy URL t - Quick test proxy / - Focus search ? - Show help modal Ctrl+A - Toggle auto-refresh Ctrl+R - Refresh all data Ctrl+F - Fetch tab Ctrl+E - Export tab Ctrl+T - Test tab Ctrl+H - Health tab
Examples
proxywhirl tui
- Return type:
None