Flask-pyWebPush
A clean interface to pywebpush from Flask. Basically, a very thin wrapper.
Installation
The package is available at the PyPI:
$ pip install flask-pywebpush
Quickstart
Instantiation
Instantiate this extension like any other Flask extension:
from flask_pywebpush import WebPush
app = Flask()
push = WebPush(app)
Or you may initialize the extension with the Flask instance later:
from flask_pywebpush import WebPush
app = Flask()
push = WebPush()
push.init_app(app)
VAPID keys and sender info
WebPush sender requires a private key and an identification URL to operate. For more information on those values, see this article on Google Developers.
You may specify these values to the extension by setting the following configuration variables of the Flask instance:
WEBPUSH_VAPID_PRIVATE_KEYThe application server private key. As withpywebpush, it may either be the literal key value (DER representation) or a path to a VAPID EC2 private key PEM file;WEBPUSH_SENDER_INFO: a URL containing information to contact the notification sender. Commonly a mailto: URL.
Alternatively, you can pass these values on creation of the WebPush extension instance or to the init_app method later on:
from flask_pywebpush import WebPush
push = WebPush(private_key='some_value',
sender_info='mailto:admin@server.com')
Notification sending
Assuming you've got the subscription storage done, you may send a notification to a given subscription object like so:
from flask_pywebpush import WebPushException
subscription = {
'endpoint': '---some-value---',
'keys': { ... }
}
notification = {
'title': 'Test',
'body': 'notification body',
}
try:
push.send(subscription, notification)
except WebPushException as exc:
print(exc)
You can also pass keyword arguments like verbose=True to .send(), which will be directly passed to pywebpush.webpush()
Extended Usage
Since this is a wrapper over pywebpush, it exposes the main objects of the underlying library, namely, webpush, WebPushException, WebPusher.
All of them may be directly imported from flask_pywebpush.
The WebPush extension instance also has a get_webpusher(subscription) method, allowing you to get a pywebpush.WebPusher instance for a given subscription.
If your usage requires more VAPID claims than simply {"sub": "sender_info"}, then you may override the passed claims using the set_claims method:
from flask_pywebpush import WebPush
push = WebPush()
push.set_claims({}) # whatever VAPID claims you might need
License
Metadata
Release files for Flask-pyWebPush 1.1
For a detailed explanation of source distributions (sdists) and built distributions (wheels), please see the package formats documentation.
Source distribution (sdist)
| File | Size | Uploaded | Provenance | Actions |
|---|---|---|---|---|
| Flask-pyWebPush-1.1.tar.gz | 3.5 kB | Without provenance | Details for Flask-pyWebPush-1.1.tar.gz |
Built distribution (wheel)
| File | Interpreter | ABI | Platform | Actions Reset |
|---|---|---|---|---|
| Flask_pyWebPush-1.1-py3-none-any.whl | Python 3 | none | any | Details for Flask_pyWebPush-1.1-py3-none-any.whl |
Total release size: 7.8 kB
Release files / Flask-pyWebPush-1.1.tar.gz
| Download URL | Flask-pyWebPush-1.1.tar.gz |
|---|---|
| Size | 3.5 kB |
| Tags | Source |
|
SHA-256 checksum How to use checksums |
aa6b6391f35b77727948fd416a5bb4051fac916d53c5dccb8af35ff768741a96
|
|
BLAKE2b-256 checksum How to use checksums |
3bb365eefcdfbb2381cb1d58a9973bfdfb113178c6a9633eb384e0d0a39cd36b
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2
|
Release files / Flask_pyWebPush-1.1-py3-none-any.whl
| Download URL | Flask_pyWebPush-1.1-py3-none-any.whl |
|---|---|
| Size | 4.3 kB |
| Tags | Python 3 |
|
SHA-256 checksum How to use checksums |
018187d9deac755ebae9fd774801704b08540c50dd0856a1e8599fcbc9e57239
|
|
BLAKE2b-256 checksum How to use checksums |
7bdf74ca48a77785d5c5d02eb80202d59ac66ef25c880f585559968f71227df8
|
| Upload date | |
|
Uploaded using Trusted Publishing? What is trusted publishing? |
No |
| Uploaded via |
twine/2.0.0 pkginfo/1.5.0.1 requests/2.23.0 setuptools/46.1.3 requests-toolbelt/0.9.1 tqdm/4.43.0 CPython/3.8.2
|
Security for Flask-pyWebPush 1.1
Provenance
Provenance describes where a file came from. On PyPI, provenance is shared via attestations, which provide a verifiable record of the build or publishing details. View details, limitations and caveats.
No provenance found
None of the files in this release were uploaded with provenance metadata.
A note on package security
PyPI is a repository for distributing packages, not a service for auditing them. While third-party security researchers and our staff do their best to detect and remove malicious packages, PyPI cannot guarantee the quality, security or suitability of any given package.
To learn more about protecting yourself from malicious actors, visit our package security documentation.