Skip to main content

Proxy auto-config and auto-discovery for Python.

Project description

PyPAC: Proxy auto-config for Python

https://img.shields.io/pypi/v/pypac.svg?maxAge=2592000 https://img.shields.io/travis/rbcarson/pypac.svg?maxAge=2592000 https://ci.appveyor.com/api/projects/status/y7nxvu2feu87i39t/branch/master?svg=true https://img.shields.io/coveralls/rbcarson/pypac/HEAD.svg?maxAge=2592000 https://img.shields.io/codacy/grade/71ac103b491d44efb94976ca5ea5d89c.svg?maxAge=2592000

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 supports Python 2.7 and 3.3+.

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.

Proxy authentication

Basic proxy authentication can be specified in the PACSession constructor:

>>> from pypac import PACSession
>>> from requests.auth import HTTPProxyAuth
>>> session = PACSession(proxy_auth=HTTPProxyAuth('user', 'password'))
>>> session.get('http://example.org')
...

To use NTLM authentication with proxies, install requests-ntlm and set PACSession.auth to an HttpNtlmAuth instance.

Security

PAC files are JavaScript. PyPAC uses Js2Py to parse and execute JavaScript. Js2Py was not designed for handling untrusted JavaScript, and so it is unclear whether the handling of PAC files is sufficiently sandboxed to prevent untrusted Python code execution.

When looking for a PAC file using DNS WPAD, the local machine’s fully-qualified hostname is checked against the Mozilla Public Suffix List to prevent requesting any PAC files outside the scope of the organization. If the hostname’s TLD isn’t in the Public Suffix List, then everything up to the final node is used in the search path. For example, a hostname of foo.bar.local will result in a search for a PAC file from wpad.bar.local and wpad.local.

PyPAC uses the tld library to match TLDs.

What’s missing

The DHCP portion of the Web Proxy Auto-Discovery (WPAD) protocol is not implemented.

PyPAC currently works with Requests by including a subclass of Session. No ready-to-use solutions are included for other HTTP libraries, though PyPAC has all the building blocks needed to make one easily.

Pull requests to add these features are welcome.

History

0.2.1 (2017-01-19)

  • Require Js2Py >= 0.43 for Python 3.6 support, and to avoid needing to monkeypatch out pyimport.

0.1.0 (2016-06-12)

  • First release.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distributions

No source distribution files available for this release.See tutorial on generating distribution archives.

Built Distribution

pypac-0.2.1-py2.py3-none-any.whl (17.9 kB view details)

Uploaded Python 2 Python 3

File details

Details for the file pypac-0.2.1-py2.py3-none-any.whl.

File metadata

File hashes

Hashes for pypac-0.2.1-py2.py3-none-any.whl
Algorithm Hash digest
SHA256 a882b52103beb00b879cf70b272221b123e79af6f92388010a64065411a3cb59
MD5 452160a4d4fb7e36f87906692416881f
BLAKE2b-256 25ad565928e1451a83ae7ed0587b0f077e56ea74e6033d50eda446519cb14142

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page