Metadata-Version: 2.4
Name: proxy-watch
Version: 0.3.0
Classifier: Development Status :: 4 - Beta
Classifier: Intended Audience :: Developers
Classifier: Operating System :: Microsoft :: Windows
Classifier: Operating System :: MacOS
Classifier: Operating System :: POSIX :: Linux
Classifier: Programming Language :: Python :: 3
Classifier: Programming Language :: Python :: Free Threading :: 2 - Beta
Classifier: Programming Language :: Rust
Classifier: Topic :: Internet :: Proxy Servers
Classifier: Typing :: Typed
License-File: LICENSE-APACHE
License-File: LICENSE-MIT
License-File: THIRD-PARTY-LICENSES.txt
Summary: The operating system's proxy settings, layered with *_proxy, and the route each URL takes under them, for Python
Keywords: proxy,pac,wpad,http_proxy,system-proxy,proxy-settings,no_proxy
License-Expression: (MIT OR Apache-2.0) AND Unicode-3.0 AND Zlib AND ISC AND CC0-1.0
Requires-Python: >=3.10
Description-Content-Type: text/markdown; charset=UTF-8; variant=GFM
Project-URL: Funding, https://github.com/sponsors/gnoays
Project-URL: Issues, https://github.com/gnoays/proxy-watch/issues
Project-URL: Repository, https://github.com/gnoays/proxy-watch

# proxy-watch

Read and watch the operating system's proxy settings on Windows, macOS and Linux (GNOME,
KDE), layered with `http_proxy`, `https_proxy`, `all_proxy` and `no_proxy`, and resolve
which route a URL takes under them (including PAC).

```sh
pip install proxy-watch
```

## Usage

### Read once

```python
import proxy_watch

snapshot = proxy_watch.read()
route = snapshot.route("https://example.com/")
if route.kind == "steps":
    print(route.steps)  # ["direct"] or proxy URLs, credentials included
else:
    print(route.kind)   # "pac", "pac-inline" or "wpad": a PAC script decides
```

`snapshot.to_dict()` gives the whole configuration as dicts and lists.

### Watch changes

```python
def on_change(err, snapshot):
    print(err or snapshot.route("https://example.com/").kind)

with proxy_watch.watch(on_change) as watcher:
    ...
```

`on_change` runs on the watch's own thread. On GNOME, start `multiprocessing` children with
`spawn` or `forkserver`: a child forked right after a read can hang on a GLib lock.

### PAC

```python
route = snapshot.route("https://example.com/", pac="auto")
```

`pac="native"` runs the OS's engine (WinHTTP, CFNetwork), `"quickjs"` runs QuickJS in this
process, and `"auto"` takes the OS's where it has one. QuickJS answers as if off every
network until a `PacPolicy` says where the machine is (`my_ip_address`, `resolve_dns`).

### Settings of your own

```python
snapshot = proxy_watch.read(
    precedence="only",  # no OS settings: the same answer on every machine
    env={"https_proxy": "http://proxy.corp.example:8080", "no_proxy": ".corp.example"},
)
snapshot.route("http://localhost:3000/", bypass="localhost,127.0.0.1")
```

`bypass` sends destinations direct on top of any configuration; GNOME and KDE settings do
not exclude loopback.

## Wheels

One `abi3` wheel per platform for CPython 3.10 and later, and one for 3.14t (free-threaded,
without the GIL): Linux x86-64 and AArch64 (manylinux2014, musllinux 1.2), Linux ARMv7
(manylinux2014), macOS x86-64 and arm64, Windows x86-64 and ARM64.

## License

MIT OR Apache-2.0. Each wheel carries `THIRD-PARTY-LICENSES.txt` for the code linked into
it.

