Registry / http-networking / pypac
library0.18.3pypypi✓ verified 82d ago

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.

pip install pypac
INSTALL
IMPORT
SIG · PYPAC
P
pypac
http-networkingpythonv0.18.3
Install
2.5s avg
Import
Disk
31MB
Pass rate
10/ 10
Env Coverage10 / 10
glibc
3.93.13
musl
3.93.13
Install & Compatibility
Where this runs
tested against v0.18.3 · pip install
no network on importno background threads
Install × environment matrix
Each cell = how many times install + import succeeded across repeated harness runs. Partial = flaky.
glibc = Debian/Ubuntu slim · musl = Alpine Linux
musl
py 3.103.940 runs
installs and imports cleanly · install 0.0s · import 0.000s · 31.7MB
glibc
py 3.103.940 runs
installs and imports cleanly · install 2.5s · import 0.000s · 34MB
31MB installed
● package 31MB
Code
Verified usage

Verified import paths — ran on the pinned version, not inferred.

PACSession
from pypac import PACSession
from pypac import PACProxyResolver
get_pac
from pypac import get_pac
pac_context_for_url
from pypac import pac_context_for_url

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}")
Debug
Known issues
gotchaWhen 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.
fix
Rely on `PACSession` to manage proxies automatically. If you need to inspect proxy usage, check `response.request.proxy_url` after a request.
affects: All versions
gotchaPAC 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.
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='...')`.
affects: All versions
gotchaPython 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.
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.
affects: 0.16.2 and older on Python 2.7
Upgrade
Version history
0.18.3latest on PyPI · released May 15, 2026
Audit
Dependencies
requestsoptionalRequired for PACSession integration with the popular requests library.
dukpyoptionalRequired for PAC script evaluation on Python 2.7.
Agent activity
12 hits · last 30 days
node
12
Resources
pypac — pip install pypac · libregistry