Name | webpush JSON |
Version |
1.0.4
JSON |
| download |
home_page | None |
Summary | WebPush library for python |
upload_time | 2025-01-11 22:22:30 |
maintainer | None |
docs_url | None |
author | None |
requires_python | ~=3.10 |
license | None |
keywords |
pwa
pydantic
webpush
|
VCS |
|
bugtrack_url |
|
requirements |
No requirements were recorded.
|
Travis-CI |
No Travis.
|
coveralls test coverage |
No coveralls.
|
# WebPush-Py
Simple library for working with [WebPush](https://web.dev/articles/push-notifications-web-push-protocol) in python
## Usage
### Installation
```bash
pip install webpush
```
### Basic Usage
```python
import requests
from webpush import WebPush, WebPushSubscription
wp = WebPush(private_key="./private_key.pem", public_key="./public_key.pem")
# example subscription info
subscription = WebPushSubscription.model_validate({
"endpoint": "https://fcm.googleapis.com/fcm/send/...",
"keys": {
"auth": "...",
"p256dh": "..."
}
})
message = wp.get(message='Hello, world!', subscription=subscription)
requests.post(subscription.endpoint, data=message.encrypted, headers=message.headers)
```
Generate VAPID keys and get applicationServerKey:
```
vapid-gen
```
Private key saved in `public_key.pem` and public key saved in `public_key.pem`.
Application Server Key saved in `applicationServerKey`
### simple usage with fastapi
```python
import aiohttp
from fastapi import FastAPI
from fastapi.responses import JSONResponse
from webpush import WebPush, WebPushSubscription
app = FastAPI()
wp = WebPush(
public_key="./public_key.pem",
private_key="./private_key.pem",
subscriber="admin@mail.com",
)
@app.get("/notification/key")
async def get_public_key() -> JSONResponse:
application_server_key = "<generated from vapid-gen>"
return JSONResponse(content={"public_key": application_server_key})
@app.post("/notification/subscribe")
async def subscribe_user(subscription: WebPushSubscription) -> JSONResponse:
message = wp.get(message="Hello, world", subscription=subscription)
async with aiohttp.ClientSession() as session:
await session.post(
url=str(subscription.endpoint),
data=message.encrypted,
headers=message.headers,
)
return JSONResponse(content={"status": "ok"})
```
## FAQ
- Why do I need another library?
The current python libraries that work with Web Push have been written for a very long time, so they do not support typing, try to support outdated encryption algorithms and pull a lot of deprecated dependencies.
- Why is only `aes128gcm` supported?
According to the [RFC8192](https://datatracker.ietf.org/doc/html/rfc8291), this is the recommended format. At the moment, all modern systems support this encryption.
- Will there be support for other encryption modes?
New, yes, but there are no old ones, for example `aesgcm`
- Who is this library for?
You need type support, you're writing a modern backend, minimum number of dependencies.
And last one, if you have ideas for improvements, bug fixes, feel free to contribute.
## Change log
- 1.0.0 - initial release
## Credits
- [pywebpush](https://github.com/web-push-libs/pywebpush)
- [http-ece](https://github.com/web-push-libs/encrypted-content-encoding)
Raw data
{
"_id": null,
"home_page": null,
"name": "webpush",
"maintainer": null,
"docs_url": null,
"requires_python": "~=3.10",
"maintainer_email": null,
"keywords": "pwa, pydantic, webpush",
"author": null,
"author_email": "Alexey <delvinru@gmail.com>",
"download_url": "https://files.pythonhosted.org/packages/37/ed/90fb111ea4c86ab4d8f79469fb907775e94ccd31fb0efe731b191769de59/webpush-1.0.4.tar.gz",
"platform": null,
"description": "# WebPush-Py\n\nSimple library for working with [WebPush](https://web.dev/articles/push-notifications-web-push-protocol) in python\n\n## Usage\n\n### Installation\n\n```bash\npip install webpush\n```\n\n### Basic Usage\n\n```python\nimport requests\nfrom webpush import WebPush, WebPushSubscription\n\nwp = WebPush(private_key=\"./private_key.pem\", public_key=\"./public_key.pem\")\n\n# example subscription info\nsubscription = WebPushSubscription.model_validate({\n \"endpoint\": \"https://fcm.googleapis.com/fcm/send/...\",\n \"keys\": {\n \"auth\": \"...\",\n \"p256dh\": \"...\"\n }\n})\n\nmessage = wp.get(message='Hello, world!', subscription=subscription)\n\nrequests.post(subscription.endpoint, data=message.encrypted, headers=message.headers)\n```\n\nGenerate VAPID keys and get applicationServerKey:\n```\nvapid-gen\n```\n\nPrivate key saved in `public_key.pem` and public key saved in `public_key.pem`.\nApplication Server Key saved in `applicationServerKey`\n\n### simple usage with fastapi\n\n```python\nimport aiohttp\nfrom fastapi import FastAPI\nfrom fastapi.responses import JSONResponse\nfrom webpush import WebPush, WebPushSubscription\n\napp = FastAPI()\n\nwp = WebPush(\n public_key=\"./public_key.pem\",\n private_key=\"./private_key.pem\",\n subscriber=\"admin@mail.com\",\n)\n\n\n@app.get(\"/notification/key\")\nasync def get_public_key() -> JSONResponse:\n application_server_key = \"<generated from vapid-gen>\"\n return JSONResponse(content={\"public_key\": application_server_key})\n\n\n@app.post(\"/notification/subscribe\")\nasync def subscribe_user(subscription: WebPushSubscription) -> JSONResponse:\n message = wp.get(message=\"Hello, world\", subscription=subscription)\n async with aiohttp.ClientSession() as session:\n await session.post(\n url=str(subscription.endpoint),\n data=message.encrypted,\n headers=message.headers,\n )\n return JSONResponse(content={\"status\": \"ok\"})\n```\n\n## FAQ\n- Why do I need another library?\n\nThe current python libraries that work with Web Push have been written for a very long time, so they do not support typing, try to support outdated encryption algorithms and pull a lot of deprecated dependencies.\n\n- Why is only `aes128gcm` supported?\n\nAccording to the [RFC8192](https://datatracker.ietf.org/doc/html/rfc8291), this is the recommended format. At the moment, all modern systems support this encryption.\n\n- Will there be support for other encryption modes?\n\nNew, yes, but there are no old ones, for example `aesgcm`\n\n- Who is this library for?\n\nYou need type support, you're writing a modern backend, minimum number of dependencies.\n\nAnd last one, if you have ideas for improvements, bug fixes, feel free to contribute.\n\n## Change log\n\n- 1.0.0 - initial release\n\n## Credits\n\n- [pywebpush](https://github.com/web-push-libs/pywebpush)\n- [http-ece](https://github.com/web-push-libs/encrypted-content-encoding)",
"bugtrack_url": null,
"license": null,
"summary": "WebPush library for python",
"version": "1.0.4",
"project_urls": {
"Homepage": "https://github.com/delvinru/webpush-py",
"Repository": "https://github.com/delvinru/webpush-py"
},
"split_keywords": [
"pwa",
" pydantic",
" webpush"
],
"urls": [
{
"comment_text": null,
"digests": {
"blake2b_256": "cf8d015e69287701742e47c6b7da1a4058d41d171aeb78830ebb014bc5286edd",
"md5": "3db5ac4949d5dfb4ff895c1a2efa0959",
"sha256": "4270e7ef40cfe1dd36f58b4a855e10ace488b3363723da30683f391646568c85"
},
"downloads": -1,
"filename": "webpush-1.0.4-py3-none-any.whl",
"has_sig": false,
"md5_digest": "3db5ac4949d5dfb4ff895c1a2efa0959",
"packagetype": "bdist_wheel",
"python_version": "py3",
"requires_python": "~=3.10",
"size": 7394,
"upload_time": "2025-01-11T22:22:28",
"upload_time_iso_8601": "2025-01-11T22:22:28.664782Z",
"url": "https://files.pythonhosted.org/packages/cf/8d/015e69287701742e47c6b7da1a4058d41d171aeb78830ebb014bc5286edd/webpush-1.0.4-py3-none-any.whl",
"yanked": false,
"yanked_reason": null
},
{
"comment_text": null,
"digests": {
"blake2b_256": "37ed90fb111ea4c86ab4d8f79469fb907775e94ccd31fb0efe731b191769de59",
"md5": "3fb74d3aa411e7dc8c97aae619eb43d6",
"sha256": "c1c0c2a8ec90392905505befb1eca92ea334364ced87367fe888f12866603d55"
},
"downloads": -1,
"filename": "webpush-1.0.4.tar.gz",
"has_sig": false,
"md5_digest": "3fb74d3aa411e7dc8c97aae619eb43d6",
"packagetype": "sdist",
"python_version": "source",
"requires_python": "~=3.10",
"size": 36015,
"upload_time": "2025-01-11T22:22:30",
"upload_time_iso_8601": "2025-01-11T22:22:30.317620Z",
"url": "https://files.pythonhosted.org/packages/37/ed/90fb111ea4c86ab4d8f79469fb907775e94ccd31fb0efe731b191769de59/webpush-1.0.4.tar.gz",
"yanked": false,
"yanked_reason": null
}
],
"upload_time": "2025-01-11 22:22:30",
"github": true,
"gitlab": false,
"bitbucket": false,
"codeberg": false,
"github_user": "delvinru",
"github_project": "webpush-py",
"travis_ci": false,
"coveralls": false,
"github_actions": false,
"lcname": "webpush"
}