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.
This project requires Python 3.12+.
Dependencies are managed by uv and should be installed.
The list of requirements is stored in pyproject.toml
.
- When running in a container, do not forget to set
WEBSOCKETS_HOST
in the environment variables. In most cases, it should be0.0.0.0
. - 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):
- Environment variable
JWT_PUBLIC_KEY
. Ensure it has no newlines. Checkenv.example
for the correct format. - A file named
jwt_public_key.pem
inside thesrc
directory.
- Environment variable
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
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 .