Skip to content

Commit b5b3e40

Browse files
authored
Make broadcaster dependencies optional (#89)
* Make broadcaster dependencies optional An option is available for each backend as well as an "all" option which gets you everything. * . * .. * Fix supply of additional headers to comply with websockets API * Bump minimum required version of websockets
1 parent 9d0afae commit b5b3e40

File tree

6 files changed

+22
-6
lines changed

6 files changed

+22
-6
lines changed

README.md

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,8 @@ FastAPI + WebSockets + PubSub == ⚡💪 ❤️
7171
async def websocket_rpc_endpoint(websocket: WebSocket):
7272
await endpoint.main_loop(websocket)
7373
```
74-
see [examples/pubsub_broadcaster_server_example.py](examples/pubsub_broadcaster_server_example.py) for full usage example
74+
see [examples/pubsub_broadcaster_server_example.py](examples/pubsub_broadcaster_server_example.py) for full usage example
75+
Note: Requires install with dependencies e.g. `pip install fastapi_websocket_pubsub[redis]`, `pip install fastapi_websocket_pubsub[postgres]`, `pip install fastapi_websocket_pubsub[kafka]` or `pip install fastapi_websocket_pubsub[all]` to get support for all three backends
7576

7677

7778

requirements-dev.txt

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,4 +5,5 @@ twine
55
wheel
66
loguru
77
uvicorn
8-
pytest-timeout
8+
pytest-timeout
9+
permit-broadcaster[redis,postgres,kafka]>=0.2.5,<3

requirements.txt

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
fastapi-websocket-rpc>=0.1.25,<1
22
packaging>=20.4
3-
permit-broadcaster[redis,postgres,kafka]>=0.2.5,<3
43
pydantic>=1.9.1
5-
websockets>=10.3
4+
websockets>=14.0
5+
permit-broadcaster>=0.2.5,<3

setup.py

Lines changed: 6 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,4 +30,10 @@ def get_requirements(env=""):
3030
],
3131
python_requires=">=3.9",
3232
install_requires=get_requirements(),
33+
extras_require = {
34+
"redis": ["permit-broadcaster[redis]>=0.2.5,<3"],
35+
"postgres": ["permit-broadcaster[postgres]>=0.2.5,<3"],
36+
"kafka": ["permit-broadcaster[kafka]>=0.2.5,<3"],
37+
"all": ["permit-broadcaster[redis,postgres,kafka]>=0.2.5,<3"],
38+
}
3339
)

tests/broadcaster_test.py

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,12 @@
2222
)
2323
from fastapi_websocket_pubsub import PubSubEndpoint, PubSubClient
2424

25+
# Check if postgres backend is available
26+
asyncpg_backend_available = True
27+
try:
28+
import asyncpg
29+
except ModuleNotFoundError:
30+
asyncpg_backend_available = False
2531

2632
logger = get_logger("Test")
2733
logger.remove()
@@ -129,6 +135,7 @@ def server(postgres):
129135

130136

131137
@pytest.mark.asyncio
138+
@pytest.mark.skipif(not asyncpg_backend_available, reason="asyncpg dependency is not installed.")
132139
async def test_all_clients_get_a_topic_via_broadcast(server, repeats=1, interval=0):
133140
"""
134141
if:
@@ -179,6 +186,7 @@ async def wait_for_sem():
179186

180187
@pytest.mark.postgres_idle_timeout(3000)
181188
@pytest.mark.asyncio
189+
@pytest.mark.skipif(not asyncpg_backend_available, reason="asyncpg dependency is not installed.")
182190
async def test_idle_pg_broadcaster_disconnect(server):
183191
"""
184192
if:

tests/server_notifier_callback_test.py

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -80,7 +80,7 @@ async def server_subscribe_to_topic(server, is_topic_permitted):
8080

8181
# Create a client and subscribe to topics
8282
async with PubSubClient(
83-
extra_headers={"headers": {"claims": {"permitted_topics": permitted_topics}}}
83+
additional_headers={"headers": {"claims": {"permitted_topics": permitted_topics}}}
8484
) as client:
8585

8686
async def on_event(data, topic):
@@ -116,7 +116,7 @@ async def test_server_subscribe_to_permitted_topic(server):
116116
async def server_publish_to_topic(server, is_topic_permitted):
117117
# Create a client and subscribe to topics
118118
async with PubSubClient(
119-
extra_headers={"headers": {"claims": {"permitted_topics": ["t1", "t2"]}}}
119+
additional_headers={"headers": {"claims": {"permitted_topics": ["t1", "t2"]}}}
120120
) as client:
121121
# start listentining
122122
client.start_client(uri)

0 commit comments

Comments
 (0)