Lokasi ngalangkungan proxy:   [ UP ]  
[Ngawartoskeun bug]   [Panyetelan cookie]                
Skip to content

Commit 8214ac5

Browse files
authored
Add httpx2 to the full extra (#3323)
1 parent 70a3bd4 commit 8214ac5

6 files changed

Lines changed: 21 additions & 14 deletions

File tree

README.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -85,7 +85,7 @@ $ uvicorn main:app
8585

8686
Starlette only requires `anyio`, and the following are optional:
8787

88-
* [`httpx`][httpx] - Required if you want to use the `TestClient`.
88+
* [`httpx2`][httpx2] - Required if you want to use the `TestClient`.
8989
* [`jinja2`][jinja2] - Required if you want to use `Jinja2Templates`.
9090
* [`python-multipart`][python-multipart] - Required if you want to support form parsing, with `request.form()`.
9191
* [`itsdangerous`][itsdangerous] - Required for `SessionMiddleware` support.
@@ -132,7 +132,7 @@ in isolation.
132132
<p align="center"><i>Starlette is <a href="https://github.com/Kludex/starlette/blob/main/LICENSE.md">BSD licensed</a> code.<br/>Designed & crafted with care.</i></br>&mdash; ⭐️ &mdash;</p>
133133

134134
[asgi]: https://asgi.readthedocs.io/en/latest/
135-
[httpx]: https://www.python-httpx.org/
135+
[httpx2]: https://pypi.org/project/httpx2/
136136
[jinja2]: https://jinja.palletsprojects.com/
137137
[python-multipart]: https://multipart.fastapiexpert.com/
138138
[itsdangerous]: https://itsdangerous.palletsprojects.com/

docs/index.md

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -100,7 +100,7 @@ uvicorn main:app
100100

101101
Starlette only requires `anyio`, and the following dependencies are optional:
102102

103-
* [`httpx`][httpx] - Required if you want to use the `TestClient`.
103+
* [`httpx2`][httpx2] - Required if you want to use the `TestClient`.
104104
* [`jinja2`][jinja2] - Required if you want to use `Jinja2Templates`.
105105
* [`python-multipart`][python-multipart] - Required if you want to support form parsing, with `request.form()`.
106106
* [`itsdangerous`][itsdangerous] - Required for `SessionMiddleware` support.
@@ -147,7 +147,7 @@ in isolation.
147147
<p align="center"><i>Starlette is <a href="https://github.com/Kludex/starlette/blob/main/LICENSE.md">BSD licensed</a> code.<br/>Designed & crafted with care.</i></br>&mdash; ⭐️ &mdash;</p>
148148

149149
[asgi]: https://asgi.readthedocs.io/en/latest/
150-
[httpx]: https://www.python-httpx.org/
150+
[httpx2]: https://pypi.org/project/httpx2/
151151
[jinja2]: https://jinja.palletsprojects.com/
152152
[python-multipart]: https://multipart.fastapiexpert.com/
153153
[itsdangerous]: https://itsdangerous.palletsprojects.com/

docs/testclient.md

Lines changed: 13 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,11 @@
1010
- "__init__"
1111

1212
The test client allows you to make requests against your ASGI application,
13-
using the `httpx` library.
13+
using the `httpx2` library.
14+
15+
!!! note
16+
The `TestClient` is built on `httpx2`. Plain `httpx` is still supported, but
17+
deprecated - install `httpx2` (included in `starlette[full]`) instead.
1418

1519
```python
1620
from starlette.responses import HTMLResponse
@@ -29,11 +33,11 @@ def test_app():
2933
assert response.status_code == 200
3034
```
3135

32-
The test client exposes the same interface as any other `httpx` session.
36+
The test client exposes the same interface as any other `httpx2` session.
3337
In particular, note that the calls to make a request are just standard
3438
function calls, not awaitables.
3539

36-
You can use any of `httpx` standard API, such as authentication, session
40+
You can use any of `httpx2` standard API, such as authentication, session
3741
cookies handling, or file uploads.
3842

3943
For example, to set headers on the TestClient you can do:
@@ -65,7 +69,7 @@ with open("example.txt", "rb") as f1:
6569
response = client.post("/form", files=files)
6670
```
6771

68-
For more information you can check the `httpx` [documentation](https://www.python-httpx.org/advanced/).
72+
For more information you can check the `httpx2` [documentation](https://www.python-httpx.org/advanced/).
6973

7074
By default the `TestClient` will raise any exceptions that occur in the
7175
application. Occasionally you might want to test the content of 500 error
@@ -117,7 +121,7 @@ def test_app():
117121

118122
You can also test websocket sessions with the test client.
119123

120-
The `httpx` library will be used to build the initial handshake, meaning you
124+
The `httpx2` library will be used to build the initial handshake, meaning you
121125
can use the same authentication options and other headers between both http and
122126
websocket testing.
123127

@@ -150,7 +154,7 @@ always raised by the test client.
150154

151155
#### Establishing a test session
152156

153-
* `.websocket_connect(url, subprotocols=None, **options)` - Takes the same set of arguments as `httpx.get()`.
157+
* `.websocket_connect(url, subprotocols=None, **options)` - Takes the same set of arguments as `httpx2.get()`.
154158

155159
May raise `starlette.websockets.WebSocketDisconnect` if the application does not accept the websocket connection.
156160

@@ -191,12 +195,12 @@ using your existing async database client/infrastructure.
191195

192196
For these situations, using `TestClient` is difficult because it creates its own event loop and async
193197
resources (like a database connection) often cannot be shared across event loops.
194-
The simplest way to work around this is to just make your entire test async and use an async client, like [httpx.AsyncClient].
198+
The simplest way to work around this is to just make your entire test async and use an async client, like [httpx2.AsyncClient].
195199

196200
Here is an example of such a test:
197201

198202
```python
199-
from httpx import AsyncClient, ASGITransport
203+
from httpx2 import AsyncClient, ASGITransport
200204
from starlette.applications import Starlette
201205
from starlette.routing import Route
202206
from starlette.requests import Request
@@ -222,4 +226,4 @@ async def test_app() -> None:
222226
assert r.text == "Hello World!"
223227
```
224228

225-
[httpx.AsyncClient]: https://www.python-httpx.org/advanced/#calling-into-python-web-apps
229+
[httpx2.AsyncClient]: https://www.python-httpx.org/advanced/#calling-into-python-web-apps

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,7 @@ full = [
4242
"python-multipart>=0.0.18",
4343
"pyyaml",
4444
"httpx>=0.27.0,<0.29.0",
45+
"httpx2>=2.0.0",
4546
]
4647

4748
[dependency-groups]

tests/types.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -2,7 +2,7 @@
22

33
from typing import TYPE_CHECKING, Protocol
44

5-
import httpx
5+
import httpx2 as httpx
66

77
from starlette.testclient import TestClient
88
from starlette.types import ASGIApp

uv.lock

Lines changed: 2 additions & 0 deletions
Some generated files are not rendered by default. Learn more about customizing how changed files appear on GitHub.

0 commit comments

Comments
 (0)