Skip to content

Commit ed8ef7a

Browse files
authored
feat(python): stream iterator request bodies (#515)
Lets `content=` take a sync or async iterable of byte chunks and streams it into the request instead of buffering it; stacked on #514. Related: #513
1 parent 778beeb commit ed8ef7a

8 files changed

Lines changed: 356 additions & 126 deletions

File tree

impit-python/python/impit/impit.pyi

Lines changed: 30 additions & 30 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,7 @@ from .headers import Headers
66
from . import Browser
77

88
from typing import Any
9-
from collections.abc import Iterator, AsyncIterator
9+
from collections.abc import AsyncIterable, AsyncIterator, Iterable, Iterator
1010
from contextlib import AbstractAsyncContextManager, AbstractContextManager
1111

1212

@@ -518,7 +518,7 @@ class Client:
518518
def get(
519519
self,
520520
url: str,
521-
content: bytes | bytearray | list[int] | None = None,
521+
content: bytes | bytearray | str | list[int] | Iterable[bytes] | None = None,
522522
data: dict[str, str] | None = None,
523523
headers: dict[str, str] | None = None,
524524
timeout: float | str | None = USE_CLIENT_DEFAULT,
@@ -538,7 +538,7 @@ class Client:
538538
def post(
539539
self,
540540
url: str,
541-
content: bytes | bytearray | list[int] | None = None,
541+
content: bytes | bytearray | str | list[int] | Iterable[bytes] | None = None,
542542
data: dict[str, str] | None = None,
543543
headers: dict[str, str] | None = None,
544544
timeout: float | str | None = USE_CLIENT_DEFAULT,
@@ -559,7 +559,7 @@ class Client:
559559
def put(
560560
self,
561561
url: str,
562-
content: bytes | bytearray | list[int] | None = None,
562+
content: bytes | bytearray | str | list[int] | Iterable[bytes] | None = None,
563563
data: dict[str, str] | None = None,
564564
headers: dict[str, str] | None = None,
565565
timeout: float | str | None = USE_CLIENT_DEFAULT,
@@ -579,7 +579,7 @@ class Client:
579579
def patch(
580580
self,
581581
url: str,
582-
content: bytes | bytearray | list[int] | None = None,
582+
content: bytes | bytearray | str | list[int] | Iterable[bytes] | None = None,
583583
data: dict[str, str] | None = None,
584584
headers: dict[str, str] | None = None,
585585
timeout: float | str | None = USE_CLIENT_DEFAULT,
@@ -599,7 +599,7 @@ class Client:
599599
def delete(
600600
self,
601601
url: str,
602-
content: bytes | bytearray | list[int] | None = None,
602+
content: bytes | bytearray | str | list[int] | Iterable[bytes] | None = None,
603603
data: dict[str, str] | None = None,
604604
headers: dict[str, str] | None = None,
605605
timeout: float | str | None = USE_CLIENT_DEFAULT,
@@ -619,7 +619,7 @@ class Client:
619619
def head(
620620
self,
621621
url: str,
622-
content: bytes | bytearray | list[int] | None = None,
622+
content: bytes | bytearray | str | list[int] | Iterable[bytes] | None = None,
623623
data: dict[str, str] | None = None,
624624
headers: dict[str, str] | None = None,
625625
timeout: float | str | None = USE_CLIENT_DEFAULT,
@@ -639,7 +639,7 @@ class Client:
639639
def options(
640640
self,
641641
url: str,
642-
content: bytes | bytearray | list[int] | None = None,
642+
content: bytes | bytearray | str | list[int] | Iterable[bytes] | None = None,
643643
data: dict[str, str] | None = None,
644644
headers: dict[str, str] | None = None,
645645
timeout: float | str | None = USE_CLIENT_DEFAULT,
@@ -659,7 +659,7 @@ class Client:
659659
def trace(
660660
self,
661661
url: str,
662-
content: bytes | bytearray | list[int] | None = None,
662+
content: bytes | bytearray | str | list[int] | Iterable[bytes] | None = None,
663663
data: dict[str, str] | None = None,
664664
headers: dict[str, str] | None = None,
665665
timeout: float | str | None = USE_CLIENT_DEFAULT,
@@ -680,7 +680,7 @@ class Client:
680680
self,
681681
method: str,
682682
url: str,
683-
content: bytes | bytearray | list[int] | None = None,
683+
content: bytes | bytearray | str | list[int] | Iterable[bytes] | None = None,
684684
data: dict[str, str] | None = None,
685685
headers: dict[str, str] | None = None,
686686
timeout: float | str | None = USE_CLIENT_DEFAULT,
@@ -704,7 +704,7 @@ class Client:
704704
self,
705705
method: str,
706706
url: str,
707-
content: bytes | bytearray | list[int] | None = None,
707+
content: bytes | bytearray | str | list[int] | Iterable[bytes] | None = None,
708708
data: dict[str, str] | None = None,
709709
headers: dict[str, str] | None = None,
710710
timeout: float | str | None = USE_CLIENT_DEFAULT,
@@ -859,7 +859,7 @@ class AsyncClient:
859859
async def get(
860860
self,
861861
url: str,
862-
content: bytes | bytearray | list[int] | None = None,
862+
content: bytes | bytearray | str | list[int] | Iterable[bytes] | AsyncIterable[bytes] | None = None,
863863
data: dict[str, str] | None = None,
864864
headers: dict[str, str] | None = None,
865865
timeout: float | str | None = USE_CLIENT_DEFAULT,
@@ -879,7 +879,7 @@ class AsyncClient:
879879
async def post(
880880
self,
881881
url: str,
882-
content: bytes | bytearray | list[int] | None = None,
882+
content: bytes | bytearray | str | list[int] | Iterable[bytes] | AsyncIterable[bytes] | None = None,
883883
data: dict[str, str] | None = None,
884884
headers: dict[str, str] | None = None,
885885
timeout: float | str | None = USE_CLIENT_DEFAULT,
@@ -900,7 +900,7 @@ class AsyncClient:
900900
async def put(
901901
self,
902902
url: str,
903-
content: bytes | bytearray | list[int] | None = None,
903+
content: bytes | bytearray | str | list[int] | Iterable[bytes] | AsyncIterable[bytes] | None = None,
904904
data: dict[str, str] | None = None,
905905
headers: dict[str, str] | None = None,
906906
timeout: float | str | None = USE_CLIENT_DEFAULT,
@@ -920,7 +920,7 @@ class AsyncClient:
920920
async def patch(
921921
self,
922922
url: str,
923-
content: bytes | bytearray | list[int] | None = None,
923+
content: bytes | bytearray | str | list[int] | Iterable[bytes] | AsyncIterable[bytes] | None = None,
924924
data: dict[str, str] | None = None,
925925
headers: dict[str, str] | None = None,
926926
timeout: float | str | None = USE_CLIENT_DEFAULT,
@@ -940,7 +940,7 @@ class AsyncClient:
940940
async def delete(
941941
self,
942942
url: str,
943-
content: bytes | bytearray | list[int] | None = None,
943+
content: bytes | bytearray | str | list[int] | Iterable[bytes] | AsyncIterable[bytes] | None = None,
944944
data: dict[str, str] | None = None,
945945
headers: dict[str, str] | None = None,
946946
timeout: float | str | None = USE_CLIENT_DEFAULT,
@@ -960,7 +960,7 @@ class AsyncClient:
960960
async def head(
961961
self,
962962
url: str,
963-
content: bytes | bytearray | list[int] | None = None,
963+
content: bytes | bytearray | str | list[int] | Iterable[bytes] | AsyncIterable[bytes] | None = None,
964964
data: dict[str, str] | None = None,
965965
headers: dict[str, str] | None = None,
966966
timeout: float | str | None = USE_CLIENT_DEFAULT,
@@ -980,7 +980,7 @@ class AsyncClient:
980980
async def options(
981981
self,
982982
url: str,
983-
content: bytes | bytearray | list[int] | None = None,
983+
content: bytes | bytearray | str | list[int] | Iterable[bytes] | AsyncIterable[bytes] | None = None,
984984
data: dict[str, str] | None = None,
985985
headers: dict[str, str] | None = None,
986986
timeout: float | str | None = USE_CLIENT_DEFAULT,
@@ -1000,7 +1000,7 @@ class AsyncClient:
10001000
async def trace(
10011001
self,
10021002
url: str,
1003-
content: bytes | bytearray | list[int] | None = None,
1003+
content: bytes | bytearray | str | list[int] | Iterable[bytes] | AsyncIterable[bytes] | None = None,
10041004
data: dict[str, str] | None = None,
10051005
headers: dict[str, str] | None = None,
10061006
timeout: float | str | None = USE_CLIENT_DEFAULT,
@@ -1021,7 +1021,7 @@ class AsyncClient:
10211021
self,
10221022
method: str,
10231023
url: str,
1024-
content: bytes | bytearray | list[int] | None = None,
1024+
content: bytes | bytearray | str | list[int] | Iterable[bytes] | AsyncIterable[bytes] | None = None,
10251025
data: dict[str, str] | None = None,
10261026
headers: dict[str, str] | None = None,
10271027
timeout: float | str | None = USE_CLIENT_DEFAULT,
@@ -1045,7 +1045,7 @@ class AsyncClient:
10451045
self,
10461046
method: str,
10471047
url: str,
1048-
content: bytes | bytearray | list[int] | None = None,
1048+
content: bytes | bytearray | str | list[int] | Iterable[bytes] | AsyncIterable[bytes] | None = None,
10491049
data: dict[str, str] | None = None,
10501050
headers: dict[str, str] | None = None,
10511051
timeout: float | str | None = USE_CLIENT_DEFAULT,
@@ -1078,7 +1078,7 @@ class AsyncClient:
10781078
def stream(
10791079
method: str,
10801080
url: str,
1081-
content: bytes | bytearray | list[int] | None = None,
1081+
content: bytes | bytearray | str | list[int] | Iterable[bytes] | None = None,
10821082
data: dict[str, str] | None = None,
10831083
headers: dict[str, str] | None = None,
10841084
timeout: float | str | None = USE_CLIENT_DEFAULT,
@@ -1111,7 +1111,7 @@ def stream(
11111111

11121112
def get(
11131113
url: str,
1114-
content: bytes | bytearray | list[int] | None = None,
1114+
content: bytes | bytearray | str | list[int] | Iterable[bytes] | None = None,
11151115
data: dict[str, str] | None = None,
11161116
headers: dict[str, str] | None = None,
11171117
timeout: float | str | None = USE_CLIENT_DEFAULT,
@@ -1144,7 +1144,7 @@ def get(
11441144

11451145
def post(
11461146
url: str,
1147-
content: bytes | bytearray | list[int] | None = None,
1147+
content: bytes | bytearray | str | list[int] | Iterable[bytes] | None = None,
11481148
data: dict[str, str] | None = None,
11491149
headers: dict[str, str] | None = None,
11501150
timeout: float | str | None = USE_CLIENT_DEFAULT,
@@ -1177,7 +1177,7 @@ def post(
11771177

11781178
def put(
11791179
url: str,
1180-
content: bytes | bytearray | list[int] | None = None,
1180+
content: bytes | bytearray | str | list[int] | Iterable[bytes] | None = None,
11811181
data: dict[str, str] | None = None,
11821182
headers: dict[str, str] | None = None,
11831183
timeout: float | str | None = USE_CLIENT_DEFAULT,
@@ -1210,7 +1210,7 @@ def put(
12101210

12111211
def patch(
12121212
url: str,
1213-
content: bytes | bytearray | list[int] | None = None,
1213+
content: bytes | bytearray | str | list[int] | Iterable[bytes] | None = None,
12141214
data: dict[str, str] | None = None,
12151215
headers: dict[str, str] | None = None,
12161216
timeout: float | str | None = USE_CLIENT_DEFAULT,
@@ -1243,7 +1243,7 @@ def patch(
12431243

12441244
def delete(
12451245
url: str,
1246-
content: bytes | bytearray | list[int] | None = None,
1246+
content: bytes | bytearray | str | list[int] | Iterable[bytes] | None = None,
12471247
data: dict[str, str] | None = None,
12481248
headers: dict[str, str] | None = None,
12491249
timeout: float | str | None = USE_CLIENT_DEFAULT,
@@ -1276,7 +1276,7 @@ def delete(
12761276

12771277
def head(
12781278
url: str,
1279-
content: bytes | bytearray | list[int] | None = None,
1279+
content: bytes | bytearray | str | list[int] | Iterable[bytes] | None = None,
12801280
data: dict[str, str] | None = None,
12811281
headers: dict[str, str] | None = None,
12821282
timeout: float | str | None = USE_CLIENT_DEFAULT,
@@ -1309,7 +1309,7 @@ def head(
13091309

13101310
def options(
13111311
url: str,
1312-
content: bytes | bytearray | list[int] | None = None,
1312+
content: bytes | bytearray | str | list[int] | Iterable[bytes] | None = None,
13131313
data: dict[str, str] | None = None,
13141314
headers: dict[str, str] | None = None,
13151315
timeout: float | str | None = USE_CLIENT_DEFAULT,
@@ -1339,7 +1339,7 @@ def options(
13391339

13401340
def trace(
13411341
url: str,
1342-
content: bytes | bytearray | list[int] | None = None,
1342+
content: bytes | bytearray | str | list[int] | Iterable[bytes] | None = None,
13431343
data: dict[str, str] | None = None,
13441344
headers: dict[str, str] | None = None,
13451345
timeout: float | str | None = USE_CLIENT_DEFAULT,

0 commit comments

Comments
 (0)