Skip to content

Commit f2fb991

Browse files
refactor: migrate httpx to httpx2 with dual import
Refs: HTTPXodus campaign
1 parent d2956ff commit f2fb991

6 files changed

Lines changed: 20 additions & 4 deletions

File tree

pyproject.toml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@ authors = [{ name = "Replicate, Inc." }]
1212
requires-python = ">=3.8"
1313
dependencies = [
1414
"httpx>=0.21.0,<1",
15+
"httpx2>=2.12.0; python_version >= \"3.10\"",
1516
"packaging",
1617
"pydantic>1.10.7",
1718
"typing_extensions>=4.5.0",

replicate/client.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
Union,
1717
)
1818

19-
import httpx
19+
try:
20+
import httpx2 as httpx
21+
except ImportError:
22+
import httpx
2023
from typing_extensions import Unpack
2124

2225
from replicate.__about__ import __version__

replicate/exceptions.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
from typing import TYPE_CHECKING, Optional
22

3-
import httpx
3+
try:
4+
import httpx2 as httpx
5+
except ImportError:
6+
import httpx
47

58
if TYPE_CHECKING:
69
from replicate.prediction import Prediction

replicate/prediction.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,10 @@
1616
overload,
1717
)
1818

19-
import httpx
19+
try:
20+
import httpx2 as httpx
21+
except ImportError:
22+
import httpx
2023
from typing_extensions import NotRequired, TypedDict, Unpack
2124

2225
from replicate.exceptions import ModelError, ReplicateError

replicate/stream.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,10 @@
1010
Union,
1111
)
1212

13-
import httpx
13+
try:
14+
import httpx2 as httpx
15+
except ImportError:
16+
import httpx
1417
from typing_extensions import Unpack
1518

1619
from replicate import identifier

replicate/webhook.py

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -11,6 +11,9 @@
1111
from replicate.resource import Namespace, Resource
1212

1313
if TYPE_CHECKING:
14+
try:
15+
import httpx2 as httpx
16+
except ImportError:
1417
import httpx
1518

1619

0 commit comments

Comments
 (0)