Skip to content

Commit bbb3e00

Browse files
committed
improving naming semantics "urlProvider"->"url_provider"
1 parent 15f6107 commit bbb3e00

File tree

7 files changed

+35
-18
lines changed

7 files changed

+35
-18
lines changed

README.md

Lines changed: 27 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -1,13 +1,20 @@
11
# Realtime Pub/Sub Client for Python
22

3-
The `realtime-pubsub-client-python` is a Python client library for interacting with [Realtime Pub/Sub](https://realtime.21no.de) applications. It enables developers to manage real-time WebSocket connections, handle subscriptions, and process messages efficiently. The library provides a simple and flexible API to interact with realtime applications, supporting features like publishing/sending messages, subscribing to topics, handling acknowledgements, and waiting for replies with timeout support.
3+
The `realtime-pubsub-client-python` is a Python client library for interacting
4+
with [Realtime Pub/Sub](https://realtime.21no.de) applications. It enables developers to manage real-time WebSocket
5+
connections, handle subscriptions, and process messages efficiently. The library provides a simple and flexible API to
6+
interact with realtime applications, supporting features like publishing/sending messages, subscribing to topics,
7+
handling acknowledgements, and waiting for replies with timeout support.
48

59
## Features
610

7-
- **WebSocket Connection Management**: Seamlessly connect and disconnect from the Realtime Pub/Sub service with automatic reconnection support.
11+
- **WebSocket Connection Management**: Seamlessly connect and disconnect from the Realtime Pub/Sub service with
12+
automatic reconnection support.
813
- **Topic Subscription**: Subscribe and unsubscribe to topics for receiving messages.
9-
- **Topic Publishing**: [Publish](https://realtime.21no.de/documentation/#publishers) messages to specific topics with optional message types and compression.
10-
- **Message Sending**: [Send](https://realtime.21no.de/documentation/#websocket-inbound-messaging) messages to backend applications with optional message types and compression.
14+
- **Topic Publishing**: [Publish](https://realtime.21no.de/documentation/#publishers) messages to specific topics with
15+
optional message types and compression.
16+
- **Message Sending**: [Send](https://realtime.21no.de/documentation/#websocket-inbound-messaging) messages to backend
17+
applications with optional message types and compression.
1118
- **Event Handling**: Handle incoming messages with custom event listeners.
1219
- **Acknowledgements and Replies**: Wait for gateway acknowledgements or replies to messages with timeout support.
1320
- **Error Handling**: Robust error handling and logging capabilities.
@@ -37,6 +44,7 @@ from realtime_pubsub_client import RealtimeClient
3744

3845
APP_ID = 'your-app-id'
3946

47+
4048
async def main():
4149
async def get_url():
4250
# replace with your access token retrieval strategy
@@ -49,7 +57,7 @@ async def main():
4957
client_options = {
5058
'logger': logging.getLogger('RealtimeClient'),
5159
'websocket_options': {
52-
'urlProvider': get_url,
60+
'url_provider': get_url,
5361
},
5462
}
5563
client = RealtimeClient(client_options)
@@ -65,6 +73,7 @@ async def main():
6573
await client.connect()
6674
await client.wait_for('session.started')
6775

76+
6877
asyncio.run(main())
6978
```
7079

@@ -79,6 +88,7 @@ def handle_message(message, reply_fn):
7988
# Message handling logic here
8089
print('Received message:', message['data']['payload'])
8190

91+
8292
client.on('topic1.action1', handle_message)
8393
```
8494

@@ -110,6 +120,7 @@ async def handle_message(message, reply_fn):
110120
# Sending a reply
111121
await reply_fn('Message received!', 'ok')
112122

123+
113124
client.on('topic1.text-message', handle_message)
114125
```
115126

@@ -157,9 +168,11 @@ Handle errors and disconnections:
157168
def on_error(error):
158169
print('WebSocket error:', error)
159170

171+
160172
def on_close(event):
161173
print('WebSocket closed:', event)
162174

175+
163176
client.on('error', on_error)
164177
client.on('close', on_close)
165178
```
@@ -192,13 +205,15 @@ Creates a new `RealtimeClient` instance.
192205
await client.disconnect()
193206
```
194207

195-
- **`subscribe_remote_topic(topic)`**: [Subscribes](https://realtime.21no.de/documentation/#subscribers) the connection to a remote topic.
208+
- **`subscribe_remote_topic(topic)`**: [Subscribes](https://realtime.21no.de/documentation/#subscribers) the connection
209+
to a remote topic.
196210

197211
```python
198212
await client.subscribe_remote_topic(topic)
199213
```
200214

201-
- **`unsubscribe_remote_topic(topic)`**: [Unsubscribes](https://realtime.21no.de/documentation/#subscribers) the connection from a remote topic.
215+
- **`unsubscribe_remote_topic(topic)`**: [Unsubscribes](https://realtime.21no.de/documentation/#subscribers) the
216+
connection from a remote topic.
202217

203218
```python
204219
await client.unsubscribe_remote_topic(topic)
@@ -260,17 +275,19 @@ This library is licensed under the MIT License.
260275

261276
---
262277

263-
For more detailed examples and advanced configurations, please refer to the [documentation](https://realtime.21no.de/docs).
278+
For more detailed examples and advanced configurations, please refer to
279+
the [documentation](https://realtime.21no.de/docs).
264280

265281
## Notes
266282

267283
- Ensure that you have an account and an app set up with [Realtime Pub/Sub](https://realtime.21no.de).
268-
- Customize the `urlProvider` or URL to retrieve the access token for connecting to your realtime application.
284+
- Customize the `url_provider` or URL to retrieve the access token for connecting to your realtime application.
269285
- Implement the `get_auth_token` function according to your authentication mechanism.
270286
- Optionally use the `logger` option to integrate with your application's logging system.
271287
- Handle errors and disconnections gracefully to improve the robustness of your application.
272288
- Make sure to handle timeouts when waiting for replies to avoid hanging operations.
273289

274290
---
275291

276-
Feel free to contribute to this project by submitting issues or pull requests on [GitHub](https://github.com/BackendStack21/realtime-pubsub-client-python).
292+
Feel free to contribute to this project by submitting issues or pull requests
293+
on [GitHub](https://github.com/BackendStack21/realtime-pubsub-client-python).

demos/publish_and_reply.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ async def get_url():
2121
config = {
2222
'logger': logging.getLogger('RealtimeClient'),
2323
'websocket_options': {
24-
'urlProvider': get_url,
24+
'url_provider': get_url,
2525
}
2626
}
2727
client = RealtimeClient(config)

demos/rpc/client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ async def get_url():
2323
config = {
2424
'logger': logging.getLogger('RealtimeClient'),
2525
'websocket_options': {
26-
'urlProvider': get_url,
26+
'url_provider': get_url,
2727
}
2828
}
2929
client = RealtimeClient(config)

demos/rpc/server.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,7 @@ async def get_url():
2323
config = {
2424
'logger': logging.getLogger('RealtimeClient'),
2525
'websocket_options': {
26-
'urlProvider': get_url,
26+
'url_provider': get_url,
2727
}
2828
}
2929
client = RealtimeClient(config)

src/client.py

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -340,7 +340,7 @@ async def connect(self):
340340
"""
341341
Establish a connection to the WebSocket server.
342342
343-
Initiates the WebSocket connection using the provided URL from the `urlProvider` function.
343+
Initiates the WebSocket connection using the provided URL from the `url_provider` function.
344344
Sets up event handlers for incoming messages, errors, and closure events.
345345
346346
Raises:
@@ -354,7 +354,7 @@ async def connect(self):
354354
max_backoff = 60
355355

356356
while True:
357-
url_provider = self.websocket_options.get('urlProvider')
357+
url_provider = self.websocket_options.get('url_provider')
358358
if callable(url_provider):
359359
if asyncio.iscoroutinefunction(url_provider):
360360
ws_url = await url_provider()
@@ -368,7 +368,7 @@ async def connect(self):
368368

369369
try:
370370
max_float = float('inf')
371-
self.ws = await connect(ws_url, max_size=2 ** 20, ping_interval=None, ping_timeout=None)
371+
self.ws = await connect(ws_url, max_size=None, ping_interval=None, ping_timeout=None)
372372
self.logger.info(f'Connected to WebSocket URL: {ws_url[:80]}...') # Masking the URL for security
373373
asyncio.ensure_future(self._receive_messages())
374374

tests/test_websocket_client.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -42,7 +42,7 @@ def setUp(self):
4242
self.client = RealtimeClient({
4343
'logger': logging.getLogger('TestRealtimeClient'),
4444
'websocket_options': {
45-
'urlProvider': url
45+
'url_provider': url
4646
}
4747
})
4848

tests/test_websocket_client_remote.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -28,7 +28,7 @@ def setUp(self):
2828
config = {
2929
'logger': logging.getLogger('RealtimeClient'),
3030
'websocket_options': {
31-
'urlProvider': f"wss://genesis.r7.21no.de/apps/{app_id}?access_token={access_token}",
31+
'url_provider': f"wss://genesis.r7.21no.de/apps/{app_id}?access_token={access_token}",
3232
}
3333
}
3434

0 commit comments

Comments
 (0)