{"id":13813884,"url":"https://github.com/safwanrahman/django-webpush","last_synced_at":"2025-05-14T16:15:29.620Z","repository":{"id":41281127,"uuid":"57388002","full_name":"safwanrahman/django-webpush","owner":"safwanrahman","description":"Web Push Notification Package for Django","archived":false,"fork":false,"pushed_at":"2025-01-13T18:22:13.000Z","size":99,"stargazers_count":402,"open_issues_count":41,"forks_count":107,"subscribers_count":17,"default_branch":"master","last_synced_at":"2025-04-05T19:08:20.323Z","etag":null,"topics":["django","django-webpush","hacktoberfest","jinja2","notification","notifications","push-notifications","vapid-keys","webpush","webpush-message"],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"gpl-3.0","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/safwanrahman.png","metadata":{"files":{"readme":"README.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2016-04-29T13:50:54.000Z","updated_at":"2025-03-30T08:59:52.000Z","dependencies_parsed_at":"2024-04-30T22:23:34.731Z","dependency_job_id":"d6ee0d18-e4b0-48f2-84ca-fa0ac8d64ef0","html_url":"https://github.com/safwanrahman/django-webpush","commit_stats":{"total_commits":85,"total_committers":24,"mean_commits":"3.5416666666666665","dds":0.3647058823529412,"last_synced_commit":"76bc13fb2df4c7879cba8d982d5230ec35f29b6e"},"previous_names":[],"tags_count":13,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/safwanrahman%2Fdjango-webpush","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/safwanrahman%2Fdjango-webpush/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/safwanrahman%2Fdjango-webpush/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/safwanrahman%2Fdjango-webpush/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/safwanrahman","download_url":"https://codeload.github.com/safwanrahman/django-webpush/tar.gz/refs/heads/master","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":248631670,"owners_count":21136554,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":["django","django-webpush","hacktoberfest","jinja2","notification","notifications","push-notifications","vapid-keys","webpush","webpush-message"],"created_at":"2024-08-04T04:01:34.501Z","updated_at":"2025-04-12T20:40:24.939Z","avatar_url":"https://github.com/safwanrahman.png","language":"Python","funding_links":[],"categories":["Python","Developer Tools \u0026 Libraries"],"sub_categories":["🚀 How to contribute"],"readme":"\nDjango-Webpush\n==============\n[![Say Thanks!](https://img.shields.io/badge/Say%20Thanks-!-1EAEDB.svg)](https://saythanks.io/to/safwanrahman)\n\nDjango-Webpush is a Package made for integrating and sending [Web Push Notification](https://developer.mozilla.org/en/docs/Web/API/Push_API) in Django Application.\n\nCurrently, it Supports Sending Push Notification to **Firefox 46+, Chrome 52+ and Apple devices on iOS 16.4+**.\n\n----------\n\nInstallation and Setup\n----------------------\n\nYou can install it easily from pypi by running\n\n    pip install django-webpush\n\nAfter installing the package, add `webpush` in in your `INSTALLED_APPS` settings\n\n```python\nINSTALLED_APPS = (\n    ...\n    'webpush',\n)\n```\n\nIf you would like to send notification to Google Chrome Users, you need to add a ``WEBPUSH_SETTINGS`` entry with the **Vapid Credentials** Like following:\n\n```python\nWEBPUSH_SETTINGS = {\n    \"VAPID_PUBLIC_KEY\": \"Vapid Public Key\",\n    \"VAPID_PRIVATE_KEY\": \"Vapid Private Key\",\n    \"VAPID_ADMIN_EMAIL\": \"admin@example.com\"\n}\n```\n\n**Replace ``\"Vapid Public Key\"`` and ``\"Vapid Private Key\"`` with your Vapid Keys. Also replace ``admin@example.com`` with your email so that the push server of browser can reach to you if anything goes wrong.**\n\n**Generate a Vapid key pair**\n\n```shell\npython manage.py webpush_generate_vapid_keypair\n```\n\nThen include `webpush` in the `urls.py`\n\n```python\n# Django \u003e= 2.0\nfrom django.urls import path, include\n\nurlpatterns =  [\n    path('webpush/', include('webpush.urls'))\n]\n\n# Django \u003c 2.0\nfrom django.conf.urls import url, include\n\nurlpatterns =  [\n    url(r'^webpush/', include('webpush.urls'))\n]\n```\n\n`django-webpush` is shipped with built in **`jinja`** support.\nIf you would like to use with jinja backend,\npass ``pipeline.jinja2.PipelineExtension`` to your jinja environment.\nIf you are using `django_jinja` as template backend you can do following:\n\n```python\nfrom django_jinja.builtins import DEFAULT_EXTENSIONS\n\nTEMPLATES = [\n    {\n        \"BACKEND\": \"django_jinja.backend.Jinja2\",\n        \"OPTIONS\": {\n            \"extensions\": DEFAULT_EXTENSIONS + [\n                \"webpush.jinja2.WebPushExtension\"\n            ]\n        }\n    }\n]\n```\n\n**Then run Migration by ***`python manage.py migrate`*****\n\nAdding Web Push Information in Template\n---------------------------------------\n\nSo in template, you need to load `webpush_notifications` custom template tag by following:\n\n- If you are using built in templating engine, add `{% load webpush_notifications %}` in the template\n- If you are using **jinja** templating engine, you do not need to load anything.\n\nNext, inside the `\u003chead\u003e\u003c/head\u003e` tag add `webpush_header` according to your templating engine:\n\n```html\n\u003chead\u003e\n  # For django templating engine\n  {% webpush_header %}\n\n  # For jinja templating engine\n  {{ webpush_header() }}\n\u003c/head\u003e\n```\n\nNext, inside the `\u003cbody\u003e\u003c/body\u003e` tag, insert `webush_button` where you would like to see the **Subscribe to Push Messaging** Button. Like following\n\n```html\n\u003cbody\u003e\n  \u003cp\u003e Hello World! \u003c/p\u003e\n\n  # For django templating engine\n  {% webpush_button %}\n\n  # For jinja templating engine\n  {{ webpush_button() }}\n\u003c/body\u003e\n```\n\nOr if you want to add custom classes (e.g. bootstrap)\n\n```html\n\u003cbody\u003e\n  \u003cp\u003e Hello World! \u003c/p\u003e\n\n  # For django templating engine\n  {% webpush_button with_class=\"btn btn-outline-info\" %}\n\n  # For jinja templating engine\n  {{ webpush_button(with_class=\"btn btn-outline-info\") }}\n\u003c/body\u003e\n```\n\n \u003e**Note:** The Push Notification Button will show only if the user is logged in or any `group` named is passed through `webpush` context\n\n ***If you would like to mark the subscription as a group, like all person subscribe for push notification from the template should be marked as group and would get same notification, you should pass a `webpush` context to the template through views. The `webpush` context should have a dictionary like `{\"group\": group_name}`*** . Like following\n\n```python\n webpush = {\"group\": group_name } # The group_name should be the name you would define.\n\nreturn render(request, 'template.html',  {\"webpush\":webpush})\n```\n\n\u003e **Note:** If you dont pass `group` through the `webpush` context, only logged in users can see the button for subscription and able to get notification.\n\n----------\n\nSending Web Push Notification\n-----------------------------\n\nA Web Push generally have a header and body. According to the W3C Specification, the data should be encrypted in transmission. The data is addressed as payload generally. Also a TTL header should be included indicating how much time the web push server store the data if the user is not online.\nSo in order to send notification, see below.\n\n- If you would like to send notification to a specific group, do like following:\n\n    ```python\n    from webpush import send_group_notification\n\n    payload = {\"head\": \"Welcome!\", \"body\": \"Hello World\"}\n\n    send_group_notification(group_name=\"my_group\", payload=payload, ttl=1000)\n    # All subscribe subscribe through \"my_group\" will get a web push notification.\n    # A ttl of 1000 is passed so the web push server will store\n    # the data maximum 1000 seconds if any user is not online\n\n    ```\n\n- If you would like to send Notification to a specific user, do like following\n\n    ```python\n    from webpush import send_user_notification\n\n    payload = {\"head\": \"Welcome!\", \"body\": \"Hello World\"}\n\n    send_user_notification(user=user, payload=payload, ttl=1000)\n    # Here in the user parameter, a user object should be passed\n    # The user will get notification to all of his subscribed browser. A user can subscribe many browsers.\n    ```\n\n    **And the subscribers will get a notification like:**\n\n![Web Push Notification](http://i.imgur.com/VA6cxRc.png)\n\n- If you notification should have an icon or open a url when clicked, you can add those to the payload:\n\n    ``` python\n    from webpush import send_user_notification\n    \n    from webpush import send_group_notification\n\n    payload = {\"head\": \"Welcome!\", \"body”: \"Hello World\", \n               \"icon\": \"https://i.imgur.com/dRDxiCQ.png“, \"url\": \"https://www.example.com\"}\n\n    send_group_notification(group_name=\"my_group\", payload=payload, ttl=1000)\n    ```\n\n**And the subscribers will get a notification like:**\n\n![Web Push Notification icon](http://i.imgur.com/Vr1RMvF.png)\n\n**That will open https://www.example.com if clicked.**\n\n- If you want fine grained control over sending a single push message, do like following\n\n    ```python\n    from webpush.utils import send_to_subscription\n\n    payload = {\"head\": \"Welcome!\", \"body\": \"Hello World\"}\n\n    user = request.user\n    push_infos = user.webpush_info.select_related(\"subscription\")\n    for push_info in push_infos:\n        send_to_subscription(push_info.subscription, payload)\n\n    ```\n\n **And the subscribers will get a notification like**\n ![Web Push Notification](http://i.imgur.com/VA6cxRc.png)\n\nContributing\n------------\n\nIf you would like to contribute, fork the repository and send a pull request. You can also open an issue if you find any bug or want to suggest a feature.\n\nInternationalization\n---------------------\n\nThe package is shipped with built in internationalization support.\n\nIf you would like to add more language or update translation, you can run the following command:\n\n    ```bash\n\n    # Add js translation\n    django-admin makemessages -d djangojs -l \u003clanguage_code\u003e\n\n    # Add python translation\n    django-admin makemessages -l \u003clanguage_code\u003e\n    ```\n\nAfter that, you can run `django-admin compilemessages` to compile the messages.\n\nLicense\n=======\n\nCopyright © 2018 Safwan Rahman\n\nThis program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.\n\n   This program is distributed in the hope that it will be useful,\n   but WITHOUT ANY WARRANTY; without even the implied warranty of\n   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\n   GNU General Public License for more details.\n\n   You should have received a copy of the GNU General Public License\n    along with this program.  If not, see \u003chttp://www.gnu.org/licenses/\u003e.\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsafwanrahman%2Fdjango-webpush","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fsafwanrahman%2Fdjango-webpush","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fsafwanrahman%2Fdjango-webpush/lists"}