popsub 0.1.0__py3-none-any.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.
popsub/__init__.py ADDED
@@ -0,0 +1,118 @@
1
+ """Asyncio client for PopSub, a WebSocket publish/subscribe broker.
2
+
3
+ `Client` keeps a connection to a PopSub server and handles what every
4
+ application would otherwise have to: logging in and refreshing the token,
5
+ reconnecting with backoff (and knowing from the server's close code when not
6
+ to), resubscribing without gaps, resending confirmed publishes without
7
+ duplicating them, acknowledging QoS 1 messages, and making sure each
8
+ `(topic, seq)` reaches the application once.
9
+
10
+ A payload is a string. For a body that isn't text, `publish_bytes` and
11
+ `publish_bytes_confirmed` send bytes as base64, and `Message.data` gives a
12
+ received message's bytes whatever its `encoding`.
13
+
14
+ Example:
15
+ import asyncio
16
+ from popsub import Client, ClientConfig, PasswordCredentials, StartFrom
17
+
18
+ async def main() -> None:
19
+ config = ClientConfig("ws://127.0.0.1:8080", PasswordCredentials("alice", "secret"))
20
+ async with await Client.connect(config) as client:
21
+ orders = await client.subscribe("orders", StartFrom.new())
22
+ stored = await client.publish_confirmed("orders", "order 42 shipped")
23
+ print("stored as seq", stored.seq)
24
+ async for message in orders:
25
+ print(message.topic, message.seq, message.payload)
26
+
27
+ asyncio.run(main())
28
+
29
+ The protocol is described in the repository's `docs/DESIGN.md` section 4.
30
+ """
31
+
32
+ from popsub.admin import Admin
33
+ from popsub.client import Client
34
+ from popsub.config import (
35
+ AckMode,
36
+ ClientConfig,
37
+ Credentials,
38
+ PasswordCredentials,
39
+ ReconnectPolicy,
40
+ TokenCredentials,
41
+ )
42
+ from popsub.errors import (
43
+ ClosedError,
44
+ ConfigError,
45
+ ConnectError,
46
+ PopSubError,
47
+ ProtocolError,
48
+ RequestTimeoutError,
49
+ ServerError,
50
+ )
51
+ from popsub.message import (
52
+ AuthExpiring,
53
+ AuthRefreshed,
54
+ Connected,
55
+ Disconnected,
56
+ Event,
57
+ EventStream,
58
+ Message,
59
+ Published,
60
+ ServerErrorEvent,
61
+ Stalled,
62
+ Subscription,
63
+ Truncated,
64
+ Unsubscribed,
65
+ )
66
+ from popsub.protocol import (
67
+ PROTOCOL_VERSION,
68
+ Access,
69
+ CloseCode,
70
+ Encoding,
71
+ RoleKind,
72
+ RoleSpec,
73
+ StartFrom,
74
+ TopicGrant,
75
+ TopicInfo,
76
+ UserInfo,
77
+ )
78
+
79
+ __all__ = [
80
+ "PROTOCOL_VERSION",
81
+ "Access",
82
+ "AckMode",
83
+ "Admin",
84
+ "AuthExpiring",
85
+ "AuthRefreshed",
86
+ "Client",
87
+ "ClientConfig",
88
+ "CloseCode",
89
+ "ClosedError",
90
+ "ConfigError",
91
+ "ConnectError",
92
+ "Connected",
93
+ "Credentials",
94
+ "Disconnected",
95
+ "Encoding",
96
+ "Event",
97
+ "EventStream",
98
+ "Message",
99
+ "PasswordCredentials",
100
+ "PopSubError",
101
+ "ProtocolError",
102
+ "Published",
103
+ "ReconnectPolicy",
104
+ "RequestTimeoutError",
105
+ "RoleKind",
106
+ "RoleSpec",
107
+ "ServerError",
108
+ "ServerErrorEvent",
109
+ "Stalled",
110
+ "StartFrom",
111
+ "Subscription",
112
+ "TokenCredentials",
113
+ "TopicGrant",
114
+ "TopicInfo",
115
+ "Truncated",
116
+ "Unsubscribed",
117
+ "UserInfo",
118
+ ]