rnet 3.0.0rc9__cp314-cp314t-manylinux_2_34_aarch64.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 ADDED
@@ -0,0 +1,1558 @@
1
+ import datetime
2
+ import ipaddress
3
+ from typing import (
4
+ AsyncGenerator,
5
+ Generator,
6
+ Optional,
7
+ Tuple,
8
+ Union,
9
+ Any,
10
+ Dict,
11
+ List,
12
+ TypedDict,
13
+ Unpack,
14
+ NotRequired,
15
+ )
16
+ from pathlib import Path
17
+ from enum import Enum, auto
18
+
19
+ from .http1 import Http1Options
20
+ from .http2 import Http2Options
21
+ from .cookie import *
22
+ from .header import *
23
+ from .emulation import *
24
+ from .tls import *
25
+
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
+ """
803
+
804
+ local_address: NotRequired[Union[ipaddress.IPv4Address, ipaddress.IPv6Address]]
805
+ """
806
+ Bind to a local IP Address.
807
+ """
808
+
809
+ interface: NotRequired[str]
810
+ """
811
+ Bind to an interface by SO_BINDTODEVICE.
812
+ """
813
+
814
+ timeout: NotRequired[int]
815
+ """
816
+ The timeout to use for the request.
817
+ """
818
+
819
+ read_timeout: NotRequired[int]
820
+ """
821
+ The read timeout to use for the request.
822
+ """
823
+
824
+ version: NotRequired[Version]
825
+ """
826
+ The HTTP version to use for the request.
827
+ """
828
+
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
+
844
+ cookies: NotRequired[Dict[str, str]]
845
+ """
846
+ The cookies to use for the request.
847
+ """
848
+
849
+ allow_redirects: NotRequired[bool]
850
+ """
851
+ Whether to allow redirects.
852
+ """
853
+
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
+
879
+ auth: NotRequired[str]
880
+ """
881
+ The authentication to use for the request.
882
+ """
883
+
884
+ bearer_auth: NotRequired[str]
885
+ """
886
+ The bearer authentication to use for the request.
887
+ """
888
+
889
+ basic_auth: NotRequired[Tuple[str, Optional[str]]]
890
+ """
891
+ The basic authentication to use for the request.
892
+ """
893
+
894
+ query: NotRequired[List[Tuple[str, str]]]
895
+ """
896
+ The query parameters to use for the request.
897
+ """
898
+
899
+ form: NotRequired[List[Tuple[str, str]]]
900
+ """
901
+ The form parameters to use for the request.
902
+ """
903
+
904
+ json: NotRequired[Dict[str, Any]]
905
+ """
906
+ The JSON body to use for the request.
907
+ """
908
+
909
+ body: NotRequired[
910
+ Union[
911
+ str,
912
+ bytes,
913
+ Generator[bytes, str, None],
914
+ AsyncGenerator[bytes, str],
915
+ ]
916
+ ]
917
+ """
918
+ The body to use for the request.
919
+ """
920
+
921
+ multipart: NotRequired[Multipart]
922
+ """
923
+ The multipart form to use for the request.
924
+ """
925
+
926
+ class WebSocketRequest(TypedDict):
927
+ emulation: NotRequired[Union[Emulation, EmulationOption]]
928
+ """
929
+ The Emulation settings for the request.
930
+ """
931
+
932
+ proxy: NotRequired[Proxy]
933
+ """
934
+ The proxy to use for the request.
935
+ """
936
+
937
+ local_address: NotRequired[Union[str, ipaddress.IPv4Address, ipaddress.IPv6Address]]
938
+ """
939
+ Bind to a local IP Address.
940
+ """
941
+
942
+ interface: NotRequired[str]
943
+ """
944
+ Bind to an interface by SO_BINDTODEVICE.
945
+ """
946
+
947
+ headers: NotRequired[Union[Dict[str, str], HeaderMap]]
948
+ """
949
+ The headers to use for the request.
950
+ """
951
+
952
+ orig_headers: NotRequired[Union[List[str], OrigHeaderMap]]
953
+ """
954
+ The original headers to use for the request.
955
+ """
956
+
957
+ default_headers: NotRequired[bool]
958
+ """
959
+ The option enables default headers.
960
+ """
961
+
962
+ cookies: NotRequired[Dict[str, str]]
963
+ """
964
+ The cookies to use for the request.
965
+ """
966
+
967
+ protocols: NotRequired[List[str]]
968
+ """
969
+ The protocols to use for the request.
970
+ """
971
+
972
+ force_http2: NotRequired[bool]
973
+ """
974
+ Whether to use HTTP/2 for the websocket.
975
+ """
976
+
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
+ """
986
+
987
+ basic_auth: NotRequired[Tuple[str, Optional[str]]]
988
+ """
989
+ The basic authentication to use for the request.
990
+ """
991
+
992
+ query: NotRequired[List[Tuple[str, str]]]
993
+ """
994
+ The query parameters to use for the request.
995
+ """
996
+
997
+ read_buffer_size: NotRequired[int]
998
+ """
999
+ Read buffer capacity. This buffer is eagerly allocated and used for receiving messages.
1000
+
1001
+ For high read load scenarios a larger buffer, e.g. 128 KiB, improves performance.
1002
+
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.
1006
+
1007
+ The default value is 128 KiB.
1008
+ """
1009
+
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.
1014
+
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.
1017
+
1018
+ Note: flush() will always fully write the buffer regardless.
1019
+ """
1020
+
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.
1026
+
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.
1030
+
1031
+ Note: Should always be at least write_buffer_size + 1 message and probably a little
1032
+ more depending on error handling strategy.
1033
+ """
1034
+
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
+ """
1041
+
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
+ """
1049
+
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
+ """
1057
+
1058
+ class Client:
1059
+ r"""
1060
+ A client for making HTTP requests.
1061
+ """
1062
+
1063
+ def __init__(
1064
+ self,
1065
+ **kwargs: Unpack[ClientParams],
1066
+ ) -> None:
1067
+ r"""
1068
+ Creates a new Client instance.
1069
+
1070
+ Examples:
1071
+
1072
+ ```python
1073
+ import asyncio
1074
+ import rnet
1075
+
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())
1085
+ ```
1086
+ """
1087
+ ...
1088
+
1089
+ async def request(
1090
+ self,
1091
+ method: Method,
1092
+ url: str,
1093
+ **kwargs: Unpack[Request],
1094
+ ) -> Response:
1095
+ r"""
1096
+ Sends a request with the given method and URL.
1097
+
1098
+ # Examples
1099
+
1100
+ ```python
1101
+ import rnet
1102
+ import asyncio
1103
+ from rnet import Method
1104
+
1105
+ async def main():
1106
+ client = rnet.Client()
1107
+ response = await client.request(Method.GET, "https://httpbin.org/anything")
1108
+ print(await response.text())
1109
+
1110
+ asyncio.run(main())
1111
+ ```
1112
+ """
1113
+
1114
+ async def websocket(
1115
+ self,
1116
+ url: str,
1117
+ **kwargs: Unpack[WebSocketRequest],
1118
+ ) -> WebSocket:
1119
+ r"""
1120
+ Sends a WebSocket request.
1121
+
1122
+ # Examples
1123
+
1124
+ ```python
1125
+ import rnet
1126
+ import asyncio
1127
+
1128
+ async def main():
1129
+ client = rnet.Client()
1130
+ ws = await client.websocket("wss://echo.websocket.org")
1131
+ await ws.send(rnet.Message.from_text("Hello, WebSocket!"))
1132
+ message = await ws.recv()
1133
+ print("Received:", message.data)
1134
+ await ws.close()
1135
+
1136
+ asyncio.run(main())
1137
+ ```
1138
+ """
1139
+
1140
+ async def trace(
1141
+ self,
1142
+ url: str,
1143
+ **kwargs: Unpack[Request],
1144
+ ) -> Response:
1145
+ r"""
1146
+ Sends a request with the given URL
1147
+
1148
+ # Examples
1149
+
1150
+ ```python
1151
+ import rnet
1152
+ import asyncio
1153
+ from rnet import Method
1154
+
1155
+ async def main():
1156
+ client = rnet.Client()
1157
+ response = await client.trace("https://httpbin.org/anything")
1158
+ print(await response.text())
1159
+
1160
+ asyncio.run(main())
1161
+ ```
1162
+ """
1163
+
1164
+ async def options(
1165
+ self,
1166
+ url: str,
1167
+ **kwargs: Unpack[Request],
1168
+ ) -> Response:
1169
+ r"""
1170
+ Sends a request with the given URL
1171
+
1172
+ # Examples
1173
+
1174
+ ```python
1175
+ import rnet
1176
+ import asyncio
1177
+ from rnet import Method
1178
+
1179
+ async def main():
1180
+ client = rnet.Client()
1181
+ response = await client.options("https://httpbin.org/anything")
1182
+ print(await response.text())
1183
+
1184
+ asyncio.run(main())
1185
+ ```
1186
+ """
1187
+
1188
+ async def patch(
1189
+ self,
1190
+ url: str,
1191
+ **kwargs: Unpack[Request],
1192
+ ) -> Response:
1193
+ r"""
1194
+ Sends a request with the given URL
1195
+
1196
+ # Examples
1197
+
1198
+ ```python
1199
+ import rnet
1200
+ import asyncio
1201
+ from rnet import Method
1202
+
1203
+ async def main():
1204
+ client = rnet.Client()
1205
+ response = await client.patch("https://httpbin.org/anything", json={"key": "value"})
1206
+ print(await response.text())
1207
+
1208
+ asyncio.run(main())
1209
+ ```
1210
+ """
1211
+
1212
+ async def delete(
1213
+ self,
1214
+ url: str,
1215
+ **kwargs: Unpack[Request],
1216
+ ) -> Response:
1217
+ r"""
1218
+ Sends a request with the given URL
1219
+
1220
+ # Examples
1221
+
1222
+ ```python
1223
+ import rnet
1224
+ import asyncio
1225
+ from rnet import Method
1226
+
1227
+ async def main():
1228
+ client = rnet.Client()
1229
+ response = await client.delete("https://httpbin.org/anything")
1230
+ print(await response.text())
1231
+
1232
+ asyncio.run(main())
1233
+ ```
1234
+ """
1235
+
1236
+ async def put(
1237
+ self,
1238
+ url: str,
1239
+ **kwargs: Unpack[Request],
1240
+ ) -> Response:
1241
+ r"""
1242
+ Sends a request with the given URL
1243
+
1244
+ # Examples
1245
+
1246
+ ```python
1247
+ import rnet
1248
+ import asyncio
1249
+ from rnet import Method
1250
+
1251
+ async def main():
1252
+ client = rnet.Client()
1253
+ response = await client.put("https://httpbin.org/anything", json={"key": "value"})
1254
+ print(await response.text())
1255
+
1256
+ asyncio.run(main())
1257
+ ```
1258
+ """
1259
+
1260
+ async def post(
1261
+ self,
1262
+ url: str,
1263
+ **kwargs: Unpack[Request],
1264
+ ) -> Response:
1265
+ r"""
1266
+ Sends a request with the given URL
1267
+
1268
+ # Examples
1269
+
1270
+ ```python
1271
+ import rnet
1272
+ import asyncio
1273
+ from rnet import Method
1274
+
1275
+ async def main():
1276
+ client = rnet.Client()
1277
+ response = await client.post("https://httpbin.org/anything", json={"key": "value"})
1278
+ print(await response.text())
1279
+
1280
+ asyncio.run(main())
1281
+ ```
1282
+ """
1283
+
1284
+ async def head(
1285
+ self,
1286
+ url: str,
1287
+ **kwargs: Unpack[Request],
1288
+ ) -> Response:
1289
+ r"""
1290
+ Sends a request with the given URL
1291
+
1292
+ # Examples
1293
+
1294
+ ```python
1295
+ import rnet
1296
+ import asyncio
1297
+ from rnet import Method
1298
+
1299
+ async def main():
1300
+ client = rnet.Client()
1301
+ response = await client.head("https://httpbin.org/anything")
1302
+ print(response.status)
1303
+
1304
+ asyncio.run(main())
1305
+ ```
1306
+ """
1307
+
1308
+ async def get(
1309
+ self,
1310
+ url: str,
1311
+ **kwargs: Unpack[Request],
1312
+ ) -> Response:
1313
+ r"""
1314
+ Sends a request with the given URL
1315
+
1316
+ # Examples
1317
+
1318
+ ```python
1319
+ import rnet
1320
+ import asyncio
1321
+ from rnet import Method
1322
+
1323
+ async def main():
1324
+ client = rnet.Client()
1325
+ response = await client.get("https://httpbin.org/anything")
1326
+ print(await response.text())
1327
+
1328
+ asyncio.run(main())
1329
+ ```
1330
+ """
1331
+
1332
+ async def delete(
1333
+ url: str,
1334
+ **kwargs: Unpack[Request],
1335
+ ) -> Response:
1336
+ r"""
1337
+ Shortcut method to quickly make a request.
1338
+
1339
+ # Examples
1340
+
1341
+ ```python
1342
+ import rnet
1343
+ import asyncio
1344
+
1345
+ async def run():
1346
+ response = await rnet.delete("https://httpbin.org/anything")
1347
+ body = await response.text()
1348
+ print(body)
1349
+
1350
+ asyncio.run(run())
1351
+ ```
1352
+ """
1353
+
1354
+ async def get(
1355
+ url: str,
1356
+ **kwargs: Unpack[Request],
1357
+ ) -> Response:
1358
+ r"""
1359
+ Shortcut method to quickly make a request.
1360
+
1361
+ # Examples
1362
+
1363
+ ```python
1364
+ import rnet
1365
+ import asyncio
1366
+
1367
+ async def run():
1368
+ response = await rnet.get("https://httpbin.org/anything")
1369
+ body = await response.text()
1370
+ print(body)
1371
+
1372
+ asyncio.run(run())
1373
+ ```
1374
+ """
1375
+
1376
+ async def head(
1377
+ url: str,
1378
+ **kwargs: Unpack[Request],
1379
+ ) -> Response:
1380
+ r"""
1381
+ Shortcut method to quickly make a request.
1382
+
1383
+ # Examples
1384
+
1385
+ ```python
1386
+ import rnet
1387
+ import asyncio
1388
+
1389
+ async def run():
1390
+ response = await rnet.head("https://httpbin.org/anything")
1391
+ print(response.status)
1392
+
1393
+ asyncio.run(run())
1394
+ ```
1395
+ """
1396
+
1397
+ async def options(
1398
+ url: str,
1399
+ **kwargs: Unpack[Request],
1400
+ ) -> Response:
1401
+ r"""
1402
+ Shortcut method to quickly make a request.
1403
+
1404
+ # Examples
1405
+
1406
+ ```python
1407
+ import rnet
1408
+ import asyncio
1409
+
1410
+ async def run():
1411
+ response = await rnet.options("https://httpbin.org/anything")
1412
+ print(response.status)
1413
+
1414
+ asyncio.run(run())
1415
+ ```
1416
+ """
1417
+
1418
+ async def patch(
1419
+ url: str,
1420
+ **kwargs: Unpack[Request],
1421
+ ) -> Response:
1422
+ r"""
1423
+ Shortcut method to quickly make a request.
1424
+
1425
+ # Examples
1426
+
1427
+ ```python
1428
+ import rnet
1429
+ import asyncio
1430
+
1431
+ async def run():
1432
+ response = await rnet.patch("https://httpbin.org/anything")
1433
+ body = await response.text()
1434
+ print(body)
1435
+
1436
+ asyncio.run(run())
1437
+ ```
1438
+ """
1439
+
1440
+ async def post(
1441
+ url: str,
1442
+ **kwargs: Unpack[Request],
1443
+ ) -> Response:
1444
+ r"""
1445
+ Shortcut method to quickly make a request.
1446
+
1447
+ # Examples
1448
+
1449
+ ```python
1450
+ import rnet
1451
+ import asyncio
1452
+
1453
+ async def run():
1454
+ response = await rnet.post("https://httpbin.org/anything")
1455
+ body = await response.text()
1456
+ print(body)
1457
+
1458
+ asyncio.run(run())
1459
+ ```
1460
+ """
1461
+
1462
+ async def put(
1463
+ url: str,
1464
+ **kwargs: Unpack[Request],
1465
+ ) -> Response:
1466
+ r"""
1467
+ Shortcut method to quickly make a request.
1468
+
1469
+ # Examples
1470
+
1471
+ ```python
1472
+ import rnet
1473
+ import asyncio
1474
+
1475
+ async def run():
1476
+ response = await rnet.put("https://httpbin.org/anything")
1477
+ body = await response.text()
1478
+ print(body)
1479
+
1480
+ asyncio.run(run())
1481
+ ```
1482
+ """
1483
+
1484
+ async def request(
1485
+ method: Method,
1486
+ url: str,
1487
+ **kwargs: Unpack[Request],
1488
+ ) -> Response:
1489
+ r"""
1490
+ Make a request with the given parameters.
1491
+
1492
+ # Arguments
1493
+
1494
+ * `method` - The method to use for the request.
1495
+ * `url` - The URL to send the request to.
1496
+ * `**kwargs` - Additional request parameters.
1497
+
1498
+ # Examples
1499
+
1500
+ ```python
1501
+ import rnet
1502
+ import asyncio
1503
+ from rnet import Method
1504
+
1505
+ async def run():
1506
+ response = await rnet.request(Method.GET, "https://www.rust-lang.org")
1507
+ body = await response.text()
1508
+ print(body)
1509
+
1510
+ asyncio.run(run())
1511
+ ```
1512
+ """
1513
+
1514
+ async def trace(
1515
+ url: str,
1516
+ **kwargs: Unpack[Request],
1517
+ ) -> Response:
1518
+ r"""
1519
+ Shortcut method to quickly make a request.
1520
+
1521
+ # Examples
1522
+
1523
+ ```python
1524
+ import rnet
1525
+ import asyncio
1526
+
1527
+ async def run():
1528
+ response = await rnet.trace("https://httpbin.org/anything")
1529
+ print(response.status)
1530
+
1531
+ asyncio.run(run())
1532
+ ```
1533
+ """
1534
+
1535
+ async def websocket(
1536
+ url: str,
1537
+ **kwargs: Unpack[WebSocketRequest],
1538
+ ) -> WebSocket:
1539
+ r"""
1540
+ Make a WebSocket connection with the given parameters.
1541
+
1542
+ # Examples
1543
+
1544
+ ```python
1545
+ import rnet
1546
+ import asyncio
1547
+ from rnet import Message
1548
+
1549
+ async def run():
1550
+ ws = await rnet.websocket("wss://echo.websocket.org")
1551
+ await ws.send(Message.from_text("Hello, World!"))
1552
+ message = await ws.recv()
1553
+ print("Received:", message.data)
1554
+ await ws.close()
1555
+
1556
+ asyncio.run(run())
1557
+ ```
1558
+ """