You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
* Add cli support
* Add setup.py
* Import main to 'httpx.main'
* Add 'cli' to requirements
* Add tests for command-line client
* Drop most CLI tests
* Add test_json
* Add test_redirects
* Coverage exclusion over _main.py in order to test more clearly
* Black formatting
* Add test_follow_redirects
* Add test_post, test_verbose, test_auth
* Add test_errors
* Remove test_errors
* Add test_download
* Change test_errors - perhaps the empty host header was causing the socket error?
* Update test_errors to not break socket
* Update docs
* Update version to 1.0.0.beta0
* Tweak CHANGELOG
* Fix up images in README
* Tweak images in README
* Update README
* The `allow_redirects` flag is now `follow_redirects` and defaults to `False`.
53
+
* The `raise_for_status()` method will now raise an exception for any responses
54
+
except those with 2xx status codes. Previously only 4xx and 5xx status codes
55
+
would result in an exception.
56
+
* The low-level transport API changes to the much simpler `response = transport.handle_request(request)`.
57
+
* The `client.send()` method no longer accepts a `timeout=...` argument, but the
58
+
`client.build_request()` does. This required by the signature change of the
59
+
Transport API. The request timeout configuration is now stored on the request
60
+
instance, as `request.extensions['timeout']`.
61
+
62
+
### Added
63
+
64
+
* Added the `httpx` command-line client.
65
+
* Response instances now include `.is_informational`, `.is_success`, `.is_redirect`, `.is_client_error`, and `.is_server_error`
66
+
properties for checking 1xx, 2xx, 3xx, 4xx, and 5xx response types. Note that the behaviour of `.is_redirect` is slightly different in that it now returns True for all 3xx responses, in order to allow for a consistent set of properties onto the different HTTP status code types. The `response.has_redirect_location` location may be used to determine responses with properly formed URL redirects.
67
+
68
+
### Fixed
69
+
70
+
*`response.iter_bytes()` no longer raises a ValueError when called on a response with no content. (Pull #1827)
71
+
* The `'wsgi.error'` configuration now defaults to `sys.stderr`, and is corrected to be a `TextIO` interface, not a `BytesIO` interface. Additionally, the WSGITransport now accepts a `wsgi_error` confguration. (Pull #1828)
72
+
* Follow the WSGI spec by properly closing the iterable returned by the application. (Pull #1830)
Copy file name to clipboardExpand all lines: README.md
+28-16Lines changed: 28 additions & 16 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -13,15 +13,21 @@
13
13
</a>
14
14
</p>
15
15
16
-
HTTPX is a fully featured HTTP client for Python 3, which provides sync and async APIs, and support for both HTTP/1.1 and HTTP/2.
16
+
HTTPX is a fully featured HTTP client library for Python 3. It includes **an integrated
17
+
command line client**, has support for both **HTTP/1.1 and HTTP/2**, and provides both **sync
18
+
and async APIs**.
17
19
18
-
**Note**: _HTTPX should be considered in beta. We believe we've got the public API to
19
-
a stable point now, but would strongly recommend pinning your dependencies to the `0.19.*`
20
-
release, so that you're able to properly review [API changes between package updates](https://github.com/encode/httpx/blob/master/CHANGELOG.md). A 1.0 release is expected to be issued sometime in 2021._
20
+
**Note**: *This is the README for the 1.0 pre-release. This release adds support for an integrated command-line client, and also includes a couple of design changes from 0.19. Redirects are no longer followed by default, and the low-level Transport API has been updated. Upgrades from 0.19 will need to see [the CHANGELOG](https://github.com/encode/httpx/blob/version-1.0/CHANGELOG.md) for more details.*
* Standard synchronous interface, but with [async support if you need it](https://www.python-httpx.org/async/).
59
71
* Ability to make requests directly to [WSGI applications](https://www.python-httpx.org/advanced/#calling-into-python-web-apps) or [ASGI applications](https://www.python-httpx.org/async/#calling-into-python-web-apps).
Copy file name to clipboardExpand all lines: docs/compatibility.md
+35-27Lines changed: 35 additions & 27 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -1,29 +1,10 @@
1
1
# Requests Compatibility Guide
2
2
3
-
HTTPX aims to be broadly compatible with the `requests` API.
3
+
HTTPX aims to be broadly compatible with the `requests` API, although there are a
4
+
few design differences in places.
4
5
5
6
This documentation outlines places where the API differs...
6
7
7
-
## Client instances
8
-
9
-
The HTTPX equivalent of `requests.Session` is `httpx.Client`.
10
-
11
-
```python
12
-
session = requests.Session(**kwargs)
13
-
```
14
-
15
-
is generally equivalent to
16
-
17
-
```python
18
-
client = httpx.Client(**kwargs)
19
-
```
20
-
21
-
## Request URLs
22
-
23
-
Accessing `response.url` will return a `URL` instance, rather than a string.
24
-
25
-
Use `str(response.url)` if you need a string instance.
26
-
27
8
## Redirects
28
9
29
10
Unlike `requests`, HTTPX does **not follow redirects by default**.
@@ -44,6 +25,26 @@ Or else instantiate a client, with redirect following enabled by default...
44
25
client = httpx.Client(follow_redirects=True)
45
26
```
46
27
28
+
## Client instances
29
+
30
+
The HTTPX equivalent of `requests.Session` is `httpx.Client`.
31
+
32
+
```python
33
+
session = requests.Session(**kwargs)
34
+
```
35
+
36
+
is generally equivalent to
37
+
38
+
```python
39
+
client = httpx.Client(**kwargs)
40
+
```
41
+
42
+
## Request URLs
43
+
44
+
Accessing `response.url` will return a `URL` instance, rather than a string.
45
+
46
+
Use `str(response.url)` if you need a string instance.
47
+
47
48
## Determining the next redirect request
48
49
49
50
The `requests` library exposes an attribute `response.next`, which can be used to obtain the next redirect request.
@@ -97,8 +98,7 @@ opened in text mode.
97
98
## Content encoding
98
99
99
100
HTTPX uses `utf-8` for encoding `str` request bodies. For example, when using `content=<str>` the request body will be encoded to `utf-8` before being sent over the wire. This differs from Requests which uses `latin1`. If you need an explicit encoding, pass encoded bytes explictly, e.g. `content=<str>.encode("latin1")`.
100
-
101
-
For response bodies, assuming the server didn't send an explicit encoding then HTTPX will do its best to figure out an appropriate encoding. HTTPX makes a guess at the encoding to use for decoding the response using `charset_normalizer`. Fallback to that or any content with less than 32 octets will be decoded using `utf-8` with the `error="replace"` decoder strategy.
101
+
For response bodies, assuming the server didn't send an explicit encoding then HTTPX will do its best to figure out an appropriate encoding. HTTPX makes a guess at the encoding to use for decoding the response using `charset_normalizer`. Fallback to that or any content with less than 32 octets will be decoded using `utf-8` with the `error="replace"` decoder strategy.
102
102
103
103
## Cookies
104
104
@@ -133,7 +133,7 @@ HTTPX provides a `.stream()` interface rather than using `stream=True`. This ens
133
133
For example:
134
134
135
135
```python
136
-
withrequest.stream("GET", "https://www.example.com") as response:
136
+
withhttpx.stream("GET", "https://www.example.com") as response:
137
137
...
138
138
```
139
139
@@ -165,13 +165,21 @@ Requests supports `REQUESTS_CA_BUNDLE` which points to either a file or a direct
165
165
166
166
## Request body on HTTP methods
167
167
168
-
The HTTP `GET`, `DELETE`, `HEAD`, and `OPTIONS` methods are specified as not supporting a request body. To stay in line with this, the `.get`, `.delete`, `.head` and `.options` functions do not support `files`, `data`, or `json` arguments.
168
+
The HTTP `GET`, `DELETE`, `HEAD`, and `OPTIONS` methods are specified as not supporting a request body. To stay in line with this, the `.get`, `.delete`, `.head` and `.options` functions do not support `content`, `files`, `data`, or `json` arguments.
169
169
170
170
If you really do need to send request data using these http methods you should use the generic `.request` function instead.
171
171
172
-
## Checking for 4xx/5xx responses
172
+
```python
173
+
httpx.request(
174
+
method="DELETE",
175
+
url="https://www.example.com/",
176
+
content=b'A request body on a DELETE request.'
177
+
)
178
+
```
179
+
180
+
## Checking for success and failure responses
173
181
174
-
We 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_error` property. Use `if not response.is_error:` instead of `if response.is_ok:`.
182
+
We 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.
Copy file name to clipboardExpand all lines: docs/index.md
+22-17Lines changed: 22 additions & 17 deletions
Display the source diff
Display the rich diff
Original file line number
Diff line number
Diff line change
@@ -25,15 +25,19 @@ HTTPX is a fully featured HTTP client for Python 3, which provides sync and asyn
25
25
26
26
27
27
!!! note
28
-
HTTPX should currently be considered in beta.
28
+
This is the documentation for the 1.0 pre-release.
29
29
30
-
We believe we've got the public API to a stable point now, but would strongly recommend pinning your dependencies to the `0.19.*` release, so that you're able to properly review [API changes between package updates](https://github.com/encode/httpx/blob/master/CHANGELOG.md).
31
-
32
-
A 1.0 release is expected to be issued sometime in 2021.
30
+
This release adds support for an integrated command-line client, and also includes a couple of design changes from 0.19. Redirects are no longer followed by default, and the low-level Transport API has been updated. See [the CHANGELOG](https://github.com/encode/httpx/blob/version-1.0/CHANGELOG.md) for more details.
0 commit comments