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