Skip to content
Myr

Fix sections references (#3058)

Before adoption: this commit came in with the history the project adopted, so no landing records it.

authored by Kar Petrosyan · committed by GitHub · parent 419d3a9 · Browse files · 10 files+22 added−22 removed
This commit

State

Before adoption: this commit came in with the history the project adopted, so no landing records it.

Diff stats

10 files+22 added−22 removed

  • other:+22 added−22 removed

10 files+22 added−22 removed

modified:docs/advanced/clients.md+7 added-7 removed
6 unmodified lines
7 If you do anything more than experimentation, one-off scripts, or prototypes, then you should use a `Client` instance.89**More efficient usage of network resources**1011When you make requests using the top-level API as documented in the [Quickstart](quickstart.md) guide, HTTPX has to establish a new connection _for every single request_ (connections are not reused). As the number of requests to a host increases, this quickly becomes inefficient.11When you make requests using the top-level API as documented in the [Quickstart](../quickstart.md) guide, HTTPX has to establish a new connection _for every single request_ (connections are not reused). As the number of requests to a host increases, this quickly becomes inefficient.1213On the other hand, a `Client` instance uses [HTTP connection pooling](https://en.wikipedia.org/wiki/HTTP_persistent_connection). This means that when you make several requests to the same host, the `Client` will reuse the underlying TCP connection, instead of recreating one for every single request.1415This can bring **significant performance improvements** compared to using the top-level API, including:
8 unmodified lines
2425- Cookie persistence across requests.26- Applying configuration across all outgoing requests.27- Sending requests through HTTP proxies.28- Using [HTTP/2](http2.md).28- Using [HTTP/2](../http2.md).2930The other sections on this page go into further detail about what you can do with a `Client` instance.3132## Usage
26 unmodified lines
59>>> r60<Response [200 OK]>61```6263These methods accept the same arguments as `httpx.get()`, `httpx.post()`, etc. This means that all features documented in the [Quickstart](quickstart.md) guide are also available at the client level.63These methods accept the same arguments as `httpx.get()`, `httpx.post()`, etc. This means that all features documented in the [Quickstart](../quickstart.md) guide are also available at the client level.6465For example, to send a request with custom headers:6667```pycon
70 unmodified lines
138>>> r.request.url139URL('http://httpbin.org/headers')140```141142For a list of all available client parameters, see the [`Client`](api.md#client) API reference.142For a list of all available client parameters, see the [`Client`](../api.md#client) API reference.143144---145146## Request instances147148For maximum control on what gets sent over the wire, HTTPX supports building explicit [`Request`](api.md#request) instances:148For maximum control on what gets sent over the wire, HTTPX supports building explicit [`Request`](../api.md#request) instances:149150```python151request = httpx.Request("GET", "https://example.com")152```
49 unmodified lines
202 progress.update(response.num_bytes_downloaded - num_bytes_downloaded)203 num_bytes_downloaded = response.num_bytes_downloaded204```205206![tqdm progress bar](img/tqdm-progress.gif)206![tqdm progress bar](../img/tqdm-progress.gif)207208Or an alternate example, this time using the [`rich`](https://github.com/willmcgugan/rich) library…209210```python
53 unmodified lines
264![tqdm progress bar](../img/tqdm-progress.gif)265266## Multipart file encoding267268As mentioned in the [quickstart](quickstart.md#sending-multipart-file-uploads)268As mentioned in the [quickstart](../quickstart.md#sending-multipart-file-uploads)269multipart file encoding is available by passing a dictionary with the270name of the payloads as keys and either tuple of elements or a file-like object or a string as values.271272```pycon
52 unmodified lines
modified:docs/advanced/proxies.md+1 added-1 removed
modified:docs/advanced/transports.md+1 added-1 removed
339 unmodified lines
340341There are also environment variables that can be used to control the dictionary of the client mounts. 342They can be used to configure HTTP proxying for clients.343344See documentation on [`HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY`](environment_variables.md#http_proxy-https_proxy-all_proxy) for more information.344See documentation on [`HTTP_PROXY`, `HTTPS_PROXY`, `ALL_PROXY`](../environment_variables.md#http_proxy-https_proxy-all_proxy) for more information.
modified:docs/async.md+1 added-1 removed
82 unmodified lines
83* `Response.aiter_lines()` - For streaming the response content as lines of text.84* `Response.aiter_raw()` - For streaming the raw response bytes, without applying content decoding.85* `Response.aclose()` - For closing the response. You don't usually need this, since `.stream` block closes the response automatically on exit.8687For situations when context block usage is not practical, it is possible to enter "manual mode" by sending a [`Request` instance](./advanced.md#request-instances) using `client.send(..., stream=True)`.87For situations when context block usage is not practical, it is possible to enter "manual mode" by sending a [`Request` instance](advanced/clients.md#request-instances) using `client.send(..., stream=True)`.8889Example in the context of forwarding the response to a streaming web endpoint with [Starlette](https://www.starlette.io):9091```python
153 unmodified lines
modified:docs/compatibility.md+4 added-4 removed
157 unmodified lines
158## Proxy keys159160HTTPX uses the mounts argument for HTTP proxying and transport routing.161It can do much more than proxies and allows you to configure more than just the proxy route.162For more detailed documentation, see [Mounting Transports](advanced.md#mounting-transports).162For more detailed documentation, see [Mounting Transports](advanced/transports.md#mounting-transports).163164When using `httpx.Client(mounts={...})` to map to a selection of different transports, we use full URL schemes, such as `mounts={"http://": ..., "https://": ...}`.165166This is different to the `requests` usage of `proxies={"http": ..., "https": ...}`.
29 unmodified lines
196We don't support `response.is_ok` since the naming is ambiguous there, and might incorrectly imply an equivalence to `response.status_code == codes.OK`. Instead we provide the `response.is_success` property, which can be used to check for a 2xx response.197198## Request instantiation199200There is no notion of [prepared requests](https://requests.readthedocs.io/en/stable/user/advanced/#prepared-requests) in HTTPX. If you need to customize request instantiation, see [Request instances](advanced.md#request-instances).200There is no notion of [prepared requests](https://requests.readthedocs.io/en/stable/user/advanced/#prepared-requests) in HTTPX. If you need to customize request instantiation, see [Request instances](advanced/clients.md#request-instances).201202Besides, `httpx.Request()` does not support the `auth`, `timeout`, `follow_redirects`, `mounts`, `verify` and `cert` parameters. However these are available in `httpx.request`, `httpx.get`, `httpx.post` etc., as well as on [`Client` instances](advanced.md#client-instances).202Besides, `httpx.Request()` does not support the `auth`, `timeout`, `follow_redirects`, `mounts`, `verify` and `cert` parameters. However these are available in `httpx.request`, `httpx.get`, `httpx.post` etc., as well as on [`Client` instances](advanced/clients.md#client-instances).203204## Mocking205206If you need to mock HTTPX the same way that test utilities like `responses` and `requests-mock` does for `requests`, see [RESPX](https://github.com/lundberg/respx).
19 unmodified lines
226`requests` allows event hooks to mutate `Request` and `Response` objects. See [examples](https://requests.readthedocs.io/en/master/user/advanced/#event-hooks) given in the documentation for `requests`.227228In HTTPX, event hooks may access properties of requests and responses, but event hook callbacks cannot mutate the original request/response.229230If you are looking for more control, consider checking out [Custom Transports](advanced.md#custom-transports).230If you are looking for more control, consider checking out [Custom Transports](advanced/transports.md#custom-transports).
modified:docs/environment_variables.md+1 added-1 removed
modified:docs/index.md+2 added-2 removed
66 unmodified lines
6768* A broadly [requests-compatible API](compatibility.md).69* Standard synchronous interface, but with [async support if you need it](async.md).70* HTTP/1.1 [and HTTP/2 support](http2.md).71* Ability to make requests directly to [WSGI applications](advanced.md#calling-into-python-web-apps) or [ASGI applications](async.md#calling-into-python-web-apps).71* Ability to make requests directly to [WSGI applications](async.md#calling-into-python-web-apps) or [ASGI applications](async.md#calling-into-python-web-apps).72* Strict timeouts everywhere.73* Fully type annotated.74* 100% test coverage.75
18 unmodified lines
94## Documentation9596For a run-through of all the basics, head over to the [QuickStart](quickstart.md).9798For more advanced topics, see the [Advanced Usage](advanced.md) section,98For more advanced topics, see the **Advanced** section,99the [async support](async.md) section, or the [HTTP/2](http2.md) section.100101The [Developer Interface](api.md) provides a comprehensive API reference.102
47 unmodified lines
modified:docs/quickstart.md+1 added-1 removed
460 unmodified lines
461```pycon462>>> httpx.get('https://github.com/', timeout=None)463```464465For advanced timeout management, see [Timeout fine-tuning](advanced.md#fine-tuning-the-configuration).465For advanced timeout management, see [Timeout fine-tuning](advanced/timeouts.md#fine-tuning-the-configuration).466467## Authentication468469HTTPX supports Basic and Digest HTTP authentication.
73 unmodified lines
modified:docs/third_party_packages.md+2 added-2 removed
26 unmodified lines
27### HTTPX-Auth2829[GitHub](https://github.com/Colin-b/httpx_auth) - [Documentation](https://colin-b.github.io/httpx_auth/)3031Provides authentication classes to be used with HTTPX [authentication parameter](advanced.md#customizing-authentication).31Provides authentication classes to be used with HTTPX [authentication parameter](advanced/authentication.md#customizing-authentication).3233### pytest-HTTPX3435[GitHub](https://github.com/Colin-b/pytest_httpx) - [Documentation](https://colin-b.github.io/pytest_httpx/)
43 unmodified lines
79### urllib3-transport8081[GitHub](https://gist.github.com/florimondmanca/d56764d78d748eb9f73165da388e546e)8283This public gist provides an example implementation for a [custom transport](advanced.md#custom-transports) implementation on top of the battle-tested [`urllib3`](https://urllib3.readthedocs.io) library.83This public gist provides an example implementation for a [custom transport](advanced/transports.md#custom-transports) implementation on top of the battle-tested [`urllib3`](https://urllib3.readthedocs.io) library.
modified:docs/troubleshooting.md+2 added-2 removed
25 unmodified lines
26```2728Using this setup, you're telling HTTPX to connect to the proxy using HTTP for HTTP requests, and using HTTPS for HTTPS requests.2930But if you get the error above, it is likely that your proxy doesn't support connecting via HTTPS. Don't worry: that's a [common gotcha](advanced.md#example).30But if you get the error above, it is likely that your proxy doesn't support connecting via HTTPS. Don't worry: that's a [common gotcha](advanced/proxies.md#http-proxies).3132Change the scheme of your HTTPS proxy to `http://...` instead of `https://...`:3334```python
10 unmodified lines
45with httpx.Client(proxy=proxy) as client:46 ...47```4849For more information, see [Proxies: FORWARD vs TUNNEL](advanced.md#forward-vs-tunnel).49For more information, see [Proxies: FORWARD vs TUNNEL](advanced/proxies.md#forward-vs-tunnel).5051---5253### Error when making requests to an HTTPS proxy
10 unmodified lines