Proxy auto-config and auto-discovery for Python.
PyPAC is a pure-Python library for finding proxy auto-config (PAC) files and making HTTP requests that respect them. PAC files are often used in organizations that need fine-grained and centralized control of proxy settings.
PyPAC provides a subclass of a Requests Session, so you can start using it immediately, with any PAC file transparently discovered and honoured:
>>> from pypac import PACSession >>> session = PACSession() >>> session.get('http://example.org') ...
If a PAC file isn’t found, then PACSession acts exactly like a regular Session.
PyPAC can find PAC files according to the DNS portion of the Web Proxy Auto-Discovery (WPAD) protocol. On Windows, PyPAC can also obtain the PAC file URL from the Internet Options dialog, via the registry.
If you’re looking to add basic PAC functionality to a library that you’re using, try the pac_context_for_url() context manager:
from pypac import pac_context_for_url import boto3 with pac_context_for_url('https://example.amazonaws.com'): client = boto3.client('sqs') client.list_queues()
This sets up proxy environment variables at the start of the scope, based on any auto-discovered PAC and the given URL. pac_context_for_url() should work for any library that honours proxy environment variables.
- The same Requests API that you already know and love
- Honour PAC setting from Windows Internet Options
- Follow DNS Web Proxy Auto-Discovery protocol
- Proxy authentication pass-through
- Proxy failover and load balancing
- Generic components for adding PAC support to other code
PyPAC supports Python 2.7 and 3.4+.
Install PyPAC using pip:
$ pip install pypac
PyPAC’s documentation is available at http://pypac.readthedocs.io/.
- Defer Js2Py import until it’s needed. It uses a lot of memory. See #20 for details.
- Add support for file:// PAC URLs on Windows.
- Drop support for Python 3.3.
- Add doc explaining how to use pac_context_for_url.
- Internal changes to dev and test processes.
- Add pac_context_for_url, a context manager that adds basic PAC functionality through proxy environment variables.
- Accept PAC files served with no Content-Type header.
- Add recursion_limit keyword argument to PACSession and PACFile. The default is an arbitrarily high value (10000), which should cover most applications.
- Exclude port numbers from host passed to FindProxyForURL(url, host).
- Update GitHub username.
- Windows: Get system auto-proxy config setting using winreg module.
- Windows: Accept local filesystem paths from system proxy auto-config setting.
- Raise PacComplexityError when recursion limit is hit while parsing PAC file.
- Support setting PACSession.proxy_auth and ProxyResolver.proxy_auth after constructing an instance.
- Narrative docs.
- Require Js2Py >= 0.43 for Python 3.6 support, and to avoid needing to monkeypatch out pyimport.
- First release.