11from collections .abc import Awaitable , Callable
22from datetime import timedelta
3- from typing import Any , overload
3+ from typing import Any , final , overload
44
5- from natsrpy ._natsrpy_rs .js import JetStream
6- from natsrpy ._natsrpy_rs .message import Message
5+ from typing_extensions import Self
76
7+ from . import js
8+
9+ @final
10+ class Message :
11+ """
12+ Simple NATS message.
13+
14+ Attributes:
15+ subject: subject where message was published
16+ reply: subject where reply should be sent, if any
17+ payload: message payload
18+ headers: dictionary of message headers,
19+ every value can be a simple value or a list.
20+ status: status is used for reply messages to indicate the status of the reply.
21+ It is None for regular messages.
22+ description: message description is used for reply messages to
23+ provide additional information about the status.
24+ length: a length of the message payload in bytes.
25+ """
26+
27+ subject : str
28+ reply : str | None
29+ payload : bytes
30+ headers : dict [str , Any ]
31+ status : int | None
32+ description : str | None
33+ length : int
34+
35+ @final
836class IteratorSubscription :
937 def __aiter__ (self ) -> IteratorSubscription : ...
1038 async def __anext__ (self ) -> Message : ...
39+ async def next (self , timeout : float | timedelta | None = None ) -> Message : ...
1140 async def unsubscribe (self , limit : int | None = None ) -> None : ...
1241 async def drain (self ) -> None : ...
1342
43+ @final
1444class CallbackSubscription :
1545 async def unsubscribe (self , limit : int | None = None ) -> None : ...
1646 async def drain (self ) -> None : ...
1747
48+ @final
1849class Nats :
19- def __init__ (
20- self ,
50+ def __new__ (
51+ cls ,
2152 / ,
22- addrs : list [str ] = [ "nats://localhost:4222" ] ,
53+ addrs : list [str ] | None = None ,
2354 user_and_pass : tuple [str , str ] | None = None ,
2455 nkey : str | None = None ,
2556 token : str | None = None ,
2657 custom_inbox_prefix : str | None = None ,
27- read_buffer_capacity : int = 65535 ,
28- sender_capacity : int = 128 ,
58+ read_buffer_capacity : int = ..., # 65535 bytes
59+ sender_capacity : int = ..., # 128 bytes
2960 max_reconnects : int | None = None ,
30- connection_timeout : float | timedelta = ...,
31- request_timeout : float | timedelta = ...,
32- ) -> None : ...
61+ connection_timeout : float | timedelta = ..., # 5 sec
62+ request_timeout : float | timedelta = ..., # 10 sec
63+ ) -> Self : ...
3364 async def startup (self ) -> None : ...
3465 async def shutdown (self ) -> None : ...
3566 async def publish (
@@ -41,7 +72,15 @@ class Nats:
4172 reply : str | None = None ,
4273 err_on_disconnect : bool = False ,
4374 ) -> None : ...
44- async def request (self , subject : str , payload : bytes ) -> None : ...
75+ async def request (
76+ self ,
77+ subject : str ,
78+ payload : bytes | str | bytearray | memoryview ,
79+ * ,
80+ headers : dict [str , Any ] | None = None ,
81+ inbox : str | None = None ,
82+ timeout : float | timedelta | None = None ,
83+ ) -> None : ...
4584 async def drain (self ) -> None : ...
4685 async def flush (self ) -> None : ...
4786 @overload
@@ -56,6 +95,16 @@ class Nats:
5695 subject : str ,
5796 callback : None = None ,
5897 ) -> IteratorSubscription : ...
59- async def jetstream (self ) -> JetStream : ...
98+ async def jetstream (
99+ self ,
100+ * ,
101+ domain : str | None = None ,
102+ api_prefix : str | None = None ,
103+ timeout : timedelta | None = None ,
104+ ack_timeout : timedelta | None = None ,
105+ concurrency_limit : int | None = None ,
106+ max_ack_inflight : int | None = None ,
107+ backpressure_on_inflight : bool | None = None ,
108+ ) -> js .JetStream : ...
60109
61- __all__ = ["CallbackSubscription" , "IteratorSubscription" , "Message" , "Nats" ]
110+ __all__ = ["CallbackSubscription" , "IteratorSubscription" , "Message" , "Nats" , "js" ]
0 commit comments