$ pip install httpx
```
+Or, to include the optional HTTP/2 support, use:
+
+```shell
+$ pip install httpx[http2]
+```
+
HTTPX requires Python 3.6+.
## Documentation
* `httpcore` - The underlying transport implementation for `httpx`.
* `h11` - HTTP/1.1 support.
- * `h2` - HTTP/2 support.
+ * `h2` - HTTP/2 support. *(Optional)*
* `certifi` - SSL certificates.
* `chardet` - Fallback auto-detection for response encoding.
* `idna` - Internationalized domain name support.
It is possible that a future version of `httpx` may enable HTTP/2 support by default.
If you're issuing highly concurrent requests you might want to consider
-trying out our HTTP/2 support. You can do so by instantiating a client with
-HTTP/2 support enabled:
+trying out our HTTP/2 support. You can do so by first making sure to install
+the optional HTTP/2 dependencies...
+
+```shell
+$ pip install httpx[http2]
+```
+
+And then then instantiating a client with HTTP/2 support enabled:
```python
client = httpx.AsyncClient(http2=True)
...
```
-HTTP/2 support is available on both `Client`, and `AsyncClient`, although it's
+HTTP/2 support is available on both `Client` and `AsyncClient`, although it's
typically more useful in async contexts if you're issuing lots of concurrent
requests.
$ pip install httpx
```
+Or, to include the optional HTTP/2 support, use:
+
+```shell
+$ pip install httpx[http2]
+```
+
HTTPX requires Python 3.6+
[sync-support]: https://github.com/encode/httpx/issues/572
trust_env=trust_env,
)
+ if http2:
+ try:
+ import h2 # noqa
+ except ImportError: # pragma: nocover
+ raise ImportError(
+ "Using http2=True, but the 'h2' package is not installed. "
+ "Make sure to install httpx using `pip install httpx[http2]`."
+ ) from None
+
if pool_limits is not None:
warn_deprecated(
"Client(..., pool_limits=...) is deprecated and will raise "
trust_env=trust_env,
)
+ if http2:
+ try:
+ import h2 # noqa
+ except ImportError: # pragma: nocover
+ raise ImportError(
+ "Using http2=True, but the 'h2' package is not installed. "
+ "Make sure to install httpx using `pip install httpx[http2]`."
+ ) from None
+
if pool_limits is not None:
warn_deprecated(
"AsyncClient(..., pool_limits=...) is deprecated and will raise "
--e .
+-e .[http2]
# Optional
brotlipy==0.7.*
"chardet==3.*",
"idna==2.*",
"rfc3986>=1.3,<2",
- "httpcore[http2]==0.10.*",
+ "httpcore==0.10.*",
],
+ extras_require={
+ "http2": "h2==3.*",
+ },
classifiers=[
"Development Status :: 4 - Beta",
"Environment :: Web Environment",
@pytest.mark.usefixtures("async_environment")
async def test_get(server):
url = server.url
- async with httpx.AsyncClient() as client:
+ async with httpx.AsyncClient(http2=True) as client:
response = await client.get(url)
assert response.status_code == 200
assert response.text == "Hello, world!"
def test_get(server):
url = server.url
- with httpx.Client() as http:
+ with httpx.Client(http2=True) as http:
response = http.get(url)
assert response.status_code == 200
assert response.url == url