Pypac
Find and use proxy auto-config (PAC) files with Python and Requests.
Install / Use
/learn @carsonyl/PypacREADME
PyPAC: Proxy auto-config for Python
.. image:: https://img.shields.io/pypi/v/pypac.svg?maxAge=2592000 :target: https://pypi.python.org/pypi/pypac .. image:: https://img.shields.io/pypi/pyversions/pypac.svg :target: https://pypi.python.org/pypi/pypac .. image:: https://readthedocs.org/projects/pypac/badge/?version=latest :target: https://pypac.readthedocs.io/en/latest/?badge=latest .. image:: https://github.com/carsonyl/pypac/actions/workflows/tests.yml/badge.svg :target: https://github.com/carsonyl/pypac/actions/workflows/tests.yml
PyPAC is a 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 can find PAC files according to the DNS portion of the Web Proxy Auto-Discovery (WPAD)_ protocol.
On Windows, PyPAC will automatically get the PAC file URL from the Internet Options dialog.
On macOS, PyPAC will automatically get the PAC file URL from System Preferences.
.. _proxy auto-config (PAC): https://en.wikipedia.org/wiki/Proxy_auto-config
PyPAC provides a subclass of a Requests <https://docs.python-requests.org/en/latest/>_ Session,
so you can start using it immediately, with any PAC file transparently discovered and honoured:
.. code-block:: python
>>> from pypac import PACSession
>>> session = PACSession()
>>> session.get('http://example.org')
...
If a PAC file isn't found, then PACSession behaves like a regular Session.
.. _Web Proxy Auto-Discovery (WPAD): https://en.wikipedia.org/wiki/Web_Proxy_Autodiscovery_Protocol
If you're looking to add basic PAC functionality to a library that you're using,
try the pac_context_for_url() context manager:
.. code-block:: python
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.
Features
- The same Requests API that you already know and love
- Honour PAC setting from Windows Internet Options and macOS System Preferences
- 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.5+.
Installation
Install PyPAC using pip <https://pip.pypa.io>_::
$ python -m pip install pypac
Documentation
PyPAC's documentation is available at https://pypac.readthedocs.io/.
Related Skills
node-connect
350.1kDiagnose OpenClaw node connection and pairing failures for Android, iOS, and macOS companion apps
frontend-design
109.9kCreate distinctive, production-grade frontend interfaces with high design quality. Use this skill when the user asks to build web components, pages, or applications. Generates creative, polished code that avoids generic AI aesthetics.
openai-whisper-api
350.1kTranscribe audio via OpenAI Audio Transcriptions API (Whisper).
qqbot-media
350.1kQQBot 富媒体收发能力。使用 <qqmedia> 标签,系统根据文件扩展名自动识别类型(图片/语音/视频/文件)。
