{"id":7597,"library":"pypac","title":"PyPAC - Python Proxy Auto-Config","description":"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.","status":"active","version":"0.17.2","language":"python","source_language":"en","source_url":"https://github.com/carsonyl/pypac","tags":["proxy","pac","wpad","network","requests","http"],"install":[{"cmd":"pip install pypac","lang":"bash","label":"Install core library"},{"cmd":"pip install pypac requests","lang":"bash","label":"Install with requests integration"}],"dependencies":[{"reason":"Required for PACSession integration with the popular requests library.","package":"requests","optional":true},{"reason":"Required for PAC script evaluation on Python 2.7.","package":"dukpy","optional":true}],"imports":[{"wrong":"from pypac import PACProxyResolver","symbol":"PACSession","correct":"from pypac import PACSession"},{"symbol":"get_pac","correct":"from pypac import get_pac"},{"symbol":"pac_context_for_url","correct":"from pypac import pac_context_for_url"}],"quickstart":{"code":"from pypac import PACSession\nimport requests\n\ntry:\n    # Auto-discovers PAC files or manually specify via PACSession(pac_url='...')\n    with PACSession() as session:\n        # Example usage with a public IP checker (ensure it's HTTP/HTTPS)\n        response = session.get('http://httpbin.org/ip')\n        response.raise_for_status()\n        print(f\"Using PACSession, IP is: {response.json()['origin']}\")\nexcept requests.exceptions.RequestException as e:\n    print(f\"Request failed: {e}\")\nexcept Exception as e:\n    print(f\"An unexpected error occurred: {e}\")\n","lang":"python","description":"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."},"warnings":[{"fix":"Rely on `PACSession` to manage proxies automatically. If you need to inspect proxy usage, check `response.request.proxy_url` after a request.","message":"When using `PACSession` for `requests` integration, do not attempt to set `session.proxies` manually. `PACSession` transparently handles proxy resolution and setting, and directly modifying `session.proxies` will override or conflict with its functionality.","severity":"gotcha","affected_versions":"All versions"},{"fix":"If auto-discovery fails, explicitly provide the PAC file URL or path: `PACSession(pac_url='http://your.proxy.com/proxy.pac')` or `PACProxyResolver(url='...')`.","message":"PAC file auto-discovery (WPAD) can be unreliable or disabled in some network environments (e.g., corporate networks, firewalls). If `PACSession` or `PACProxyResolver` cannot find a PAC file, it will fall back to a direct connection, which might not be desired.","severity":"gotcha","affected_versions":"All versions"},{"fix":"Migrate to Python 3. If Python 2.7 is mandatory, ensure `dukpy>=0.2.3` is installed and be aware of potential platform-specific issues.","message":"Python 2.7 support is deprecated and requires the `dukpy` library for PAC script evaluation, which itself has specific installation and versioning requirements for older Python. For modern use, Python 3 is strongly recommended.","severity":"gotcha","affected_versions":"0.16.2 and older on Python 2.7"}],"env_vars":null,"search_vec":"'0.17.2':54 'address':67 'annual':66 'applic':28 'auto':5,16,22 'auto-config':4,15 'auto-discoveri':21 'automat':30 'base':38 'bug':68 'cadenc':61 'complex':47 'config':6,17 'correct':35 'crucial':43 'current':51 'determin':31 'discoveri':23 'enabl':27 'enhanc':72 'environ':45 'fix':69 'function':25 'http':78 'librari':11 'logic':49 'maintain':57 'minor':64,71 'moder':59 'network':76 'pac':18,41,74 'provid':13 'proxi':3,14,20,36,48,73 'pypac':1,7 'python':2,10 'releas':60,65 'request':77 'requir':46 'script':42 'server':37 'sever':63 'use':33 'version':52 'wpad':24,75","created_at":"2026-04-16T14:05:12.071729+00:00","updated_at":"2026-04-16T14:05:12.071729+00:00","problems":null,"ecosystem":"pypi","meta_description":null,"install_score":null,"quickstart_score":null,"quickstart_tag":null,"pypi_latest":"0.18.3","cli_name":"","cli_version":null,"type":"library","homepage":null,"github":"https://github.com/carsonyl/pypac","docs":null,"changelog":null,"pypi":"https://pypi.org/project/pypac/","npm":null,"openapi_spec":null,"status_page":null,"smithery":null,"categories":["http-networking"],"base_url":null,"auth_type":null,"provenance":{"verified_status":"passing","verified_at":"2026-07-03","last_verified":"2026-07-03","next_check":"2026-08-02","install_tag":null}}