environment_variables.md
This file
Path
docs/environment_variables.md
79 lines · 2.8 KiB · Markdown
Last changed by
Documentation for SSL_CERT_FILE and SSL_CERT_DIR (#3579)Tobias Fischerbefore adoption652f051
History of this fileTake it
The walk stopped after 200 commits: lines older than 9d022c0 point at it.
Bump ruff from 0.0.260 to 0.0.275 (#2753)dependabot[bot]before adoption9d022c0
lines 1–17why, one step back1# Environment Variables23The HTTPX library can be configured via environment variables.4Environment variables are used by default. To ignore environment variables, `trust_env` has to be set `False`. There are two ways to set `trust_env` to disable environment variables:56* On the client via `httpx.Client(trust_env=False)`.7* Using the top-level API, such as `httpx.get("<url>", trust_env=False)`.89Here is a list of environment variables that HTTPX recognizes and what function they serve:1011## Proxies1213The environment variables documented below are used as a convention by various HTTP tooling, including:1415* [cURL](https://github.com/curl/curl/blob/master/docs/MANUAL.md#environment-variables)16* [requests](https://github.com/psf/requests/blob/master/docs/user/advanced.rst#proxies)17Fix sections references (#3058)Kar Petrosyanbefore adoption73e6888
line 18why, one step back18For more information on using proxies in HTTPX, see [HTTP Proxying](advanced/proxies.md#http-proxying).Bump ruff from 0.0.260 to 0.0.275 (#2753)dependabot[bot]before adoption9d022c0
lines 19–53why, one step back1920### `HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY`2122Valid values: A URL to a proxy2324`HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY` set the proxy to be used for `http`, `https`, or all requests respectively.2526```bash27export HTTP_PROXY=http://my-external-proxy.com:12342829# This request will be sent through the proxy30python -c "import httpx; httpx.get('http://example.com')"3132# This request will be sent directly, as we set `trust_env=False`33python -c "import httpx; httpx.get('http://example.com', trust_env=False)"3435```3637### `NO_PROXY`3839Valid values: a comma-separated list of hostnames/urls4041`NO_PROXY` disables the proxy for specific urls4243```bash44export HTTP_PROXY=http://my-external-proxy.com:123445export NO_PROXY=http://127.0.0.1,python-httpx.org4647# As in the previous example, this request will be sent through the proxy48python -c "import httpx; httpx.get('http://example.com')"4950# These requests will be sent directly, bypassing the proxy51python -c "import httpx; httpx.get('http://127.0.0.1:5000/my-api')"52python -c "import httpx; httpx.get('https://www.python-httpx.org')"53```Documentation for SSL_CERT_FILE and SSL_CERT_DIR (#3579)Tobias Fischerbefore adoption652f051
lines 54–79why, one step back5455## `SSL_CERT_FILE`5657Valid values: a filename5859If this environment variable is set then HTTPX will load60CA certificate from the specified file instead of the default61location.6263Example:6465```console66SSL_CERT_FILE=/path/to/ca-certs/ca-bundle.crt python -c "import httpx; httpx.get('https://example.com')"67```6869## `SSL_CERT_DIR`7071Valid values: a directory following an [OpenSSL specific layout](https://www.openssl.org/docs/manmaster/man3/SSL_CTX_load_verify_locations.html).7273If this environment variable is set and the directory follows an [OpenSSL specific layout](https://www.openssl.org/docs/manmaster/man3/SSL_CTX_load_verify_locations.html) (ie. you ran `c_rehash`) then HTTPX will load CA certificates from this directory instead of the default location.7475Example:7677```console78SSL_CERT_DIR=/path/to/ca-certs/ python -c "import httpx; httpx.get('https://example.com')"79```