PyPAC - Python Proxy Auto-Config

0.17.2 · active · verified Thu Apr 16

PyPAC is a Python library that provides proxy auto-config (PAC) and proxy auto-discovery (WPAD) functionality. It enables applications to automatically determine and use the correct proxy server based on a PAC script, crucial for environments requiring complex proxy logic. The current version is 0.17.2, and it maintains a moderate release cadence, with several minor releases annually addressing bug fixes and minor enhancements.

Common errors

Warnings

Install

Imports

Quickstart

This quickstart demonstrates how to use PyPAC's `PACSession` to automatically resolve and apply proxy settings for `requests` calls. `PACSession` handles PAC file discovery (e.g., via WPAD) and proxy resolution transparently. If no PAC file is found via auto-discovery, it will default to direct connections.

from pypac import PACSession
import requests

try:
    # Auto-discovers PAC files or manually specify via PACSession(pac_url='...')
    with PACSession() as session:
        # Example usage with a public IP checker (ensure it's HTTP/HTTPS)
        response = session.get('http://httpbin.org/ip')
        response.raise_for_status()
        print(f"Using PACSession, IP is: {response.json()['origin']}")
except requests.exceptions.RequestException as e:
    print(f"Request failed: {e}")
except Exception as e:
    print(f"An unexpected error occurred: {e}")

view raw JSON →