Skip to content

Simple notifications service by web sockets

Notifications You must be signed in to change notification settings

fandsdev/websockets-notifications-py

Repository files navigation

websockets-notifications Demo

A notification service via WebSockets. Allows clients to connect, authenticate through a JWT token, and subscribe to events. Events are captured by a consumer and all subscribers are notified.

Documentation schemas

This project requires Python 3.12+. Dependencies are managed by uv and should be installed. The list of requirements is stored in pyproject.toml.

Some Facts About Environment Variables:

  1. When running in a container, do not forget to set WEBSOCKETS_HOST in the environment variables. In most cases, it should be 0.0.0.0.
  2. The app requires a JWT public key for authentication. It can be set using one of two options (if both are set, the app will not start):
    1. Environment variable JWT_PUBLIC_KEY. Ensure it has no newlines. Check env.example for the correct format.
    2. A file named jwt_public_key.pem inside the src directory.

Develop on a Local Machine

Install and activate a virtual environment:

uv venv
source venv/bin/activate

Set environment variables

cp env.example ./src/.env  # default environment variables

Install requirements:

make  # compile and install deps

Run message broker:

docker compose up -d

Run server:

cd python src/entrypoint.py

Connect to the server in cli:

python -m websockets ws://localhost:{% port %}/{% websockets_path % }

Format code with ruff

make fmt

Run linters

make lint

Run tests

make test

Build docker image

If you need to set python version manually

docker build --build-arg "PYTHON_VERSION=3.11.6" --tag websocket-notifications .

Preferred way is to use .python-version file

docker build --build-arg "PYTHON_VERSION=$(cat .python-version)" --tag websocket-notifications .

About

Simple notifications service by web sockets

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages