Subscribe to Web Push notifications and receive them in FastAPI.
Project description
🫸💬📲⚡ FastAPI Web Push Endpoint
Subscribe to Web Push notifications and receive them in FastAPI.
Supports Python >= 3.11
Installation 🛠️
pip install fastapi_webpush_endpoint
To run examples, install with dependencies:
pip install fastapi_webpush_endpoint[development]
Intro to Web Push
Web Push allows an end user to give permission to a website, allowing it to send push notifications to the end user's device mediated by a Web Push Endpoint.
The flow is illustrated below. Javascript code triggers an "Allow notifications" dialogue which the user accepts. As a result, a Web Push Endpoint operated by the end user's web browser vendor is provided. Javascsript code can share the endpoint with the website backend. The website backend can then publish notifications to the endpoint and these will be delivered to the end user's device.
sequenceDiagram
participant Backend
participant Frontend Javascript
participant User/Device
participant Web Push Endpoint
Frontend Javascript->>User/Device: Permission to send Web Push notifications?
User/Device->>Frontend Javascript: Permission granted
Web Push Endpoint-->>Frontend Javascript: Subscription endpoint URL, secret and public key
Frontend Javascript-->>Backend: Subscription endpoint URL, secret and public key
Backend-->>Web Push Endpoint: Publish notification
Web Push Endpoint->>User/Device: Show notification
Backend-->>Web Push Endpoint: Publish notification
Web Push Endpoint->>User/Device: Show notification
What fastapi_webpush_endpoint does
fastapi_webpush_endpoint implements a Web Push Endpoint that backends can send notifications to. The flow is illustrated below. A WebPushSubscription object created by fastapi_webpush_endpoint is sent to the backend via HTTP request (typically POST method). The backend publishes notifications to the endpoint just as it would if it were a "real" service passing messages on to an end user device.
sequenceDiagram
participant Backend
participant fastapi_webpush_endpoint
fastapi_webpush_endpoint-->>Backend: Subscription endpoint URL, secret and public key
Backend-->>fastapi_webpush_endpoint: Publish notification
Backend-->>fastapi_webpush_endpoint: Publish notification
Examples
See examples/ directory for an example using either the pywebpush or the webpush library. There's also endpoint_example.py that only showcases the endpoint.
What can I do with this?
- Integration tests of Web Push backends
- Use Web Push notifications as a regular webhook in downstream web services
Foundations
Project details
Release history Release notifications | RSS feed
Download files
Download the file for your platform. If you're not sure which to choose, learn more about installing packages.
Source Distribution
File details
Details for the file fastapi_webpush_endpoint-0.0.1.tar.gz.
File metadata
- Download URL: fastapi_webpush_endpoint-0.0.1.tar.gz
- Upload date:
- Size: 10.9 kB
- Tags: Source
- Uploaded using Trusted Publishing? Yes
- Uploaded via: twine/6.1.0 CPython/3.12.9
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8011694e0e7eda1eecf7542103c75c5fb810877ba5e4969f6ba10829b1e96135
|
|
| MD5 |
7a13f106891adab5e2a2715929555e6e
|
|
| BLAKE2b-256 |
7399f2a2004be24e90380c1de535c3040abae8a12a46b5f896d9276c95c4c127
|
Provenance
The following attestation bundles were made for fastapi_webpush_endpoint-0.0.1.tar.gz:
Publisher:
cicd.yml on eskildsf/fastapi_webpush_endpoint
-
Statement:
-
Statement type:
https://in-toto.io/Statement/v1 -
Predicate type:
https://docs.pypi.org/attestations/publish/v1 -
Subject name:
fastapi_webpush_endpoint-0.0.1.tar.gz -
Subject digest:
8011694e0e7eda1eecf7542103c75c5fb810877ba5e4969f6ba10829b1e96135 - Sigstore transparency entry: 233501050
- Sigstore integration time:
-
Permalink:
eskildsf/fastapi_webpush_endpoint@72a67d2940509130ac3214dcb7b93bb3d3039b9e -
Branch / Tag:
refs/heads/main - Owner: https://github.com/eskildsf
-
Access:
public
-
Token Issuer:
https://token.actions.githubusercontent.com -
Runner Environment:
github-hosted -
Publication workflow:
cicd.yml@72a67d2940509130ac3214dcb7b93bb3d3039b9e -
Trigger Event:
push
-
Statement type: