httpx2 2.4.0__tar.gz → 2.5.0__tar.gz
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- {httpx2-2.4.0 → httpx2-2.5.0}/CHANGELOG.md +11 -0
- {httpx2-2.4.0 → httpx2-2.5.0}/PKG-INFO +5 -10
- {httpx2-2.4.0 → httpx2-2.5.0}/httpx2/__init__.py +4 -0
- {httpx2-2.4.0 → httpx2-2.5.0}/httpx2/_client.py +85 -0
- {httpx2-2.4.0 → httpx2-2.5.0}/httpx2/_models.py +18 -0
- httpx2-2.5.0/httpx2/_sse.py +158 -0
- {httpx2-2.4.0 → httpx2-2.5.0}/httpx2/_utils.py +5 -1
- {httpx2-2.4.0 → httpx2-2.5.0}/.gitignore +0 -0
- {httpx2-2.4.0 → httpx2-2.5.0}/LICENSE.md +0 -0
- {httpx2-2.4.0 → httpx2-2.5.0}/README.md +0 -0
- {httpx2-2.4.0 → httpx2-2.5.0}/httpx2/__version__.py +0 -0
- {httpx2-2.4.0 → httpx2-2.5.0}/httpx2/_api.py +0 -0
- {httpx2-2.4.0 → httpx2-2.5.0}/httpx2/_auth.py +0 -0
- {httpx2-2.4.0 → httpx2-2.5.0}/httpx2/_config.py +0 -0
- {httpx2-2.4.0 → httpx2-2.5.0}/httpx2/_content.py +0 -0
- {httpx2-2.4.0 → httpx2-2.5.0}/httpx2/_decoders.py +0 -0
- {httpx2-2.4.0 → httpx2-2.5.0}/httpx2/_exceptions.py +0 -0
- {httpx2-2.4.0 → httpx2-2.5.0}/httpx2/_main.py +0 -0
- {httpx2-2.4.0 → httpx2-2.5.0}/httpx2/_multipart.py +0 -0
- {httpx2-2.4.0 → httpx2-2.5.0}/httpx2/_status_codes.py +0 -0
- {httpx2-2.4.0 → httpx2-2.5.0}/httpx2/_transports/__init__.py +0 -0
- {httpx2-2.4.0 → httpx2-2.5.0}/httpx2/_transports/asgi.py +0 -0
- {httpx2-2.4.0 → httpx2-2.5.0}/httpx2/_transports/base.py +0 -0
- {httpx2-2.4.0 → httpx2-2.5.0}/httpx2/_transports/default.py +0 -0
- {httpx2-2.4.0 → httpx2-2.5.0}/httpx2/_transports/mock.py +0 -0
- {httpx2-2.4.0 → httpx2-2.5.0}/httpx2/_transports/wsgi.py +0 -0
- {httpx2-2.4.0 → httpx2-2.5.0}/httpx2/_types.py +0 -0
- {httpx2-2.4.0 → httpx2-2.5.0}/httpx2/_urlparse.py +0 -0
- {httpx2-2.4.0 → httpx2-2.5.0}/httpx2/_urls.py +0 -0
- {httpx2-2.4.0 → httpx2-2.5.0}/httpx2/py.typed +0 -0
- {httpx2-2.4.0 → httpx2-2.5.0}/pyproject.toml +0 -0
|
@@ -4,6 +4,17 @@ All notable changes to this project will be documented in this file.
|
|
|
4
4
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/).
|
|
6
6
|
|
|
7
|
+
## 2.5.0 (June 25th, 2026)
|
|
8
|
+
|
|
9
|
+
### Added
|
|
10
|
+
|
|
11
|
+
* Add native server-sent events support via `client.sse()`. ([#1046](https://github.com/pydantic/httpx2/pull/1046))
|
|
12
|
+
* Support `|` and `|=` operators for `Headers`. ([#1047](https://github.com/pydantic/httpx2/pull/1047))
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
|
|
16
|
+
* Allow IPv6 CIDR notation in `no_proxy`. ([#967](https://github.com/pydantic/httpx2/pull/967))
|
|
17
|
+
|
|
7
18
|
## 2.4.0 (June 11th, 2026)
|
|
8
19
|
|
|
9
20
|
### Added
|
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
Metadata-Version: 2.4
|
|
2
2
|
Name: httpx2
|
|
3
|
-
Version: 2.
|
|
3
|
+
Version: 2.5.0
|
|
4
4
|
Summary: The next generation HTTP client.
|
|
5
5
|
Project-URL: Changelog, https://github.com/pydantic/httpx2/blob/main/src/httpx2/CHANGELOG.md
|
|
6
6
|
Project-URL: Homepage, https://github.com/pydantic/httpx2
|
|
@@ -26,7 +26,7 @@ Classifier: Programming Language :: Python :: 3.14
|
|
|
26
26
|
Classifier: Topic :: Internet :: WWW/HTTP
|
|
27
27
|
Requires-Python: >=3.10
|
|
28
28
|
Requires-Dist: anyio
|
|
29
|
-
Requires-Dist: httpcore2==2.
|
|
29
|
+
Requires-Dist: httpcore2==2.5.0
|
|
30
30
|
Requires-Dist: idna>=3.18
|
|
31
31
|
Requires-Dist: truststore>=0.10
|
|
32
32
|
Requires-Dist: typing-extensions>=4.5.0; python_version < '3.13'
|
|
@@ -188,17 +188,12 @@ inspiration around the lower-level networking details.
|
|
|
188
188
|
|
|
189
189
|
### Added
|
|
190
190
|
|
|
191
|
-
* Add
|
|
192
|
-
|
|
193
|
-
### Changed
|
|
194
|
-
|
|
195
|
-
* Limit the number of chained `Content-Encoding` decoders to 5. ([#1027](https://github.com/pydantic/httpx2/pull/1027))
|
|
196
|
-
* Allow version 15 of `rich` in the `cli` extra. ([#1015](https://github.com/pydantic/httpx2/pull/1015))
|
|
191
|
+
* Add native server-sent events support via `client.sse()`. ([#1046](https://github.com/pydantic/httpx2/pull/1046))
|
|
192
|
+
* Support `|` and `|=` operators for `Headers`. ([#1047](https://github.com/pydantic/httpx2/pull/1047))
|
|
197
193
|
|
|
198
194
|
### Fixed
|
|
199
195
|
|
|
200
|
-
*
|
|
201
|
-
* Decode IDNA labels in non-leading host positions. ([#1018](https://github.com/pydantic/httpx2/pull/1018))
|
|
196
|
+
* Allow IPv6 CIDR notation in `no_proxy`. ([#967](https://github.com/pydantic/httpx2/pull/967))
|
|
202
197
|
|
|
203
198
|
|
|
204
199
|
---
|
|
@@ -6,6 +6,7 @@ from ._config import *
|
|
|
6
6
|
from ._content import *
|
|
7
7
|
from ._exceptions import *
|
|
8
8
|
from ._models import *
|
|
9
|
+
from ._sse import *
|
|
9
10
|
from ._status_codes import *
|
|
10
11
|
from ._transports import *
|
|
11
12
|
from ._types import *
|
|
@@ -35,6 +36,7 @@ __all__ = [
|
|
|
35
36
|
"DecodingError",
|
|
36
37
|
"delete",
|
|
37
38
|
"DigestAuth",
|
|
39
|
+
"EventSource",
|
|
38
40
|
"FunctionAuth",
|
|
39
41
|
"get",
|
|
40
42
|
"head",
|
|
@@ -66,6 +68,8 @@ __all__ = [
|
|
|
66
68
|
"RequestNotRead",
|
|
67
69
|
"Response",
|
|
68
70
|
"ResponseNotRead",
|
|
71
|
+
"ServerSentEvent",
|
|
72
|
+
"SSEError",
|
|
69
73
|
"stream",
|
|
70
74
|
"StreamClosed",
|
|
71
75
|
"StreamConsumed",
|
|
@@ -28,6 +28,7 @@ from ._exceptions import (
|
|
|
28
28
|
request_context,
|
|
29
29
|
)
|
|
30
30
|
from ._models import Cookies, Headers, Request, Response
|
|
31
|
+
from ._sse import EventSource
|
|
31
32
|
from ._status_codes import codes
|
|
32
33
|
from ._transports.base import AsyncBaseTransport, BaseTransport
|
|
33
34
|
from ._transports.default import AsyncHTTPTransport, HTTPTransport
|
|
@@ -845,6 +846,48 @@ class Client(BaseClient):
|
|
|
845
846
|
finally:
|
|
846
847
|
response.close()
|
|
847
848
|
|
|
849
|
+
@contextmanager
|
|
850
|
+
def sse(
|
|
851
|
+
self,
|
|
852
|
+
url: URL | str,
|
|
853
|
+
*,
|
|
854
|
+
method: str = "GET",
|
|
855
|
+
content: RequestContent | None = None,
|
|
856
|
+
data: RequestData | None = None,
|
|
857
|
+
files: RequestFiles | None = None,
|
|
858
|
+
json: typing.Any | None = None,
|
|
859
|
+
params: QueryParamTypes | None = None,
|
|
860
|
+
headers: HeaderTypes | None = None,
|
|
861
|
+
cookies: CookieTypes | None = None,
|
|
862
|
+
auth: AuthTypes | UseClientDefault | None = USE_CLIENT_DEFAULT,
|
|
863
|
+
follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT,
|
|
864
|
+
timeout: TimeoutTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
|
865
|
+
extensions: RequestExtensions | None = None,
|
|
866
|
+
) -> Generator[EventSource]:
|
|
867
|
+
"""
|
|
868
|
+
Connect to a server-sent events endpoint and yield an `EventSource`.
|
|
869
|
+
|
|
870
|
+
Iterating the `EventSource` yields `ServerSentEvent` instances.
|
|
871
|
+
|
|
872
|
+
**Parameters**: See `httpx2.request`.
|
|
873
|
+
"""
|
|
874
|
+
with self.stream(
|
|
875
|
+
method,
|
|
876
|
+
url,
|
|
877
|
+
content=content,
|
|
878
|
+
data=data,
|
|
879
|
+
files=files,
|
|
880
|
+
json=json,
|
|
881
|
+
params=params,
|
|
882
|
+
headers={"Accept": "text/event-stream", "Cache-Control": "no-store"} | Headers(headers),
|
|
883
|
+
cookies=cookies,
|
|
884
|
+
auth=auth,
|
|
885
|
+
follow_redirects=follow_redirects,
|
|
886
|
+
timeout=timeout,
|
|
887
|
+
extensions=extensions,
|
|
888
|
+
) as response:
|
|
889
|
+
yield EventSource(response)
|
|
890
|
+
|
|
848
891
|
def send(
|
|
849
892
|
self,
|
|
850
893
|
request: Request,
|
|
@@ -1548,6 +1591,48 @@ class AsyncClient(BaseClient):
|
|
|
1548
1591
|
finally:
|
|
1549
1592
|
await response.aclose()
|
|
1550
1593
|
|
|
1594
|
+
@asynccontextmanager
|
|
1595
|
+
async def sse(
|
|
1596
|
+
self,
|
|
1597
|
+
url: URL | str,
|
|
1598
|
+
*,
|
|
1599
|
+
method: str = "GET",
|
|
1600
|
+
content: RequestContent | None = None,
|
|
1601
|
+
data: RequestData | None = None,
|
|
1602
|
+
files: RequestFiles | None = None,
|
|
1603
|
+
json: typing.Any | None = None,
|
|
1604
|
+
params: QueryParamTypes | None = None,
|
|
1605
|
+
headers: HeaderTypes | None = None,
|
|
1606
|
+
cookies: CookieTypes | None = None,
|
|
1607
|
+
auth: AuthTypes | UseClientDefault | None = USE_CLIENT_DEFAULT,
|
|
1608
|
+
follow_redirects: bool | UseClientDefault = USE_CLIENT_DEFAULT,
|
|
1609
|
+
timeout: TimeoutTypes | UseClientDefault = USE_CLIENT_DEFAULT,
|
|
1610
|
+
extensions: RequestExtensions | None = None,
|
|
1611
|
+
) -> AsyncGenerator[EventSource]:
|
|
1612
|
+
"""
|
|
1613
|
+
Connect to a server-sent events endpoint and yield an `EventSource`.
|
|
1614
|
+
|
|
1615
|
+
Iterating the `EventSource` yields `ServerSentEvent` instances.
|
|
1616
|
+
|
|
1617
|
+
**Parameters**: See `httpx2.request`.
|
|
1618
|
+
"""
|
|
1619
|
+
async with self.stream(
|
|
1620
|
+
method,
|
|
1621
|
+
url,
|
|
1622
|
+
content=content,
|
|
1623
|
+
data=data,
|
|
1624
|
+
files=files,
|
|
1625
|
+
json=json,
|
|
1626
|
+
params=params,
|
|
1627
|
+
headers={"Accept": "text/event-stream", "Cache-Control": "no-store"} | Headers(headers),
|
|
1628
|
+
cookies=cookies,
|
|
1629
|
+
auth=auth,
|
|
1630
|
+
follow_redirects=follow_redirects,
|
|
1631
|
+
timeout=timeout,
|
|
1632
|
+
extensions=extensions,
|
|
1633
|
+
) as response:
|
|
1634
|
+
yield EventSource(response)
|
|
1635
|
+
|
|
1551
1636
|
async def send(
|
|
1552
1637
|
self,
|
|
1553
1638
|
request: Request,
|
|
@@ -277,6 +277,24 @@ class Headers(typing.MutableMapping[str, str]):
|
|
|
277
277
|
def copy(self) -> Headers:
|
|
278
278
|
return Headers(self, encoding=self.encoding)
|
|
279
279
|
|
|
280
|
+
def __or__(self, other: Mapping[str, str]) -> Headers:
|
|
281
|
+
if not isinstance(other, Mapping):
|
|
282
|
+
return NotImplemented
|
|
283
|
+
merged = self.copy()
|
|
284
|
+
merged.update(other)
|
|
285
|
+
return merged
|
|
286
|
+
|
|
287
|
+
def __ror__(self, other: Mapping[str, str]) -> Headers:
|
|
288
|
+
if not isinstance(other, Mapping):
|
|
289
|
+
return NotImplemented
|
|
290
|
+
merged = Headers(other)
|
|
291
|
+
merged.update(self)
|
|
292
|
+
return merged
|
|
293
|
+
|
|
294
|
+
def __ior__(self, other: HeaderTypes) -> Headers:
|
|
295
|
+
self.update(other)
|
|
296
|
+
return self
|
|
297
|
+
|
|
280
298
|
def __getitem__(self, key: str) -> str:
|
|
281
299
|
"""
|
|
282
300
|
Return a single header value.
|
|
@@ -0,0 +1,158 @@
|
|
|
1
|
+
"""
|
|
2
|
+
Server-sent events support, derived from httpx-sse (https://github.com/florimondmanca/httpx-sse).
|
|
3
|
+
|
|
4
|
+
Copyright (c) 2022 Florimond Manca, MIT License (https://github.com/florimondmanca/httpx-sse/blob/master/LICENSE).
|
|
5
|
+
"""
|
|
6
|
+
|
|
7
|
+
from __future__ import annotations
|
|
8
|
+
|
|
9
|
+
import json as jsonlib
|
|
10
|
+
from collections.abc import AsyncIterator, Iterator
|
|
11
|
+
from dataclasses import dataclass
|
|
12
|
+
|
|
13
|
+
from ._exceptions import TransportError
|
|
14
|
+
from ._models import Response
|
|
15
|
+
|
|
16
|
+
__all__ = ["EventSource", "SSEError", "ServerSentEvent"]
|
|
17
|
+
|
|
18
|
+
|
|
19
|
+
class SSEError(TransportError):
|
|
20
|
+
"""
|
|
21
|
+
An error that occurred while connecting to a server-sent events endpoint.
|
|
22
|
+
"""
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
@dataclass(frozen=True)
|
|
26
|
+
class ServerSentEvent:
|
|
27
|
+
event: str = "message"
|
|
28
|
+
data: str = ""
|
|
29
|
+
id: str = ""
|
|
30
|
+
retry: int | None = None
|
|
31
|
+
|
|
32
|
+
def json(self) -> object:
|
|
33
|
+
return jsonlib.loads(self.data)
|
|
34
|
+
|
|
35
|
+
|
|
36
|
+
class _SSEDecoder:
|
|
37
|
+
def __init__(self) -> None:
|
|
38
|
+
self._event = ""
|
|
39
|
+
self._data: list[str] = []
|
|
40
|
+
self._last_event_id = ""
|
|
41
|
+
self._retry: int | None = None
|
|
42
|
+
self._pending = False
|
|
43
|
+
|
|
44
|
+
def decode(self, line: str) -> ServerSentEvent | None:
|
|
45
|
+
if not line:
|
|
46
|
+
if not self._pending:
|
|
47
|
+
return None
|
|
48
|
+
|
|
49
|
+
sse = ServerSentEvent(
|
|
50
|
+
event=self._event or "message",
|
|
51
|
+
data="\n".join(self._data),
|
|
52
|
+
id=self._last_event_id,
|
|
53
|
+
retry=self._retry,
|
|
54
|
+
)
|
|
55
|
+
self._event = ""
|
|
56
|
+
self._data = []
|
|
57
|
+
self._retry = None
|
|
58
|
+
self._pending = False
|
|
59
|
+
return sse
|
|
60
|
+
|
|
61
|
+
if line.startswith(":"):
|
|
62
|
+
return None
|
|
63
|
+
|
|
64
|
+
fieldname, _, value = line.partition(":")
|
|
65
|
+
value = value[1:] if value.startswith(" ") else value
|
|
66
|
+
|
|
67
|
+
if fieldname == "event":
|
|
68
|
+
self._event = value
|
|
69
|
+
self._pending = True
|
|
70
|
+
elif fieldname == "data":
|
|
71
|
+
self._data.append(value)
|
|
72
|
+
self._pending = True
|
|
73
|
+
elif fieldname == "id":
|
|
74
|
+
if "\0" not in value:
|
|
75
|
+
self._last_event_id = value
|
|
76
|
+
self._pending = True
|
|
77
|
+
elif fieldname == "retry":
|
|
78
|
+
try:
|
|
79
|
+
self._retry = int(value)
|
|
80
|
+
self._pending = True
|
|
81
|
+
except ValueError:
|
|
82
|
+
pass
|
|
83
|
+
|
|
84
|
+
return None
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
class _SSELineDecoder:
|
|
88
|
+
def __init__(self) -> None:
|
|
89
|
+
self._buffer = ""
|
|
90
|
+
self._trailing_cr = False
|
|
91
|
+
|
|
92
|
+
def decode(self, text: str) -> list[str]:
|
|
93
|
+
if self._trailing_cr:
|
|
94
|
+
text = "\r" + text
|
|
95
|
+
self._trailing_cr = False
|
|
96
|
+
if text.endswith("\r"):
|
|
97
|
+
self._trailing_cr = True
|
|
98
|
+
text = text[:-1]
|
|
99
|
+
|
|
100
|
+
text = self._buffer + text.replace("\r\n", "\n").replace("\r", "\n")
|
|
101
|
+
lines = text.split("\n")
|
|
102
|
+
self._buffer = lines.pop()
|
|
103
|
+
return lines
|
|
104
|
+
|
|
105
|
+
def flush(self) -> list[str]:
|
|
106
|
+
if self._trailing_cr:
|
|
107
|
+
self._buffer += "\n"
|
|
108
|
+
self._trailing_cr = False
|
|
109
|
+
if not self._buffer:
|
|
110
|
+
return []
|
|
111
|
+
lines = self._buffer.split("\n")
|
|
112
|
+
self._buffer = ""
|
|
113
|
+
return lines
|
|
114
|
+
|
|
115
|
+
|
|
116
|
+
class EventSource:
|
|
117
|
+
def __init__(self, response: Response) -> None:
|
|
118
|
+
self._response = response
|
|
119
|
+
|
|
120
|
+
@property
|
|
121
|
+
def response(self) -> Response:
|
|
122
|
+
return self._response
|
|
123
|
+
|
|
124
|
+
def _check_content_type(self) -> None:
|
|
125
|
+
content_type, _, _ = self._response.headers.get("content-type", "").partition(";")
|
|
126
|
+
if content_type.strip().lower() != "text/event-stream":
|
|
127
|
+
raise SSEError(
|
|
128
|
+
f"Expected response with content type 'text/event-stream', got {content_type.strip()!r}.",
|
|
129
|
+
request=self._response.request,
|
|
130
|
+
)
|
|
131
|
+
|
|
132
|
+
def __iter__(self) -> Iterator[ServerSentEvent]:
|
|
133
|
+
self._check_content_type()
|
|
134
|
+
decoder = _SSEDecoder()
|
|
135
|
+
lines = _SSELineDecoder()
|
|
136
|
+
for chunk in self._response.iter_text():
|
|
137
|
+
for line in lines.decode(chunk):
|
|
138
|
+
sse = decoder.decode(line)
|
|
139
|
+
if sse is not None:
|
|
140
|
+
yield sse
|
|
141
|
+
for line in lines.flush():
|
|
142
|
+
sse = decoder.decode(line)
|
|
143
|
+
if sse is not None:
|
|
144
|
+
yield sse
|
|
145
|
+
|
|
146
|
+
async def __aiter__(self) -> AsyncIterator[ServerSentEvent]:
|
|
147
|
+
self._check_content_type()
|
|
148
|
+
decoder = _SSEDecoder()
|
|
149
|
+
lines = _SSELineDecoder()
|
|
150
|
+
async for chunk in self._response.aiter_text():
|
|
151
|
+
for line in lines.decode(chunk):
|
|
152
|
+
sse = decoder.decode(line)
|
|
153
|
+
if sse is not None:
|
|
154
|
+
yield sse
|
|
155
|
+
for line in lines.flush():
|
|
156
|
+
sse = decoder.decode(line)
|
|
157
|
+
if sse is not None:
|
|
158
|
+
yield sse
|
|
@@ -65,7 +65,11 @@ def get_environment_proxies() -> dict[str, str | None]:
|
|
|
65
65
|
elif is_ipv4_hostname(hostname):
|
|
66
66
|
mounts[f"all://{hostname}"] = None
|
|
67
67
|
elif is_ipv6_hostname(hostname):
|
|
68
|
-
|
|
68
|
+
if "/" in hostname:
|
|
69
|
+
addr, _, subnet = hostname.partition("/")
|
|
70
|
+
mounts[f"all://[{addr}]/{subnet}"] = None
|
|
71
|
+
else:
|
|
72
|
+
mounts[f"all://[{hostname}]"] = None
|
|
69
73
|
elif hostname.lower() == "localhost":
|
|
70
74
|
mounts[f"all://{hostname}"] = None
|
|
71
75
|
else:
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|
|
File without changes
|