rnet 2.4.1__cp313-cp313t-win_amd64.whl → 3.0.0rc9__cp313-cp313t-win_amd64.whl

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.

Potentially problematic release.


This version of rnet might be problematic. Click here for more details.

rnet/__init__.pyi CHANGED
@@ -1,6 +1,8 @@
1
+ import datetime
1
2
  import ipaddress
2
- import typing
3
3
  from typing import (
4
+ AsyncGenerator,
5
+ Generator,
4
6
  Optional,
5
7
  Tuple,
6
8
  Union,
@@ -8,311 +10,1087 @@ from typing import (
8
10
  Dict,
9
11
  List,
10
12
  TypedDict,
13
+ Unpack,
14
+ NotRequired,
11
15
  )
12
16
  from pathlib import Path
13
17
  from enum import Enum, auto
14
18
 
15
- from .blocking import *
19
+ from .http1 import Http1Options
20
+ from .http2 import Http2Options
16
21
  from .cookie import *
17
- from .exceptions import *
18
22
  from .header import *
19
- from .impersonate import *
23
+ from .emulation import *
24
+ from .tls import *
20
25
 
21
- try:
22
- from typing import Unpack, NotRequired
23
- except ImportError:
24
- from typing_extensions import Unpack, NotRequired
26
+ class Method(Enum):
27
+ r"""
28
+ An HTTP method.
29
+ """
30
+
31
+ GET = auto()
32
+ HEAD = auto()
33
+ POST = auto()
34
+ PUT = auto()
35
+ DELETE = auto()
36
+ OPTIONS = auto()
37
+ TRACE = auto()
38
+ PATCH = auto()
39
+
40
+ class Version(Enum):
41
+ r"""
42
+ An HTTP version.
43
+ """
44
+
45
+ HTTP_09 = auto()
46
+ HTTP_10 = auto()
47
+ HTTP_11 = auto()
48
+ HTTP_2 = auto()
49
+ HTTP_3 = auto()
50
+
51
+ class StatusCode:
52
+ r"""
53
+ HTTP status code.
54
+ """
55
+
56
+ def __str__(self) -> str: ...
57
+ def as_int(self) -> int:
58
+ r"""
59
+ Return the status code as an integer.
60
+ """
61
+ ...
62
+
63
+ def is_informational(self) -> bool:
64
+ r"""
65
+ Check if status is within 100-199.
66
+ """
67
+ ...
68
+
69
+ def is_success(self) -> bool:
70
+ r"""
71
+ Check if status is within 200-299.
72
+ """
73
+ ...
74
+
75
+ def is_redirection(self) -> bool:
76
+ r"""
77
+ Check if status is within 300-399.
78
+ """
79
+ ...
80
+
81
+ def is_client_error(self) -> bool:
82
+ r"""
83
+ Check if status is within 400-499.
84
+ """
85
+ ...
86
+
87
+ def is_server_error(self) -> bool:
88
+ r"""
89
+ Check if status is within 500-599.
90
+ """
91
+ ...
92
+
93
+ class SocketAddr:
94
+ r"""
95
+ A IP socket address.
96
+ """
97
+
98
+ def __str__(self) -> str: ...
99
+ def ip(self) -> Union[ipaddress.IPv4Address, ipaddress.IPv6Address]:
100
+ r"""
101
+ Returns the IP address of the socket address.
102
+ """
103
+
104
+ def port(self) -> int:
105
+ r"""
106
+ Returns the port number of the socket address.
107
+ """
108
+
109
+ class Multipart:
110
+ r"""
111
+ A multipart form for a request.
112
+ """
113
+
114
+ def __init__(self, *parts: Part) -> None:
115
+ r"""
116
+ Creates a new multipart form.
117
+ """
118
+ ...
119
+
120
+ class Part:
121
+ r"""
122
+ A part of a multipart form.
123
+ """
124
+
125
+ def __init__(
126
+ self,
127
+ name: str,
128
+ value: Union[
129
+ str,
130
+ bytes,
131
+ Path,
132
+ Generator[bytes, str, None],
133
+ AsyncGenerator[bytes, str],
134
+ ],
135
+ filename: str | None = None,
136
+ mime: str | None = None,
137
+ length: int | None = None,
138
+ headers: HeaderMap | None = None,
139
+ ) -> None:
140
+ r"""
141
+ Creates a new part.
142
+
143
+ # Arguments
144
+ - `name` - The name of the part.
145
+ - `value` - The value of the part, either text, bytes, a file path, or a async or sync stream.
146
+ - `filename` - The filename of the part.
147
+ - `mime` - The MIME type of the part.
148
+ - `length` - The length of the part when value is a stream (e.g., for file uploads).
149
+ - `headers` - The custom headers for the part.
150
+ """
151
+ ...
152
+
153
+ class ProxyParams(TypedDict):
154
+ username: NotRequired[str]
155
+ r"""Username for proxy authentication."""
156
+
157
+ password: NotRequired[str]
158
+ r"""Password for proxy authentication."""
159
+
160
+ custom_http_auth: NotRequired[str]
161
+ r"""Custom HTTP proxy authentication header value."""
162
+
163
+ custom_http_headers: NotRequired[Union[Dict[str, str], HeaderMap]]
164
+ r"""Custom HTTP proxy headers."""
165
+
166
+ exclusion: NotRequired[str]
167
+ r"""List of domains to exclude from proxying."""
168
+
169
+ class Proxy:
170
+ r"""
171
+ A proxy server for a request.
172
+ Supports HTTP, HTTPS, SOCKS4, SOCKS4a, SOCKS5, and SOCKS5h protocols.
173
+ """
174
+
175
+ @staticmethod
176
+ def http(url: str, **kwargs: Unpack[ProxyParams]) -> "Proxy":
177
+ r"""
178
+ Creates a new HTTP proxy.
179
+
180
+ This method sets up a proxy server for HTTP requests.
181
+
182
+ # Examples
183
+
184
+ ```python
185
+ import rnet
186
+
187
+ proxy = rnet.Proxy.http("http://proxy.example.com")
188
+ ```
189
+ """
190
+
191
+ @staticmethod
192
+ def https(url: str, **kwargs: Unpack[ProxyParams]) -> "Proxy":
193
+ r"""
194
+ Creates a new HTTPS proxy.
195
+
196
+ This method sets up a proxy server for HTTPS requests.
197
+
198
+ # Examples
199
+
200
+ ```python
201
+ import rnet
202
+
203
+ proxy = rnet.Proxy.https("https://proxy.example.com")
204
+ ```
205
+ """
206
+
207
+ @staticmethod
208
+ def all(url: str, **kwargs: Unpack[ProxyParams]) -> "Proxy":
209
+ r"""
210
+ Creates a new proxy for all protocols.
211
+
212
+ This method sets up a proxy server for all types of requests (HTTP, HTTPS, etc.).
213
+
214
+ # Examples
215
+
216
+ ```python
217
+ import rnet
218
+
219
+ proxy = rnet.Proxy.all("https://proxy.example.com")
220
+ ```
221
+ """
222
+
223
+ class Message:
224
+ r"""
225
+ A WebSocket message.
226
+ """
227
+
228
+ data: Optional[bytes]
229
+ r"""
230
+ Returns the data of the message as bytes.
231
+ """
232
+
233
+ text: Optional[str]
234
+ r"""
235
+ Returns the text content of the message if it is a text message.
236
+ """
237
+
238
+ binary: Optional[bytes]
239
+ r"""
240
+ Returns the binary data of the message if it is a binary message.
241
+ """
242
+
243
+ ping: Optional[bytes]
244
+ r"""
245
+ Returns the ping data of the message if it is a ping message.
246
+ """
247
+
248
+ pong: Optional[bytes]
249
+ r"""
250
+ Returns the pong data of the message if it is a pong message.
251
+ """
252
+
253
+ close: Optional[Tuple[int, Optional[str]]]
254
+ r"""
255
+ Returns the close code and reason of the message if it is a close message.
256
+ """
257
+
258
+ @staticmethod
259
+ def text_from_json(json: Dict[str, Any]) -> "Message":
260
+ r"""
261
+ Creates a new text message from the JSON representation.
262
+
263
+ # Arguments
264
+ * `json` - The JSON representation of the message.
265
+ """
266
+ ...
267
+
268
+ @staticmethod
269
+ def binary_from_json(json: Dict[str, Any]) -> "Message":
270
+ r"""
271
+ Creates a new binary message from the JSON representation.
272
+
273
+ # Arguments
274
+ * `json` - The JSON representation of the message.
275
+ """
276
+
277
+ @staticmethod
278
+ def from_text(text: str) -> "Message":
279
+ r"""
280
+ Creates a new text message.
281
+
282
+ # Arguments
283
+
284
+ * `text` - The text content of the message.
285
+ """
286
+
287
+ @staticmethod
288
+ def from_binary(data: bytes) -> "Message":
289
+ r"""
290
+ Creates a new binary message.
291
+
292
+ # Arguments
293
+
294
+ * `data` - The binary data of the message.
295
+ """
296
+
297
+ @staticmethod
298
+ def from_ping(data: bytes) -> "Message":
299
+ r"""
300
+ Creates a new ping message.
301
+
302
+ # Arguments
303
+
304
+ * `data` - The ping data of the message.
305
+ """
306
+
307
+ @staticmethod
308
+ def from_pong(data: bytes) -> "Message":
309
+ r"""
310
+ Creates a new pong message.
311
+
312
+ # Arguments
313
+
314
+ * `data` - The pong data of the message.
315
+ """
316
+
317
+ @staticmethod
318
+ def from_close(code: int, reason: str | None = None) -> "Message":
319
+ r"""
320
+ Creates a new close message.
321
+
322
+ # Arguments
323
+
324
+ * `code` - The close code.
325
+ * `reason` - An optional reason for closing.
326
+ """
327
+
328
+ def json(self) -> Dict[str, Any]:
329
+ r"""
330
+ Returns the JSON representation of the message.
331
+ """
332
+
333
+ def __str__(self) -> str: ...
334
+
335
+ class History:
336
+ """
337
+ An entry in the redirect history.
338
+ """
339
+
340
+ status: int
341
+ """Get the status code of the redirect response."""
342
+
343
+ url: str
344
+ """Get the URL of the redirect response."""
345
+
346
+ previous: str
347
+ """Get the previous URL before the redirect response."""
348
+
349
+ headers: HeaderMap
350
+ """Get the headers of the redirect response."""
351
+
352
+ def __str__(self) -> str: ...
353
+
354
+ class Streamer:
355
+ r"""
356
+ A byte stream response.
357
+ An asynchronous iterator yielding data chunks from the response stream.
358
+ Used to stream response content.
359
+ Implemented in the `stream` method of the `Response` class.
360
+ Can be used in an asynchronous for loop in Python.
361
+
362
+ # Examples
363
+
364
+ ```python
365
+ import asyncio
366
+ import rnet
367
+ from rnet import Method, Emulation
368
+
369
+ async def main():
370
+ resp = await rnet.get("https://httpbin.org/stream/20")
371
+ async with resp.stream() as streamer:
372
+ async for chunk in streamer:
373
+ print("Chunk: ", chunk)
374
+ await asyncio.sleep(0.1)
375
+
376
+ if __name__ == "__main__":
377
+ asyncio.run(main())
378
+ ```
379
+ """
380
+
381
+ async def __aiter__(self) -> "Streamer": ...
382
+ async def __anext__(self) -> Optional[bytes]: ...
383
+ async def __aenter__(self) -> Any: ...
384
+ async def __aexit__(
385
+ self, _exc_type: Any, _exc_value: Any, _traceback: Any
386
+ ) -> Any: ...
387
+ def __iter__(self) -> "Streamer": ...
388
+ def __next__(self) -> bytes: ...
389
+ def __enter__(self) -> "Streamer": ...
390
+ def __exit__(self, _exc_type: Any, _exc_value: Any, _traceback: Any) -> None: ...
391
+
392
+ class Response:
393
+ r"""
394
+ A response from a request.
395
+
396
+ # Examples
397
+
398
+ ```python
399
+ import asyncio
400
+ import rnet
401
+
402
+ async def main():
403
+ response = await rnet.get("https://www.rust-lang.org")
404
+ print("Status Code: ", response.status)
405
+ print("Version: ", response.version)
406
+ print("Response URL: ", response.url)
407
+ print("Headers: ", response.headers)
408
+ print("Content-Length: ", response.content_length)
409
+ print("Encoding: ", response.encoding)
410
+ print("Remote Address: ", response.remote_addr)
411
+
412
+ text_content = await response.text()
413
+ print("Text: ", text_content)
414
+
415
+ if __name__ == "__main__":
416
+ asyncio.run(main())
417
+ ```
418
+ """
419
+
420
+ url: str
421
+ r"""
422
+ Get the URL of the response.
423
+ """
424
+
425
+ status: StatusCode
426
+ r"""
427
+ Get the status code of the response.
428
+ """
429
+
430
+ version: Version
431
+ r"""
432
+ Get the HTTP version of the response.
433
+ """
434
+
435
+ headers: HeaderMap
436
+ r"""
437
+ Get the headers of the response.
438
+ """
439
+
440
+ cookies: List[Cookie]
441
+ r"""
442
+ Get the cookies of the response.
443
+ """
444
+
445
+ content_length: Optional[int]
446
+ r"""
447
+ Get the content length of the response.
448
+ """
449
+
450
+ remote_addr: Optional[SocketAddr]
451
+ r"""
452
+ Get the remote address of the response.
453
+ """
454
+
455
+ local_addr: Optional[SocketAddr]
456
+ r"""
457
+ Get the local address of the response.
458
+ """
459
+
460
+ history: List[History]
461
+ r"""
462
+ Get the redirect history of the Response.
463
+ """
464
+
465
+ peer_certificate: Optional[bytes]
466
+ r"""
467
+ Get the DER encoded leaf certificate of the response.
468
+ """
469
+
470
+ def raise_for_status(self) -> None:
471
+ r"""
472
+ Turn a response into an error if the server returned an error.
473
+ """
474
+
475
+ def stream(self) -> Streamer:
476
+ r"""
477
+ Get the response into a `Streamer` of `bytes` from the body.
478
+ """
479
+
480
+ async def text(self) -> str:
481
+ r"""
482
+ Get the text content of the response.
483
+ """
484
+
485
+ async def text_with_charset(self, encoding: str) -> str:
486
+ r"""
487
+ Get the full response text given a specific encoding.
488
+ """
489
+
490
+ async def json(self) -> Any:
491
+ r"""
492
+ Get the JSON content of the response.
493
+ """
494
+
495
+ async def bytes(self) -> bytes:
496
+ r"""
497
+ Get the bytes content of the response.
498
+ """
499
+
500
+ async def close(self) -> None:
501
+ r"""
502
+ Close the response connection.
503
+ """
504
+
505
+ async def __aenter__(self) -> Any: ...
506
+ async def __aexit__(
507
+ self, _exc_type: Any, _exc_value: Any, _traceback: Any
508
+ ) -> Any: ...
509
+
510
+ class WebSocket:
511
+ r"""
512
+ A WebSocket response.
513
+ """
514
+
515
+ status: StatusCode
516
+ r"""
517
+ Get the status code of the response.
518
+ """
519
+
520
+ version: Version
521
+ r"""
522
+ Get the HTTP version of the response.
523
+ """
524
+
525
+ headers: HeaderMap
526
+ r"""
527
+ Get the headers of the response.
528
+ """
529
+
530
+ cookies: List[Cookie]
531
+ r"""
532
+ Get the cookies of the response.
533
+ """
534
+
535
+ remote_addr: Optional[SocketAddr]
536
+ r"""
537
+ Get the remote address of the response.
538
+ """
539
+
540
+ protocol: Optional[str]
541
+ r"""
542
+ Get the WebSocket protocol.
543
+ """
544
+
545
+ async def recv(
546
+ self, timeout: datetime.timedelta | None = None
547
+ ) -> Optional[Message]:
548
+ r"""
549
+ Receive a message from the WebSocket.
550
+ """
551
+
552
+ async def send(self, message: Message) -> None:
553
+ r"""
554
+ Send a message to the WebSocket.
555
+ """
556
+
557
+ async def send_all(self, messages: List[Message]) -> None:
558
+ r"""
559
+ Send multiple messages to the WebSocket.
560
+ """
561
+
562
+ async def close(
563
+ self,
564
+ code: int | None = None,
565
+ reason: str | None = None,
566
+ ) -> None:
567
+ r"""
568
+ Close the WebSocket connection.
569
+ """
570
+
571
+ def __aenter__(self) -> Any: ...
572
+ def __aexit__(self, _exc_type: Any, _exc_value: Any, _traceback: Any) -> Any: ...
573
+
574
+ class ClientParams(TypedDict):
575
+ emulation: NotRequired[Union[Emulation, EmulationOption]]
576
+ """Emulation config."""
577
+
578
+ user_agent: NotRequired[str]
579
+ """
580
+ Default User-Agent string.
581
+ """
582
+
583
+ headers: NotRequired[Union[Dict[str, str], HeaderMap]]
584
+ """
585
+ Default request headers.
586
+ """
587
+
588
+ orig_headers: NotRequired[Union[List[str], OrigHeaderMap]]
589
+ """
590
+ Original request headers (case-sensitive and order).
591
+ """
592
+
593
+ referer: NotRequired[bool]
594
+ """
595
+ Automatically set Referer.
596
+ """
597
+
598
+ history: NotRequired[bool]
599
+ """
600
+ Store redirect history.
601
+ """
602
+
603
+ allow_redirects: NotRequired[bool]
604
+ """
605
+ Allow automatic redirects.
606
+ """
607
+
608
+ max_redirects: NotRequired[int]
609
+ """
610
+ Maximum number of redirects.
611
+ """
612
+
613
+ cookie_store: NotRequired[bool]
614
+ """
615
+ Enable cookie store.
616
+ """
617
+
618
+ cookie_provider: NotRequired[Jar]
619
+ """
620
+ Custom cookie provider.
621
+ """
622
+
623
+ lookup_ip_strategy: NotRequired[str]
624
+ """
625
+ IP lookup strategy.
626
+ """
627
+
628
+ timeout: NotRequired[int]
629
+ """
630
+ Total timeout (seconds).
631
+ """
632
+
633
+ connect_timeout: NotRequired[int]
634
+ """
635
+ Connection timeout (seconds).
636
+ """
637
+
638
+ read_timeout: NotRequired[int]
639
+ """
640
+ Read timeout (seconds).
641
+ """
642
+
643
+ tcp_keepalive: NotRequired[int]
644
+ """
645
+ TCP keepalive time (seconds).
646
+ """
647
+
648
+ tcp_keepalive_interval: NotRequired[int]
649
+ """
650
+ TCP keepalive interval (seconds).
651
+ """
652
+
653
+ tcp_keepalive_retries: NotRequired[int]
654
+ """
655
+ TCP keepalive retry count.
656
+ """
657
+
658
+ tcp_user_timeout: NotRequired[int]
659
+ """
660
+ TCP user timeout (seconds).
661
+ """
662
+
663
+ tcp_nodelay: NotRequired[bool]
664
+ """
665
+ Enable TCP_NODELAY.
666
+ """
667
+
668
+ tcp_reuse_address: NotRequired[bool]
669
+ """
670
+ Enable SO_REUSEADDR.
671
+ """
672
+
673
+ pool_idle_timeout: NotRequired[int]
674
+ """
675
+ Connection pool idle timeout (seconds).
676
+ """
677
+
678
+ pool_max_idle_per_host: NotRequired[int]
679
+ """
680
+ Max idle connections per host.
681
+ """
682
+
683
+ pool_max_size: NotRequired[int]
684
+ """
685
+ Max total connections in pool.
686
+ """
687
+
688
+ http1_only: NotRequired[bool]
689
+ """
690
+ Enable HTTP/1.1 only.
691
+ """
692
+
693
+ http2_only: NotRequired[bool]
694
+ """
695
+ Enable HTTP/2 only.
696
+ """
697
+
698
+ https_only: NotRequired[bool]
699
+ """
700
+ Enable HTTPS only.
701
+ """
702
+
703
+ http1_options: NotRequired[Http1Options]
704
+ """
705
+ Sets the HTTP/1 options.
706
+ """
707
+
708
+ http2_options: NotRequired[Http2Options]
709
+ """
710
+ Sets the HTTP/2 options.
711
+ """
712
+
713
+ verify: NotRequired[Union[bool, Path, CertStore]]
714
+ """
715
+ Verify SSL or specify CA path.
716
+ """
717
+
718
+ verify_hostname: NotRequired[bool]
719
+ """
720
+ Configures the use of hostname verification when connecting.
721
+ """
722
+
723
+ identity: NotRequired[Identity]
724
+ """
725
+ Represents a private key and X509 cert as a client certificate.
726
+ """
727
+
728
+ keylog: NotRequired[KeyLog]
729
+ """
730
+ Key logging policy (environment or file).
731
+ """
732
+
733
+ tls_info: NotRequired[bool]
734
+ """
735
+ Return TLS info.
736
+ """
737
+
738
+ min_tls_version: NotRequired[TlsVersion]
739
+ """
740
+ Minimum TLS version.
741
+ """
742
+
743
+ max_tls_version: NotRequired[TlsVersion]
744
+ """
745
+ Maximum TLS version.
746
+ """
747
+
748
+ tls_options: NotRequired[TlsOptions]
749
+ """
750
+ Sets the TLS options.
751
+ """
752
+
753
+ no_proxy: NotRequired[bool]
754
+ """
755
+ Disable proxy.
756
+ """
757
+
758
+ proxies: NotRequired[List[Proxy]]
759
+ """
760
+ Proxy server list.
761
+ """
762
+
763
+ local_address: NotRequired[Union[str, ipaddress.IPv4Address, ipaddress.IPv6Address]]
764
+ """
765
+ Local bind address.
766
+ """
767
+
768
+ interface: NotRequired[str]
769
+ """
770
+ Local network interface.
771
+ """
772
+
773
+ gzip: NotRequired[bool]
774
+ """
775
+ Enable gzip decompression.
776
+ """
777
+
778
+ brotli: NotRequired[bool]
779
+ """
780
+ Enable brotli decompression.
781
+ """
782
+
783
+ deflate: NotRequired[bool]
784
+ """
785
+ Enable deflate decompression.
786
+ """
787
+
788
+ zstd: NotRequired[bool]
789
+ """
790
+ Enable zstd decompression.
791
+ """
792
+
793
+ class Request(TypedDict):
794
+ emulation: NotRequired[Union[Emulation, EmulationOption]]
795
+ """
796
+ The Emulation settings for the request.
797
+ """
798
+
799
+ proxy: NotRequired[Proxy]
800
+ """
801
+ The proxy to use for the request.
802
+ """
25
803
 
26
- class RequestParams(TypedDict, closed=True):
27
- proxy: NotRequired[Union[str, Proxy]]
28
804
  local_address: NotRequired[Union[ipaddress.IPv4Address, ipaddress.IPv6Address]]
805
+ """
806
+ Bind to a local IP Address.
807
+ """
808
+
29
809
  interface: NotRequired[str]
810
+ """
811
+ Bind to an interface by SO_BINDTODEVICE.
812
+ """
813
+
30
814
  timeout: NotRequired[int]
815
+ """
816
+ The timeout to use for the request.
817
+ """
818
+
31
819
  read_timeout: NotRequired[int]
820
+ """
821
+ The read timeout to use for the request.
822
+ """
823
+
32
824
  version: NotRequired[Version]
825
+ """
826
+ The HTTP version to use for the request.
827
+ """
828
+
33
829
  headers: NotRequired[Union[Dict[str, str], HeaderMap]]
830
+ """
831
+ The headers to use for the request.
832
+ """
833
+
834
+ orig_headers: NotRequired[Union[List[str], OrigHeaderMap]]
835
+ """
836
+ The original headers to use for the request.
837
+ """
838
+
839
+ default_headers: NotRequired[bool]
840
+ """
841
+ The option enables default headers.
842
+ """
843
+
34
844
  cookies: NotRequired[Dict[str, str]]
845
+ """
846
+ The cookies to use for the request.
847
+ """
848
+
35
849
  allow_redirects: NotRequired[bool]
850
+ """
851
+ Whether to allow redirects.
852
+ """
853
+
36
854
  max_redirects: NotRequired[int]
855
+ """
856
+ The maximum number of redirects to follow.
857
+ """
858
+
859
+ gzip: NotRequired[bool]
860
+ """
861
+ Sets gzip as an accepted encoding.
862
+ """
863
+
864
+ brotli: NotRequired[bool]
865
+ """
866
+ Sets brotli as an accepted encoding.
867
+ """
868
+
869
+ deflate: NotRequired[bool]
870
+ """
871
+ Sets deflate as an accepted encoding.
872
+ """
873
+
874
+ zstd: NotRequired[bool]
875
+ """
876
+ Sets zstd as an accepted encoding.
877
+ """
878
+
37
879
  auth: NotRequired[str]
880
+ """
881
+ The authentication to use for the request.
882
+ """
883
+
38
884
  bearer_auth: NotRequired[str]
885
+ """
886
+ The bearer authentication to use for the request.
887
+ """
888
+
39
889
  basic_auth: NotRequired[Tuple[str, Optional[str]]]
890
+ """
891
+ The basic authentication to use for the request.
892
+ """
893
+
40
894
  query: NotRequired[List[Tuple[str, str]]]
895
+ """
896
+ The query parameters to use for the request.
897
+ """
898
+
41
899
  form: NotRequired[List[Tuple[str, str]]]
900
+ """
901
+ The form parameters to use for the request.
902
+ """
903
+
42
904
  json: NotRequired[Dict[str, Any]]
905
+ """
906
+ The JSON body to use for the request.
907
+ """
908
+
43
909
  body: NotRequired[
44
910
  Union[
45
911
  str,
46
912
  bytes,
47
- typing.AsyncGenerator[bytes, str],
48
- typing.Generator[bytes, str],
913
+ Generator[bytes, str, None],
914
+ AsyncGenerator[bytes, str],
49
915
  ]
50
916
  ]
917
+ """
918
+ The body to use for the request.
919
+ """
920
+
51
921
  multipart: NotRequired[Multipart]
922
+ """
923
+ The multipart form to use for the request.
924
+ """
52
925
 
53
- class WebSocketParams(TypedDict, closed=True):
54
- proxy: NotRequired[Union[str, Proxy]]
55
- local_address: NotRequired[Union[str, ipaddress.IPv4Address, ipaddress.IPv6Address]]
56
- interface: NotRequired[str]
57
- headers: NotRequired[Union[Dict[str, str], HeaderMap]]
58
- cookies: NotRequired[Dict[str, str]]
59
- protocols: NotRequired[List[str]]
60
- use_http2: NotRequired[bool]
61
- auth: NotRequired[str]
62
- bearer_auth: NotRequired[str]
63
- basic_auth: NotRequired[Tuple[str, Optional[str]]]
64
- query: NotRequired[List[Tuple[str, str]]]
65
- read_buffer_size: NotRequired[int]
66
- write_buffer_size: NotRequired[int]
67
- max_write_buffer_size: NotRequired[int]
68
- max_message_size: NotRequired[int]
69
- max_frame_size: NotRequired[int]
70
- accept_unmasked_frames: NotRequired[bool]
926
+ class WebSocketRequest(TypedDict):
927
+ emulation: NotRequired[Union[Emulation, EmulationOption]]
928
+ """
929
+ The Emulation settings for the request.
930
+ """
71
931
 
72
- class ProxyParams(TypedDict, closed=True):
73
- username: NotRequired[str]
74
- password: NotRequired[str]
75
- custom_http_auth: NotRequired[str]
76
- custom_http_headers: NotRequired[Union[Dict[str, str], HeaderMap]]
77
- exclusion: NotRequired[str]
932
+ proxy: NotRequired[Proxy]
933
+ """
934
+ The proxy to use for the request.
935
+ """
78
936
 
79
- class Client:
80
- r"""
81
- A client for making HTTP requests.
937
+ local_address: NotRequired[Union[str, ipaddress.IPv4Address, ipaddress.IPv6Address]]
938
+ """
939
+ Bind to a local IP Address.
82
940
  """
83
941
 
84
- user_agent: Optional[str]
85
- r"""
86
- Returns the user agent of the client.
87
-
88
- # Examples
89
-
90
- ```python
91
- import rnet
92
-
93
- client = rnet.Client()
94
- user_agent = client.user_agent()
95
- print(user_agent)
96
- ```
942
+ interface: NotRequired[str]
97
943
  """
98
- headers: HeaderMap
99
- r"""
100
- Returns the headers of the client.
101
-
102
- # Examples
103
-
104
- ```python
105
- import rnet
106
-
107
- client = rnet.Client()
108
- headers = client.headers()
109
- print(headers)
110
- ```
944
+ Bind to an interface by SO_BINDTODEVICE.
111
945
  """
112
- def __new__(
113
- cls,
114
- impersonate: Optional[Union[Impersonate, ImpersonateOption]] = None,
115
- user_agent: Optional[str] = None,
116
- default_headers: Optional[Union[Dict[str, str], HeaderMap]] = None,
117
- headers_order: Optional[List[str]] = None,
118
- referer: Optional[bool] = None,
119
- allow_redirects: Optional[bool] = None,
120
- max_redirects: Optional[int] = None,
121
- cookie_store: Optional[bool] = None,
122
- lookup_ip_strategy: Optional[LookupIpStrategy] = None,
123
- timeout: Optional[int] = None,
124
- connect_timeout: Optional[int] = None,
125
- read_timeout: Optional[int] = None,
126
- no_keepalive: Optional[bool] = None,
127
- tcp_keepalive: Optional[int] = None,
128
- tcp_keepalive_interval: Optional[int] = None,
129
- tcp_keepalive_retries: Optional[int] = None,
130
- tcp_user_timeout: Optional[int] = None,
131
- pool_idle_timeout: Optional[int] = None,
132
- pool_max_idle_per_host: Optional[int] = None,
133
- pool_max_size: Optional[int] = None,
134
- http1_only: Optional[bool] = None,
135
- http2_only: Optional[bool] = None,
136
- https_only: Optional[bool] = None,
137
- tcp_nodelay: Optional[bool] = None,
138
- http2_max_retry_count: Optional[int] = None,
139
- verify: Optional[Union[bool, Path]] = None,
140
- tls_info: Optional[bool] = None,
141
- min_tls_version: Optional[TlsVersion] = None,
142
- max_tls_version: Optional[TlsVersion] = None,
143
- no_proxy: Optional[bool] = None,
144
- proxies: Optional[List[Proxy]] = None,
145
- local_address: Optional[
146
- Union[str, ipaddress.IPv4Address, ipaddress.IPv6Address]
147
- ] = None,
148
- interface: Optional[str] = None,
149
- gzip: Optional[bool] = None,
150
- brotli: Optional[bool] = None,
151
- deflate: Optional[bool] = None,
152
- zstd: Optional[bool] = None,
153
- ) -> Client:
154
- r"""
155
- Creates a new Client instance.
156
946
 
157
- Args:
158
- impersonate: Browser fingerprint/impersonation config.
159
- user_agent: Default User-Agent string.
160
- default_headers: Default request headers.
161
- headers_order: Custom header order.
162
- referer: Automatically set Referer.
163
- allow_redirects: Allow automatic redirects.
164
- max_redirects: Maximum number of redirects.
165
- cookie_store: Enable cookie store.
166
- lookup_ip_strategy: IP lookup strategy.
167
- timeout: Total timeout (seconds).
168
- connect_timeout: Connection timeout (seconds).
169
- read_timeout: Read timeout (seconds).
170
- no_keepalive: Disable HTTP keep-alive.
171
- tcp_keepalive: TCP keepalive time (seconds).
172
- tcp_keepalive_interval: TCP keepalive interval (seconds).
173
- tcp_keepalive_retries: TCP keepalive retry count.
174
- tcp_user_timeout: TCP user timeout (seconds).
175
- pool_idle_timeout: Connection pool idle timeout (seconds).
176
- pool_max_idle_per_host: Max idle connections per host.
177
- pool_max_size: Max total connections in pool.
178
- http1_only: Enable HTTP/1.1 only.
179
- http2_only: Enable HTTP/2 only.
180
- https_only: Enable HTTPS only.
181
- tcp_nodelay: Enable TCP_NODELAY.
182
- http2_max_retry_count: Max HTTP/2 retry count.
183
- verify: Verify SSL or specify CA path.
184
- tls_info: Return TLS info.
185
- min_tls_version: Minimum TLS version.
186
- max_tls_version: Maximum TLS version.
187
- no_proxy: Disable proxy.
188
- proxies: Proxy server list.
189
- local_address: Local bind address.
190
- interface: Local network interface.
191
- gzip: Enable gzip decompression.
192
- brotli: Enable brotli decompression.
193
- deflate: Enable deflate decompression.
194
- zstd: Enable zstd decompression.
947
+ headers: NotRequired[Union[Dict[str, str], HeaderMap]]
948
+ """
949
+ The headers to use for the request.
950
+ """
195
951
 
196
- Examples:
952
+ orig_headers: NotRequired[Union[List[str], OrigHeaderMap]]
953
+ """
954
+ The original headers to use for the request.
955
+ """
197
956
 
198
- ```python
199
- import asyncio
200
- import rnet
957
+ default_headers: NotRequired[bool]
958
+ """
959
+ The option enables default headers.
960
+ """
201
961
 
202
- client = rnet.Client(
203
- user_agent="my-app/0.0.1",
204
- timeout=10,
205
- )
206
- response = await client.get('https://httpbin.org/get')
207
- print(response.text)
208
- ```
209
- """
962
+ cookies: NotRequired[Dict[str, str]]
963
+ """
964
+ The cookies to use for the request.
965
+ """
210
966
 
211
- def get_cookies(self, url: str) -> Optional[bytes]:
212
- r"""
213
- Returns the cookies for the given URL.
967
+ protocols: NotRequired[List[str]]
968
+ """
969
+ The protocols to use for the request.
970
+ """
214
971
 
215
- # Arguments
972
+ force_http2: NotRequired[bool]
973
+ """
974
+ Whether to use HTTP/2 for the websocket.
975
+ """
216
976
 
217
- * `url` - The URL to get the cookies for.
977
+ auth: NotRequired[str]
978
+ """
979
+ The authentication to use for the request.
980
+ """
981
+
982
+ bearer_auth: NotRequired[str]
983
+ """
984
+ The bearer authentication to use for the request.
985
+ """
218
986
 
219
- # Returns
987
+ basic_auth: NotRequired[Tuple[str, Optional[str]]]
988
+ """
989
+ The basic authentication to use for the request.
990
+ """
220
991
 
221
- A List of cookie strings.
992
+ query: NotRequired[List[Tuple[str, str]]]
993
+ """
994
+ The query parameters to use for the request.
995
+ """
222
996
 
223
- # Examples
997
+ read_buffer_size: NotRequired[int]
998
+ """
999
+ Read buffer capacity. This buffer is eagerly allocated and used for receiving messages.
224
1000
 
225
- ```python
226
- import rnet
1001
+ For high read load scenarios a larger buffer, e.g. 128 KiB, improves performance.
227
1002
 
228
- client = rnet.Client(cookie_store=True)
229
- cookies = client.get_cookies("https://example.com")
230
- print(cookies)
231
- ```
232
- """
1003
+ For scenarios where you expect a lot of connections and don't need high read load
1004
+ performance a smaller buffer, e.g. 4 KiB, would be appropriate to lower total
1005
+ memory usage.
233
1006
 
234
- def set_cookie(self, url: str, cookie: Cookie) -> None:
235
- r"""
236
- Sets the cookies for the given URL.
1007
+ The default value is 128 KiB.
1008
+ """
237
1009
 
238
- # Arguments
239
- * `url` - The URL to set the cookies for.
240
- * `cookie` - The cookie to set.
1010
+ write_buffer_size: NotRequired[int]
1011
+ """
1012
+ The target minimum size of the write buffer to reach before writing the data
1013
+ to the underlying stream. The default value is 128 KiB.
241
1014
 
242
- # Examples
1015
+ If set to 0 each message will be eagerly written to the underlying stream.
1016
+ It is often more optimal to allow them to buffer a little, hence the default value.
243
1017
 
244
- ```python
245
- import rnet
1018
+ Note: flush() will always fully write the buffer regardless.
1019
+ """
246
1020
 
247
- client = rnet.Client(cookie_store=True)
248
- client.set_cookie("https://example.com", rnet.Cookie(name="foo", value="bar"))
249
- ```
250
- """
1021
+ max_write_buffer_size: NotRequired[int]
1022
+ """
1023
+ The max size of the write buffer in bytes. Setting this can provide backpressure
1024
+ in the case the write buffer is filling up due to write errors.
1025
+ The default value is unlimited.
251
1026
 
252
- def remove_cookie(self, url: str, name: str) -> None:
253
- r"""
254
- Removes the cookie with the given name for the given URL.
1027
+ Note: The write buffer only builds up past write_buffer_size when writes to the
1028
+ underlying stream are failing. So the write buffer can not fill up if you are not
1029
+ observing write errors even if not flushing.
255
1030
 
256
- # Arguments
257
- * `url` - The URL to remove the cookie from.
258
- * `name` - The name of the cookie to remove.
1031
+ Note: Should always be at least write_buffer_size + 1 message and probably a little
1032
+ more depending on error handling strategy.
1033
+ """
259
1034
 
260
- # Examples
1035
+ max_message_size: NotRequired[int]
1036
+ """
1037
+ The maximum size of an incoming message. None means no size limit.
1038
+ The default value is 64 MiB which should be reasonably big for all normal use-cases
1039
+ but small enough to prevent memory eating by a malicious user.
1040
+ """
261
1041
 
262
- ```python
263
- import rnet
1042
+ max_frame_size: NotRequired[int]
1043
+ """
1044
+ The maximum size of a single incoming message frame. None means no size limit.
1045
+ The limit is for frame payload NOT including the frame header.
1046
+ The default value is 16 MiB which should be reasonably big for all normal use-cases
1047
+ but small enough to prevent memory eating by a malicious user.
1048
+ """
264
1049
 
265
- client = rnet.Client(cookie_store=True)
266
- client.remove_cookie("https://example.com", "foo")
267
- """
1050
+ accept_unmasked_frames: NotRequired[bool]
1051
+ """
1052
+ When set to True, the server will accept and handle unmasked frames from the client.
1053
+ According to RFC 6455, the server must close the connection to the client in such cases,
1054
+ however it seems like there are some popular libraries that are sending unmasked frames,
1055
+ ignoring the RFC. By default this option is set to False, i.e. according to RFC6455.
1056
+ """
268
1057
 
269
- def clear_cookies(self) -> None:
270
- r"""
271
- Clears the cookies for the given URL.
272
- """
1058
+ class Client:
1059
+ r"""
1060
+ A client for making HTTP requests.
1061
+ """
273
1062
 
274
- def update(
1063
+ def __init__(
275
1064
  self,
276
- impersonate: Optional[Union[Impersonate, ImpersonateOption]] = None,
277
- headers: Optional[Union[Dict[str, str], HeaderMap]] = None,
278
- headers_order: Optional[List[str]] = None,
279
- proxies: Optional[List[Proxy]] = None,
280
- local_address: Optional[
281
- Union[ipaddress.IPv4Address, ipaddress.IPv6Address]
282
- ] = None,
283
- interface: Optional[str] = None,
1065
+ **kwargs: Unpack[ClientParams],
284
1066
  ) -> None:
285
1067
  r"""
286
- Updates the client with the given parameters.
287
-
288
- # Arguments
289
-
290
- * `impersonate` - The impersonation settings for the request.
291
- * `headers` - The headers to use for the request.
292
- * `headers_order` - The order of the headers to use for the request.
293
- * `proxies` - The proxy to use for the request.
294
- * `local_address` - The local IP address to bind to.
295
- * `interface` - The interface to bind to.
1068
+ Creates a new Client instance.
296
1069
 
297
- # Examples
1070
+ Examples:
298
1071
 
299
1072
  ```python
1073
+ import asyncio
300
1074
  import rnet
301
1075
 
302
- client = rnet.Client()
303
- client.update(
304
- impersonate=rnet.Impersonate.Firefox135,
305
- headers={"X-My-Header": "value"},
306
- proxies=[rnet.Proxy.all("http://proxy.example.com:8080")],
307
- )
1076
+ async def main():
1077
+ client = rnet.Client(
1078
+ user_agent="Mozilla/5.0",
1079
+ timeout=10,
1080
+ )
1081
+ response = await client.get('https://httpbin.org/get')
1082
+ print(await response.text())
1083
+
1084
+ asyncio.run(main())
308
1085
  ```
309
1086
  """
1087
+ ...
310
1088
 
311
1089
  async def request(
312
1090
  self,
313
1091
  method: Method,
314
1092
  url: str,
315
- **kwargs: Unpack[RequestParams],
1093
+ **kwargs: Unpack[Request],
316
1094
  ) -> Response:
317
1095
  r"""
318
1096
  Sends a request with the given method and URL.
@@ -336,7 +1114,7 @@ class Client:
336
1114
  async def websocket(
337
1115
  self,
338
1116
  url: str,
339
- **kwargs: Unpack[WebSocketParams],
1117
+ **kwargs: Unpack[WebSocketRequest],
340
1118
  ) -> WebSocket:
341
1119
  r"""
342
1120
  Sends a WebSocket request.
@@ -362,7 +1140,7 @@ class Client:
362
1140
  async def trace(
363
1141
  self,
364
1142
  url: str,
365
- **kwargs: Unpack[RequestParams],
1143
+ **kwargs: Unpack[Request],
366
1144
  ) -> Response:
367
1145
  r"""
368
1146
  Sends a request with the given URL
@@ -386,7 +1164,7 @@ class Client:
386
1164
  async def options(
387
1165
  self,
388
1166
  url: str,
389
- **kwargs: Unpack[RequestParams],
1167
+ **kwargs: Unpack[Request],
390
1168
  ) -> Response:
391
1169
  r"""
392
1170
  Sends a request with the given URL
@@ -410,7 +1188,7 @@ class Client:
410
1188
  async def patch(
411
1189
  self,
412
1190
  url: str,
413
- **kwargs: Unpack[RequestParams],
1191
+ **kwargs: Unpack[Request],
414
1192
  ) -> Response:
415
1193
  r"""
416
1194
  Sends a request with the given URL
@@ -434,7 +1212,7 @@ class Client:
434
1212
  async def delete(
435
1213
  self,
436
1214
  url: str,
437
- **kwargs: Unpack[RequestParams],
1215
+ **kwargs: Unpack[Request],
438
1216
  ) -> Response:
439
1217
  r"""
440
1218
  Sends a request with the given URL
@@ -458,7 +1236,7 @@ class Client:
458
1236
  async def put(
459
1237
  self,
460
1238
  url: str,
461
- **kwargs: Unpack[RequestParams],
1239
+ **kwargs: Unpack[Request],
462
1240
  ) -> Response:
463
1241
  r"""
464
1242
  Sends a request with the given URL
@@ -482,7 +1260,7 @@ class Client:
482
1260
  async def post(
483
1261
  self,
484
1262
  url: str,
485
- **kwargs: Unpack[RequestParams],
1263
+ **kwargs: Unpack[Request],
486
1264
  ) -> Response:
487
1265
  r"""
488
1266
  Sends a request with the given URL
@@ -506,7 +1284,7 @@ class Client:
506
1284
  async def head(
507
1285
  self,
508
1286
  url: str,
509
- **kwargs: Unpack[RequestParams],
1287
+ **kwargs: Unpack[Request],
510
1288
  ) -> Response:
511
1289
  r"""
512
1290
  Sends a request with the given URL
@@ -530,7 +1308,7 @@ class Client:
530
1308
  async def get(
531
1309
  self,
532
1310
  url: str,
533
- **kwargs: Unpack[RequestParams],
1311
+ **kwargs: Unpack[Request],
534
1312
  ) -> Response:
535
1313
  r"""
536
1314
  Sends a request with the given URL
@@ -540,261 +1318,20 @@ class Client:
540
1318
  ```python
541
1319
  import rnet
542
1320
  import asyncio
543
- from rnet import Method
544
-
545
- async def main():
546
- client = rnet.Client()
547
- response = await client.get("https://httpbin.org/anything")
548
- print(await response.text())
549
-
550
- asyncio.run(main())
551
- ```
552
- """
553
-
554
- class Multipart:
555
- r"""
556
- A multipart form for a request.
557
- """
558
-
559
- def __new__(cls, *parts) -> Multipart:
560
- r"""
561
- Creates a new multipart form.
562
- """
563
-
564
- class Part:
565
- r"""
566
- A part of a multipart form.
567
- """
568
-
569
- def __new__(
570
- cls,
571
- name: str,
572
- value: Union[
573
- str,
574
- bytes,
575
- Path,
576
- typing.AsyncGenerator[bytes, str],
577
- typing.Generator[bytes, str],
578
- ],
579
- filename: Optional[str] = None,
580
- mime: Optional[str] = None,
581
- ) -> Part:
582
- r"""
583
- Creates a new part.
584
-
585
- # Arguments
586
- - `name` - The name of the part.
587
- - `value` - The value of the part, either text, bytes, a file path, or a async or sync stream.
588
- - `filename` - The filename of the part.
589
- - `mime` - The MIME type of the part.
590
- """
591
-
592
- class Response:
593
- r"""
594
- A response from a request.
595
-
596
- # Examples
597
-
598
- ```python
599
- import asyncio
600
- import rnet
601
-
602
- async def main():
603
- response = await rnet.get("https://www.rust-lang.org")
604
- print("Status Code: ", response.status_code)
605
- print("Version: ", response.version)
606
- print("Response URL: ", response.url)
607
- print("Headers: ", response.headers)
608
- print("Content-Length: ", response.content_length)
609
- print("Encoding: ", response.encoding)
610
- print("Remote Address: ", response.remote_addr)
611
-
612
- text_content = await response.text()
613
- print("Text: ", text_content)
614
-
615
- if __name__ == "__main__":
616
- asyncio.run(main())
617
- ```
618
- """
619
-
620
- url: str
621
- r"""
622
- Returns the URL of the response.
623
- """
624
- ok: bool
625
- r"""
626
- Returns whether the response is successful.
627
- """
628
- status: int
629
- r"""
630
- Returns the status code as integer of the response.
631
- """
632
- status_code: StatusCode
633
- r"""
634
- Returns the status code of the response.
635
- """
636
- version: Version
637
- r"""
638
- Returns the HTTP version of the response.
639
- """
640
- headers: HeaderMap
641
- r"""
642
- Returns the headers of the response.
643
- """
644
- cookies: List[Cookie]
645
- r"""
646
- Returns the cookies of the response.
647
- """
648
- content_length: int
649
- r"""
650
- Returns the content length of the response.
651
- """
652
- remote_addr: Optional[SocketAddr]
653
- r"""
654
- Returns the remote address of the response.
655
- """
656
- encoding: str
657
- r"""
658
- Encoding to decode with when accessing text.
659
- """
660
- def __aenter__(self) -> Any: ...
661
- def __aexit__(self, _exc_type: Any, _exc_value: Any, _traceback: Any) -> Any: ...
662
- def peer_certificate(self) -> Optional[bytes]:
663
- r"""
664
- Returns the TLS peer certificate of the response.
665
- """
666
-
667
- async def text(self) -> str:
668
- r"""
669
- Returns the text content of the response.
670
- """
671
-
672
- async def text_with_charset(self, encoding: str) -> str:
673
- r"""
674
- Returns the text content of the response with a specific charset.
675
-
676
- # Arguments
677
-
678
- * `encoding` - The default encoding to use if the charset is not specified.
679
- """
680
-
681
- async def json(self) -> Any:
682
- r"""
683
- Returns the JSON content of the response.
684
- """
685
-
686
- async def bytes(self) -> bytes:
687
- r"""
688
- Returns the bytes content of the response.
689
- """
690
-
691
- def stream(self) -> Streamer:
692
- r"""
693
- Convert the response into a `Stream` of `Bytes` from the body.
694
- """
695
-
696
- async def close(self) -> None:
697
- r"""
698
- Closes the response connection.
699
- """
700
-
701
- class SocketAddr:
702
- r"""
703
- A IP socket address.
704
- """
705
-
706
- def __str__(self) -> str: ...
707
- def __repr__(self) -> str: ...
708
- def ip(self) -> Union[ipaddress.IPv4Address, ipaddress.IPv6Address]:
709
- r"""
710
- Returns the IP address of the socket address.
711
- """
712
-
713
- def port(self) -> int:
714
- r"""
715
- Returns the port number of the socket address.
716
- """
717
-
718
- class StatusCode:
719
- r"""
720
- HTTP status code.
721
- """
722
-
723
- def __str__(self) -> str: ...
724
- def __repr__(self) -> str: ...
725
- def as_int(self) -> int:
726
- r"""
727
- Return the status code as an integer.
728
- """
729
-
730
- def is_informational(self) -> bool:
731
- r"""
732
- Check if status is within 100-199.
733
- """
734
-
735
- def is_success(self) -> bool:
736
- r"""
737
- Check if status is within 200-299.
738
- """
739
-
740
- def is_redirection(self) -> bool:
741
- r"""
742
- Check if status is within 300-399.
743
- """
744
-
745
- def is_client_error(self) -> bool:
746
- r"""
747
- Check if status is within 400-499.
748
- """
749
-
750
- def is_server_error(self) -> bool:
751
- r"""
752
- Check if status is within 500-599.
753
- """
754
-
755
- class Streamer:
756
- r"""
757
- A byte stream response.
758
- An asynchronous iterator yielding data chunks from the response stream.
759
- Used to stream response content.
760
- Implemented in the `stream` method of the `Response` class.
761
- Can be used in an asynchronous for loop in Python.
762
-
763
- # Examples
764
-
765
- ```python
766
- import asyncio
767
- import rnet
768
- from rnet import Method, Impersonate
769
-
770
- async def main():
771
- resp = await rnet.get("https://httpbin.org/stream/20")
772
- print("Status Code: ", resp.status_code)
773
- print("Version: ", resp.version)
774
- print("Response URL: ", resp.url)
775
- print("Headers: ", resp.headers)
776
- print("Content-Length: ", resp.content_length)
777
- print("Encoding: ", resp.encoding)
778
- print("Remote Address: ", resp.remote_addr)
1321
+ from rnet import Method
779
1322
 
780
- async with resp.stream() as streamer:
781
- async for chunk in streamer:
782
- print("Chunk: ", chunk)
783
- await asyncio.sleep(0.1)
1323
+ async def main():
1324
+ client = rnet.Client()
1325
+ response = await client.get("https://httpbin.org/anything")
1326
+ print(await response.text())
784
1327
 
785
- if __name__ == "__main__":
786
1328
  asyncio.run(main())
787
- ```
788
- """
789
-
790
- def __aiter__(self) -> Streamer: ...
791
- def __anext__(self) -> Any: ...
792
- def __aenter__(self) -> Any: ...
793
- def __aexit__(self, _exc_type: Any, _exc_value: Any, _traceback: Any) -> Any: ...
1329
+ ```
1330
+ """
794
1331
 
795
1332
  async def delete(
796
1333
  url: str,
797
- **kwargs: Unpack[RequestParams],
1334
+ **kwargs: Unpack[Request],
798
1335
  ) -> Response:
799
1336
  r"""
800
1337
  Shortcut method to quickly make a request.
@@ -816,7 +1353,7 @@ async def delete(
816
1353
 
817
1354
  async def get(
818
1355
  url: str,
819
- **kwargs: Unpack[RequestParams],
1356
+ **kwargs: Unpack[Request],
820
1357
  ) -> Response:
821
1358
  r"""
822
1359
  Shortcut method to quickly make a request.
@@ -838,7 +1375,7 @@ async def get(
838
1375
 
839
1376
  async def head(
840
1377
  url: str,
841
- **kwargs: Unpack[RequestParams],
1378
+ **kwargs: Unpack[Request],
842
1379
  ) -> Response:
843
1380
  r"""
844
1381
  Shortcut method to quickly make a request.
@@ -859,7 +1396,7 @@ async def head(
859
1396
 
860
1397
  async def options(
861
1398
  url: str,
862
- **kwargs: Unpack[RequestParams],
1399
+ **kwargs: Unpack[Request],
863
1400
  ) -> Response:
864
1401
  r"""
865
1402
  Shortcut method to quickly make a request.
@@ -880,7 +1417,7 @@ async def options(
880
1417
 
881
1418
  async def patch(
882
1419
  url: str,
883
- **kwargs: Unpack[RequestParams],
1420
+ **kwargs: Unpack[Request],
884
1421
  ) -> Response:
885
1422
  r"""
886
1423
  Shortcut method to quickly make a request.
@@ -902,7 +1439,7 @@ async def patch(
902
1439
 
903
1440
  async def post(
904
1441
  url: str,
905
- **kwargs: Unpack[RequestParams],
1442
+ **kwargs: Unpack[Request],
906
1443
  ) -> Response:
907
1444
  r"""
908
1445
  Shortcut method to quickly make a request.
@@ -924,7 +1461,7 @@ async def post(
924
1461
 
925
1462
  async def put(
926
1463
  url: str,
927
- **kwargs: Unpack[RequestParams],
1464
+ **kwargs: Unpack[Request],
928
1465
  ) -> Response:
929
1466
  r"""
930
1467
  Shortcut method to quickly make a request.
@@ -947,7 +1484,7 @@ async def put(
947
1484
  async def request(
948
1485
  method: Method,
949
1486
  url: str,
950
- **kwargs: Unpack[RequestParams],
1487
+ **kwargs: Unpack[Request],
951
1488
  ) -> Response:
952
1489
  r"""
953
1490
  Make a request with the given parameters.
@@ -976,7 +1513,7 @@ async def request(
976
1513
 
977
1514
  async def trace(
978
1515
  url: str,
979
- **kwargs: Unpack[RequestParams],
1516
+ **kwargs: Unpack[Request],
980
1517
  ) -> Response:
981
1518
  r"""
982
1519
  Shortcut method to quickly make a request.
@@ -997,7 +1534,7 @@ async def trace(
997
1534
 
998
1535
  async def websocket(
999
1536
  url: str,
1000
- **kwargs: Unpack[WebSocketParams],
1537
+ **kwargs: Unpack[WebSocketRequest],
1001
1538
  ) -> WebSocket:
1002
1539
  r"""
1003
1540
  Make a WebSocket connection with the given parameters.
@@ -1019,304 +1556,3 @@ async def websocket(
1019
1556
  asyncio.run(run())
1020
1557
  ```
1021
1558
  """
1022
-
1023
- class Proxy:
1024
- r"""
1025
- A proxy server for a request.
1026
- Supports HTTP, HTTPS, SOCKS4, SOCKS4a, SOCKS5, and SOCKS5h protocols.
1027
- """
1028
-
1029
- @staticmethod
1030
- def http(url: str, **kwargs: Unpack[ProxyParams]) -> Proxy:
1031
- r"""
1032
- Creates a new HTTP proxy.
1033
-
1034
- This method sets up a proxy server for HTTP requests.
1035
-
1036
- # Arguments
1037
-
1038
- * `url` - The URL of the proxy server.
1039
- * `username` - Optional username for proxy authentication.
1040
- * `password` - Optional password for proxy authentication.
1041
- * `custom_http_auth` - Optional custom HTTP proxy authentication header value.
1042
- * `custom_http_headers` - Optional custom HTTP proxy headers.
1043
- * `exclusion` - Optional List of domains to exclude from proxying.
1044
-
1045
- # Examples
1046
-
1047
- ```python
1048
- import rnet
1049
-
1050
- proxy = rnet.Proxy.http("http://proxy.example.com")
1051
- ```
1052
- """
1053
-
1054
- @staticmethod
1055
- def https(url: str, **kwargs: Unpack[ProxyParams]) -> Proxy:
1056
- r"""
1057
- Creates a new HTTPS proxy.
1058
-
1059
- This method sets up a proxy server for HTTPS requests.
1060
-
1061
- # Arguments
1062
-
1063
- * `url` - The URL of the proxy server.
1064
- * `username` - Optional username for proxy authentication.
1065
- * `password` - Optional password for proxy authentication.
1066
- * `custom_http_auth` - Optional custom HTTP proxy authentication header value.
1067
- * `custom_http_headers` - Optional custom HTTP proxy headers.
1068
- * `exclusion` - Optional List of domains to exclude from proxying.
1069
-
1070
- # Examples
1071
-
1072
- ```python
1073
- import rnet
1074
-
1075
- proxy = rnet.Proxy.https("https://proxy.example.com")
1076
- ```
1077
- """
1078
-
1079
- @staticmethod
1080
- def all(url: str, **kwargs: Unpack[ProxyParams]) -> Proxy:
1081
- r"""
1082
- Creates a new proxy for all protocols.
1083
-
1084
- This method sets up a proxy server for all types of requests (HTTP, HTTPS, etc.).
1085
-
1086
- # Arguments
1087
-
1088
- * `url` - The URL of the proxy server.
1089
- * `username` - Optional username for proxy authentication.
1090
- * `password` - Optional password for proxy authentication.
1091
- * `custom_http_auth` - Optional custom HTTP proxy authentication header value.
1092
- * `custom_http_headers` - Optional custom HTTP proxy headers.
1093
- * `exclusion` - Optional List of domains to exclude from proxying.
1094
-
1095
- # Examples
1096
-
1097
- ```python
1098
- import rnet
1099
-
1100
- proxy = rnet.Proxy.all("https://proxy.example.com")
1101
- ```
1102
- """
1103
-
1104
- class Message:
1105
- r"""
1106
- A WebSocket message.
1107
- """
1108
-
1109
- data: Optional[bytes]
1110
- r"""
1111
- Returns the data of the message as bytes.
1112
- """
1113
- text: Optional[str]
1114
- r"""
1115
- Returns the text content of the message if it is a text message.
1116
- """
1117
- binary: Optional[bytes]
1118
- r"""
1119
- Returns the binary data of the message if it is a binary message.
1120
- """
1121
- ping: Optional[bytes]
1122
- r"""
1123
- Returns the ping data of the message if it is a ping message.
1124
- """
1125
- pong: Optional[bytes]
1126
- r"""
1127
- Returns the pong data of the message if it is a pong message.
1128
- """
1129
- close: Optional[Tuple[int, Optional[str]]]
1130
- r"""
1131
- Returns the close code and reason of the message if it is a close message.
1132
- """
1133
- def __str__(self) -> str: ...
1134
- def __repr__(self) -> str: ...
1135
- @staticmethod
1136
- def text_from_json(json: Dict[str, Any]) -> Message:
1137
- r"""
1138
- Creates a new text message from the JSON representation.
1139
-
1140
- # Arguments
1141
- * `json` - The JSON representation of the message.
1142
- """
1143
-
1144
- @staticmethod
1145
- def binary_from_json(json: Dict[str, Any]) -> Message:
1146
- r"""
1147
- Creates a new binary message from the JSON representation.
1148
-
1149
- # Arguments
1150
- * `json` - The JSON representation of the message.
1151
- """
1152
-
1153
- @staticmethod
1154
- def from_text(text: str) -> Message:
1155
- r"""
1156
- Creates a new text message.
1157
-
1158
- # Arguments
1159
-
1160
- * `text` - The text content of the message.
1161
- """
1162
-
1163
- @staticmethod
1164
- def from_binary(data: bytes) -> Message:
1165
- r"""
1166
- Creates a new binary message.
1167
-
1168
- # Arguments
1169
-
1170
- * `data` - The binary data of the message.
1171
- """
1172
-
1173
- @staticmethod
1174
- def from_ping(data: bytes) -> Message:
1175
- r"""
1176
- Creates a new ping message.
1177
-
1178
- # Arguments
1179
-
1180
- * `data` - The ping data of the message.
1181
- """
1182
-
1183
- @staticmethod
1184
- def from_pong(data: bytes) -> Message:
1185
- r"""
1186
- Creates a new pong message.
1187
-
1188
- # Arguments
1189
-
1190
- * `data` - The pong data of the message.
1191
- """
1192
-
1193
- @staticmethod
1194
- def from_close(code: int, reason: Optional[str] = None) -> Message:
1195
- r"""
1196
- Creates a new close message.
1197
-
1198
- # Arguments
1199
-
1200
- * `code` - The close code.
1201
- * `reason` - An optional reason for closing.
1202
- """
1203
-
1204
- def json(self) -> Dict[str, Any]:
1205
- r"""
1206
- Returns the JSON representation of the message.
1207
- """
1208
-
1209
- class WebSocket:
1210
- r"""
1211
- A WebSocket response.
1212
- """
1213
-
1214
- ok: bool
1215
- r"""
1216
- Returns whether the response is successful.
1217
- """
1218
- status: int
1219
- r"""
1220
- Returns the status code as integer of the response.
1221
- """
1222
- status_code: StatusCode
1223
- r"""
1224
- Returns the status code of the response.
1225
- """
1226
- version: Version
1227
- r"""
1228
- Returns the HTTP version of the response.
1229
- """
1230
- headers: HeaderMap
1231
- r"""
1232
- Returns the headers of the response.
1233
- """
1234
- cookies: List[Cookie]
1235
- r"""
1236
- Returns the cookies of the response.
1237
- """
1238
- remote_addr: Optional[SocketAddr]
1239
- r"""
1240
- Returns the remote address of the response.
1241
- """
1242
- protocol: Optional[str]
1243
- r"""
1244
- Returns the WebSocket protocol.
1245
- """
1246
- def __aiter__(self) -> WebSocket: ...
1247
- def __anext__(self) -> Any: ...
1248
- def __aenter__(self) -> Any: ...
1249
- def __aexit__(self, _exc_type: Any, _exc_value: Any, _traceback: Any) -> Any: ...
1250
- async def recv(self) -> Optional[Message]:
1251
- r"""
1252
- Receives a message from the WebSocket.
1253
- """
1254
-
1255
- async def send(self, message: Message) -> None:
1256
- r"""
1257
- Sends a message to the WebSocket.
1258
-
1259
- # Arguments
1260
-
1261
- * `message` - The message to send.
1262
- """
1263
-
1264
- async def close(
1265
- self,
1266
- code: Optional[int] = None,
1267
- reason: Optional[str] = None,
1268
- ) -> None:
1269
- r"""
1270
- Closes the WebSocket connection.
1271
-
1272
- # Arguments
1273
-
1274
- * `code` - An optional close code.
1275
- * `reason` - An optional reason for closing.
1276
- """
1277
-
1278
- class LookupIpStrategy(Enum):
1279
- r"""
1280
- The lookup ip strategy.
1281
- """
1282
-
1283
- Ipv4Only = auto()
1284
- Ipv6Only = auto()
1285
- Ipv4AndIpv6 = auto()
1286
- Ipv6thenIpv4 = auto()
1287
- Ipv4thenIpv6 = auto()
1288
-
1289
- class Method(Enum):
1290
- r"""
1291
- An HTTP method.
1292
- """
1293
-
1294
- GET = auto()
1295
- HEAD = auto()
1296
- POST = auto()
1297
- PUT = auto()
1298
- DELETE = auto()
1299
- OPTIONS = auto()
1300
- TRACE = auto()
1301
- PATCH = auto()
1302
-
1303
- class TlsVersion(Enum):
1304
- r"""
1305
- The TLS version.
1306
- """
1307
-
1308
- TLS_1_0 = auto()
1309
- TLS_1_1 = auto()
1310
- TLS_1_2 = auto()
1311
- TLS_1_3 = auto()
1312
-
1313
- class Version(Enum):
1314
- r"""
1315
- An HTTP version.
1316
- """
1317
-
1318
- HTTP_09 = auto()
1319
- HTTP_10 = auto()
1320
- HTTP_11 = auto()
1321
- HTTP_2 = auto()
1322
- HTTP_3 = auto()