Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension


Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion README.md
Original file line number Diff line number Diff line change
Expand Up @@ -71,7 +71,8 @@ FastAPI + WebSockets + PubSub == ⚡💪 ❤️
async def websocket_rpc_endpoint(websocket: WebSocket):
await endpoint.main_loop(websocket)
```
see [examples/pubsub_broadcaster_server_example.py](examples/pubsub_broadcaster_server_example.py) for full usage example
see [examples/pubsub_broadcaster_server_example.py](examples/pubsub_broadcaster_server_example.py) for full usage example
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



Expand Down
3 changes: 2 additions & 1 deletion requirements-dev.txt
Original file line number Diff line number Diff line change
Expand Up @@ -5,4 +5,5 @@ twine
wheel
loguru
uvicorn
pytest-timeout
pytest-timeout
permit-broadcaster[redis,postgres,kafka]>=0.2.5,<3
4 changes: 2 additions & 2 deletions requirements.txt
Original file line number Diff line number Diff line change
@@ -1,5 +1,5 @@
fastapi-websocket-rpc>=0.1.25,<1
packaging>=20.4
permit-broadcaster[redis,postgres,kafka]>=0.2.5,<3
pydantic>=1.9.1
websockets>=10.3
websockets>=14.0
permit-broadcaster>=0.2.5,<3
6 changes: 6 additions & 0 deletions setup.py
Original file line number Diff line number Diff line change
Expand Up @@ -30,4 +30,10 @@ def get_requirements(env=""):
],
python_requires=">=3.9",
install_requires=get_requirements(),
extras_require = {
"redis": ["permit-broadcaster[redis]>=0.2.5,<3"],
"postgres": ["permit-broadcaster[postgres]>=0.2.5,<3"],
"kafka": ["permit-broadcaster[kafka]>=0.2.5,<3"],
"all": ["permit-broadcaster[redis,postgres,kafka]>=0.2.5,<3"],
}
)
8 changes: 8 additions & 0 deletions tests/broadcaster_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -22,6 +22,12 @@
)
from fastapi_websocket_pubsub import PubSubEndpoint, PubSubClient

# Check if postgres backend is available
asyncpg_backend_available = True
try:
import asyncpg
except ModuleNotFoundError:
asyncpg_backend_available = False

logger = get_logger("Test")
logger.remove()
Expand Down Expand Up @@ -129,6 +135,7 @@ def server(postgres):


@pytest.mark.asyncio
@pytest.mark.skipif(not asyncpg_backend_available, reason="asyncpg dependency is not installed.")
async def test_all_clients_get_a_topic_via_broadcast(server, repeats=1, interval=0):
"""
if:
Expand Down Expand Up @@ -179,6 +186,7 @@ async def wait_for_sem():

@pytest.mark.postgres_idle_timeout(3000)
@pytest.mark.asyncio
@pytest.mark.skipif(not asyncpg_backend_available, reason="asyncpg dependency is not installed.")
async def test_idle_pg_broadcaster_disconnect(server):
"""
if:
Expand Down
4 changes: 2 additions & 2 deletions tests/server_notifier_callback_test.py
Original file line number Diff line number Diff line change
Expand Up @@ -80,7 +80,7 @@ async def server_subscribe_to_topic(server, is_topic_permitted):

# Create a client and subscribe to topics
async with PubSubClient(
extra_headers={"headers": {"claims": {"permitted_topics": permitted_topics}}}
additional_headers={"headers": {"claims": {"permitted_topics": permitted_topics}}}
) as client:

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