{"id":3440,"date":"2026-11-17T10:12:00","date_gmt":"2026-11-17T04:42:00","guid":{"rendered":"https:\/\/larapush.com\/blog\/?p=3440"},"modified":"2026-11-17T10:12:00","modified_gmt":"2026-11-17T04:42:00","slug":"send-web-push-notifications-python","status":"publish","type":"post","link":"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/","title":{"rendered":"How to Send Web Push Notifications From Python"},"content":{"rendered":"\n<p><strong>To send web push notifications from Python, install pywebpush, generate a VAPID key pair, and store each browser&#8217;s push subscription in your database.<\/strong> Then call webpush() with the subscription, a JSON payload, your private key and a vapid_claims dict with a mailto: subject. pywebpush encrypts the message and posts it to the browser&#8217;s push service.<\/p>\n\n\n\n<p>Python web push notifications work with any framework: Flask, Django, FastAPI or a plain script run by cron. The protocol is an open standard, so you don&#8217;t need Firebase or a paid service on the sending side. The code below is checked against <a href=\"https:\/\/github.com\/web-push-libs\/pywebpush\" target=\"_blank\" rel=\"noreferrer noopener\">pywebpush<\/a> 2.5.0 and py-vapid 1.9.6, the current releases in November 2026.<\/p>\n\n\n\n<div id=\"ez-toc-container\" class=\"ez-toc-v2_0_63 counter-hierarchy ez-toc-counter ez-toc-grey ez-toc-container-direction\">\n<div class=\"ez-toc-title-container\">\n<p class=\"ez-toc-title \" >Table of Contents<\/p>\n<span class=\"ez-toc-title-toggle\"><a href=\"#\" class=\"ez-toc-pull-right ez-toc-btn ez-toc-btn-xs ez-toc-btn-default ez-toc-toggle\" aria-label=\"Toggle Table of Content\"><span class=\"ez-toc-js-icon-con\"><span class=\"\"><span class=\"eztoc-hide\" style=\"display:none;\">Toggle<\/span><span class=\"ez-toc-icon-toggle-span\"><svg style=\"fill: #999;color:#999\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" class=\"list-377408\" width=\"20px\" height=\"20px\" viewBox=\"0 0 24 24\" fill=\"none\"><path d=\"M6 6H4v2h2V6zm14 0H8v2h12V6zM4 11h2v2H4v-2zm16 0H8v2h12v-2zM4 16h2v2H4v-2zm16 0H8v2h12v-2z\" fill=\"currentColor\"><\/path><\/svg><svg style=\"fill: #999;color:#999\" class=\"arrow-unsorted-368013\" xmlns=\"http:\/\/www.w3.org\/2000\/svg\" width=\"10px\" height=\"10px\" viewBox=\"0 0 24 24\" version=\"1.2\" baseProfile=\"tiny\"><path d=\"M18.2 9.3l-6.2-6.3-6.2 6.3c-.2.2-.3.4-.3.7s.1.5.3.7c.2.2.4.3.7.3h11c.3 0 .5-.1.7-.3.2-.2.3-.5.3-.7s-.1-.5-.3-.7zM5.8 14.7l6.2 6.3 6.2-6.3c.2-.2.3-.5.3-.7s-.1-.5-.3-.7c-.2-.2-.4-.3-.7-.3h-11c-.3 0-.5.1-.7.3-.2.2-.3.5-.3.7s.1.5.3.7z\"\/><\/svg><\/span><\/span><\/span><\/a><\/span><\/div>\n<nav><ul class='ez-toc-list ez-toc-list-level-1 ' ><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-1\" href=\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#What_do_you_need_to_send_Python_web_push_notifications\" title=\"What do you need to send Python web push notifications?\">What do you need to send Python web push notifications?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-2\" href=\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#How_do_you_install_pywebpush_and_generate_VAPID_keys\" title=\"How do you install pywebpush and generate VAPID keys?\">How do you install pywebpush and generate VAPID keys?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-3\" href=\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#How_do_you_collect_subscriptions_from_the_browser\" title=\"How do you collect subscriptions from the browser?\">How do you collect subscriptions from the browser?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-4\" href=\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#How_do_you_send_a_notification_with_pywebpush\" title=\"How do you send a notification with pywebpush?\">How do you send a notification with pywebpush?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-5\" href=\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#Which_pywebpush_options_should_you_set\" title=\"Which pywebpush options should you set?\">Which pywebpush options should you set?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-6\" href=\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#How_do_you_handle_errors_and_expired_subscriptions\" title=\"How do you handle errors and expired subscriptions?\">How do you handle errors and expired subscriptions?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-7\" href=\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#Does_Python_web_push_work_on_iPhone\" title=\"Does Python web push work on iPhone?\">Does Python web push work on iPhone?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-8\" href=\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#Should_you_build_it_in_Python_or_use_a_push_panel\" title=\"Should you build it in Python or use a push panel?\">Should you build it in Python or use a push panel?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-9\" href=\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#Where_does_LaraPush_fit\" title=\"Where does LaraPush fit?\">Where does LaraPush fit?<\/a><\/li><li class='ez-toc-page-1 ez-toc-heading-level-2'><a class=\"ez-toc-link ez-toc-heading-10\" href=\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#Frequently_asked_questions\" title=\"Frequently asked questions\">Frequently asked questions<\/a><\/li><\/ul><\/nav><\/div>\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"What_do_you_need_to_send_Python_web_push_notifications\"><\/span>What do you need to send Python web push notifications?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>You need HTTPS, a VAPID key pair, a service worker, a table of subscriptions and the pywebpush package. pywebpush 2.5 requires Python 3.10 or newer, according to its <a href=\"https:\/\/pypi.org\/project\/pywebpush\/\" target=\"_blank\" rel=\"noreferrer noopener\">PyPI page<\/a>.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Piece<\/th><th>Purpose<\/th><th>Notes<\/th><\/tr><\/thead><tbody><tr><td>HTTPS site<\/td><td>Service workers only run in secure contexts<\/td><td>localhost works for testing<\/td><\/tr><tr><td>VAPID key pair<\/td><td>Identifies your server to push services<\/td><td>Created with the vapid tool from py-vapid<\/td><\/tr><tr><td>Service worker<\/td><td>Shows the notification when a push arrives<\/td><td>Same JavaScript whatever your backend<\/td><\/tr><tr><td>Subscriptions table<\/td><td>Stores endpoint, p256dh and auth per browser<\/td><td>One row per browser<\/td><\/tr><tr><td>pywebpush<\/td><td>Encrypts and sends each message<\/td><td>Installs py-vapid as a dependency<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>The browser half doesn&#8217;t change between languages. If you also work in PHP, my <a href=\"https:\/\/larapush.com\/blog\/send-web-push-php-laravel\/\">PHP and Laravel web push guide<\/a> uses the same service worker.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_do_you_install_pywebpush_and_generate_VAPID_keys\"><\/span>How do you install pywebpush and generate VAPID keys?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Install pywebpush with pip, then run the vapid command from py-vapid once. It writes two PEM files and can print the public key in the format browsers expect.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>pip install pywebpush\nvapid --gen                    # writes private_key.pem and public_key.pem\nvapid --applicationServerKey   # prints the public key for the browser<\/code><\/pre>\n\n\n\n<p>Keep private_key.pem on the server, outside your web root, and back it up. The printed &#8220;Application Server Key&#8221; is the public key your page passes to pushManager.subscribe. Generate keys once, because every subscription is tied to the public key it was created with. My post on <a href=\"https:\/\/larapush.com\/blog\/vapid-keys-web-push\/\">VAPID keys for web push<\/a> explains why.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_do_you_collect_subscriptions_from_the_browser\"><\/span>How do you collect subscriptions from the browser?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Register a service worker, ask for permission on a click, subscribe with your public key, and post the subscription JSON to your Python backend. The service worker below shows a notification from a JSON payload.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>\/\/ sw.js, served from your site root\nself.addEventListener('push', (event) =&gt; {\n  const data = event.data ? event.data.json() : {};\n  event.waitUntil(\n    self.registration.showNotification(data.title || 'New update', {\n      body: data.body,\n      data: { url: data.url || '\/' }\n    })\n  );\n});\nself.addEventListener('notificationclick', (event) =&gt; {\n  event.notification.close();\n  event.waitUntil(clients.openWindow(event.notification.data.url));\n});<\/code><\/pre>\n\n\n\n<p>On the page, call navigator.serviceWorker.register(&#8216;\/sw.js&#8217;), then registration.pushManager.subscribe with userVisibleOnly set to true and applicationServerKey set to your public key. Send JSON.stringify(subscription) to an endpoint such as \/api\/subscribe. MDN&#8217;s <a href=\"https:\/\/developer.mozilla.org\/en-US\/docs\/Web\/API\/PushManager\/subscribe\" target=\"_blank\" rel=\"noreferrer noopener\">PushManager.subscribe() reference<\/a> lists the options.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_do_you_send_a_notification_with_pywebpush\"><\/span>How do you send a notification with pywebpush?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Call webpush() with four arguments: the subscription dict, the data string, the private key and the claims. The example below is a minimal Flask app that stores subscriptions and sends to all of them.<\/p>\n\n\n\n<pre class=\"wp-block-code\"><code>import json, os\nfrom flask import Flask, request\nfrom pywebpush import webpush, WebPushException\n\napp = Flask(__name__)\nsubscriptions = {}  # use a real database in production\nVAPID_PRIVATE_KEY = os.environ.get(\"VAPID_PRIVATE_KEY\", \"private_key.pem\")\n\n@app.post(\"\/api\/subscribe\")\ndef subscribe():\n    sub = request.get_json()\n    subscriptions[sub[\"endpoint\"]] = sub\n    return \"\", 201\n\n@app.post(\"\/api\/send\")\ndef send():\n    payload = json.dumps({\n        \"title\": \"New post: Python web push\",\n        \"body\": \"Read the step-by-step guide\",\n        \"url\": \"\/blog\/python-web-push\/\",\n    })\n    for endpoint, sub in list(subscriptions.items()):\n        try:\n            webpush(\n                subscription_info=sub,\n                data=payload,\n                vapid_private_key=VAPID_PRIVATE_KEY,\n                vapid_claims={\"sub\": \"mailto:you@example.com\"},\n                ttl=3600,\n            )\n        except WebPushException as ex:\n            status = ex.response.status_code if ex.response is not None else None\n            if status in (404, 410):\n                del subscriptions[endpoint]  # expired or unsubscribed\n            else:\n                app.logger.error(\"push failed: %s\", ex)\n    return \"\", 202<\/code><\/pre>\n\n\n\n<p>The vapid_private_key argument takes a path to a PEM file or the key as a base64 string. Pass a fresh claims dict on every call: the README warns that pywebpush mutates it, adding aud and exp for you.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Which_pywebpush_options_should_you_set\"><\/span>Which pywebpush options should you set?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Set ttl on every send. pywebpush defaults to a TTL of 0, which tells the push service it may drop the message if the device is offline right now. That surprises many people the first time.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Option<\/th><th>What it does<\/th><th>Default<\/th><\/tr><\/thead><tbody><tr><td>ttl<\/td><td>Seconds the push service keeps the message for an offline device<\/td><td>0<\/td><\/tr><tr><td>headers<\/td><td>Extra headers, such as {&#8220;Urgency&#8221;: &#8220;high&#8221;} or {&#8220;Topic&#8221;: &#8220;price&#8221;}<\/td><td>None<\/td><\/tr><tr><td>content_encoding<\/td><td>aes128gcm (standard) or the older aesgcm<\/td><td>aes128gcm<\/td><\/tr><tr><td>timeout<\/td><td>Request timeout in seconds<\/td><td>None<\/td><\/tr><tr><td>requests_session<\/td><td>Reuse one HTTP session for many sends<\/td><td>None<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>Urgency and Topic are standard headers from <a href=\"https:\/\/www.rfc-editor.org\/rfc\/rfc8030\" target=\"_blank\" rel=\"noreferrer noopener\">RFC 8030<\/a>, so you pass them through headers. Keep the payload small, because RFC 8030 only requires push services to accept 4,096 bytes.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"How_do_you_handle_errors_and_expired_subscriptions\"><\/span>How do you handle errors and expired subscriptions?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Remove the subscription when the push service returns 404 or 410, because those codes mean it no longer exists. pywebpush raises WebPushException and attaches the HTTP response, so check ex.response.status_code as in the example.<\/p>\n\n\n\n<p>Other status codes point to different fixes:<\/p>\n\n\n\n<ul class=\"wp-block-list\">\n<li><strong>400 or 403<\/strong>: usually a VAPID mismatch. The public key used in the browser must pair with the private key on the server.<\/li>\n\n\n\n<li><strong>413<\/strong>: the payload is too large.<\/li>\n\n\n\n<li><strong>429<\/strong>: you&#8217;re sending too fast. Back off and retry later.<\/li>\n<\/ul>\n\n\n\n<p>For big lists, don&#8217;t send one by one inside a web request. Move sending to a background worker such as Celery or RQ, or use webpush_async with aiohttp for concurrent sends. Either way, keep a single requests or aiohttp session per batch.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Does_Python_web_push_work_on_iPhone\"><\/span>Does Python web push work on iPhone?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Yes, on iOS 16.4 and later, once the visitor adds your site to the Home Screen. pywebpush sends to Apple&#8217;s push endpoint like any other, as long as your site has a web app manifest and the subscribe call happens after a tap. The steps are in my guide on <a href=\"https:\/\/larapush.com\/blog\/how-to-get-web-push-working-on-iphone\/\">getting web push working on iPhone<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Should_you_build_it_in_Python_or_use_a_push_panel\"><\/span>Should you build it in Python or use a push panel?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>Build it in Python when you need alerts triggered by your own app&#8217;s events, such as price drops or account activity, and you have developers to look after it. Choose a panel when non-developers will send campaigns, because pywebpush gives you delivery only.<\/p>\n\n\n\n<figure class=\"wp-block-table\"><table><thead><tr><th>Need<\/th><th>DIY with pywebpush<\/th><th>Push panel<\/th><\/tr><\/thead><tbody><tr><td>Event alerts from your code<\/td><td>Good fit<\/td><td>Works through an API<\/td><\/tr><tr><td>Campaign editor, templates, scheduling<\/td><td>You build it<\/td><td>Included<\/td><\/tr><tr><td>Segments and reports<\/td><td>You build it<\/td><td>Included<\/td><\/tr><tr><td>Expired subscription cleanup<\/td><td>You build it<\/td><td>Handled for you<\/td><\/tr><\/tbody><\/table><\/figure>\n\n\n\n<p>If you&#8217;re also using Node.js elsewhere, my <a href=\"https:\/\/larapush.com\/blog\/send-web-push-notifications-nodejs\/\">Node.js web push guide<\/a> covers the same flow with the web-push package.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Where_does_LaraPush_fit\"><\/span>Where does LaraPush fit?<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<p>LaraPush is a self-hosted web push panel that runs on your own VPS. It gives non-developers a campaign editor, scheduling, segmentation and click reports, and its REST API has no call limits, so a Python app can trigger sends without handling encryption itself. See the <a href=\"https:\/\/larapush.com\/features\/\">features overview<\/a> and the <a href=\"https:\/\/larapush.com\/guide\/\">setup guide<\/a>.<\/p>\n\n\n\n<p>The trade-offs are that you run the server, the licence covers one server, and there&#8217;s no free plan. Plans start from $499 one-time; check the <a href=\"https:\/\/larapush.com\/pricing\/\">pricing page<\/a> for current prices. To compare it with SaaS options, see my <a href=\"https:\/\/larapush.com\/blog\/best-push-notification-services-and-tools\/\">guide to push notification services<\/a>.<\/p>\n\n\n\n<h2 class=\"wp-block-heading\"><span class=\"ez-toc-section\" id=\"Frequently_asked_questions\"><\/span>Frequently asked questions<span class=\"ez-toc-section-end\"><\/span><\/h2>\n\n\n\n<div class=\"schema-faq wp-block-yoast-faq-block\"><div class=\"schema-faq-section\" id=\"faq-question-1763371000000\"><strong class=\"schema-faq-question\">Which Python library sends web push notifications?<\/strong> <p class=\"schema-faq-answer\">pywebpush is the standard choice. It&#8217;s open source, handles aes128gcm payload encryption and VAPID signing, and works with Flask, Django, FastAPI or plain scripts. It installs py-vapid, which provides the vapid command for creating keys.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1763371001111\"><strong class=\"schema-faq-question\">Why are my pywebpush notifications not arriving?<\/strong> <p class=\"schema-faq-answer\">Check the TTL first. pywebpush defaults to a TTL of 0, so the push service may drop messages for devices that are offline. Also confirm the browser&#8217;s public key matches your private key, and that the service worker calls showNotification.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1763371002222\"><strong class=\"schema-faq-question\">Can I use Django or FastAPI instead of Flask?<\/strong> <p class=\"schema-faq-answer\">Yes. pywebpush doesn&#8217;t depend on any web framework. Save subscriptions with your ORM, then call webpush() from a view, a background task or a management command. For async frameworks, webpush_async sends with aiohttp.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1763371003333\"><strong class=\"schema-faq-question\">Do I need Firebase to send web push from Python?<\/strong> <p class=\"schema-faq-answer\">No. pywebpush sends directly to each browser&#8217;s push service using VAPID. The README notes that sending to Firebase Cloud Messaging with an old server key is no longer supported, but standard web push to Chrome isn&#8217;t affected.<\/p> <\/div> <div class=\"schema-faq-section\" id=\"faq-question-1763371004444\"><strong class=\"schema-faq-question\">Where should I keep the VAPID private key?<\/strong> <p class=\"schema-faq-answer\">On the server, outside the web root, in a secrets manager or an environment variable, with a backup. If you lose it, you can&#8217;t send to existing subscribers, and anyone who gets it can sign messages as your server.<\/p> <\/div><\/div>\n","protected":false},"excerpt":{"rendered":"How to send web push notifications from Python with pywebpush: VAPID keys, a Flask example, TTL and other options, and error handling.","protected":false},"author":7,"featured_media":3450,"comment_status":"open","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":"","csco_display_header_overlay":false,"csco_singular_sidebar":"","csco_page_header_type":""},"categories":[68],"tags":[],"yoast_head":"<!-- This site is optimized with the Yoast SEO plugin v22.2 - https:\/\/yoast.com\/wordpress\/plugins\/seo\/ -->\n<title>How to Send Web Push Notifications From Python<\/title>\n<meta name=\"robots\" content=\"index, follow, max-snippet:-1, max-image-preview:large, max-video-preview:-1\" \/>\n<link rel=\"canonical\" href=\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/\" \/>\n<meta property=\"og:locale\" content=\"en_US\" \/>\n<meta property=\"og:type\" content=\"article\" \/>\n<meta property=\"og:title\" content=\"How to Send Web Push Notifications From Python\" \/>\n<meta property=\"og:description\" content=\"How to send web push notifications from Python with pywebpush: VAPID keys, a Flask example, TTL and other options, and error handling.\" \/>\n<meta property=\"og:url\" content=\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/\" \/>\n<meta property=\"og:site_name\" content=\"LaraPush Blog\" \/>\n<meta property=\"article:published_time\" content=\"2026-11-17T04:42:00+00:00\" \/>\n<meta property=\"og:image\" content=\"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/send-web-push-notifications-python.jpg\" \/>\n\t<meta property=\"og:image:width\" content=\"1200\" \/>\n\t<meta property=\"og:image:height\" content=\"675\" \/>\n\t<meta property=\"og:image:type\" content=\"image\/jpeg\" \/>\n<meta name=\"author\" content=\"Ritesh Das\" \/>\n<meta name=\"twitter:card\" content=\"summary_large_image\" \/>\n<meta name=\"twitter:label1\" content=\"Written by\" \/>\n\t<meta name=\"twitter:data1\" content=\"Ritesh Das\" \/>\n\t<meta name=\"twitter:label2\" content=\"Est. reading time\" \/>\n\t<meta name=\"twitter:data2\" content=\"7 minutes\" \/>\n<script type=\"application\/ld+json\" class=\"yoast-schema-graph\">{\"@context\":\"https:\/\/schema.org\",\"@graph\":[{\"@type\":\"Article\",\"@id\":\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#article\",\"isPartOf\":{\"@id\":\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/\"},\"author\":{\"name\":\"Ritesh Das\",\"@id\":\"https:\/\/larapush.com\/blog\/#\/schema\/person\/4f23894f98426ea3a6bd617e59f03bbd\"},\"headline\":\"How to Send Web Push Notifications From Python\",\"datePublished\":\"2026-11-17T04:42:00+00:00\",\"dateModified\":\"2026-11-17T04:42:00+00:00\",\"mainEntityOfPage\":{\"@id\":\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/\"},\"wordCount\":1282,\"commentCount\":0,\"publisher\":{\"@id\":\"https:\/\/larapush.com\/blog\/#organization\"},\"image\":{\"@id\":\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/send-web-push-notifications-python.jpg\",\"articleSection\":[\"How to\"],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"CommentAction\",\"name\":\"Comment\",\"target\":[\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#respond\"]}]},{\"@type\":[\"WebPage\",\"FAQPage\"],\"@id\":\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/\",\"url\":\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/\",\"name\":\"How to Send Web Push Notifications From Python\",\"isPartOf\":{\"@id\":\"https:\/\/larapush.com\/blog\/#website\"},\"primaryImageOfPage\":{\"@id\":\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#primaryimage\"},\"image\":{\"@id\":\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#primaryimage\"},\"thumbnailUrl\":\"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/send-web-push-notifications-python.jpg\",\"datePublished\":\"2026-11-17T04:42:00+00:00\",\"dateModified\":\"2026-11-17T04:42:00+00:00\",\"breadcrumb\":{\"@id\":\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#breadcrumb\"},\"mainEntity\":[{\"@id\":\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#faq-question-1763371000000\"},{\"@id\":\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#faq-question-1763371001111\"},{\"@id\":\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#faq-question-1763371002222\"},{\"@id\":\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#faq-question-1763371003333\"},{\"@id\":\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#faq-question-1763371004444\"}],\"inLanguage\":\"en-US\",\"potentialAction\":[{\"@type\":\"ReadAction\",\"target\":[\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/\"]}]},{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#primaryimage\",\"url\":\"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/send-web-push-notifications-python.jpg\",\"contentUrl\":\"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/send-web-push-notifications-python.jpg\",\"width\":1200,\"height\":675,\"caption\":\"Illustration of a Python server sending web push notifications to a browser window\"},{\"@type\":\"BreadcrumbList\",\"@id\":\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#breadcrumb\",\"itemListElement\":[{\"@type\":\"ListItem\",\"position\":1,\"name\":\"Home\",\"item\":\"https:\/\/larapush.com\/blog\/\"},{\"@type\":\"ListItem\",\"position\":2,\"name\":\"How to Send Web Push Notifications From Python\"}]},{\"@type\":\"WebSite\",\"@id\":\"https:\/\/larapush.com\/blog\/#website\",\"url\":\"https:\/\/larapush.com\/blog\/\",\"name\":\"LaraPush Blog\",\"description\":\"Stay Ahead, Stay Notified with LaraPush!\",\"publisher\":{\"@id\":\"https:\/\/larapush.com\/blog\/#organization\"},\"potentialAction\":[{\"@type\":\"SearchAction\",\"target\":{\"@type\":\"EntryPoint\",\"urlTemplate\":\"https:\/\/larapush.com\/blog\/?s={search_term_string}\"},\"query-input\":\"required name=search_term_string\"}],\"inLanguage\":\"en-US\"},{\"@type\":\"Organization\",\"@id\":\"https:\/\/larapush.com\/blog\/#organization\",\"name\":\"LaraPush\",\"url\":\"https:\/\/larapush.com\/blog\/\",\"logo\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/larapush.com\/blog\/#\/schema\/logo\/image\/\",\"url\":\"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2022\/05\/LARAPUSH.png\",\"contentUrl\":\"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2022\/05\/LARAPUSH.png\",\"width\":280,\"height\":60,\"caption\":\"LaraPush\"},\"image\":{\"@id\":\"https:\/\/larapush.com\/blog\/#\/schema\/logo\/image\/\"}},{\"@type\":\"Person\",\"@id\":\"https:\/\/larapush.com\/blog\/#\/schema\/person\/4f23894f98426ea3a6bd617e59f03bbd\",\"name\":\"Ritesh Das\",\"image\":{\"@type\":\"ImageObject\",\"inLanguage\":\"en-US\",\"@id\":\"https:\/\/larapush.com\/blog\/#\/schema\/person\/image\/\",\"url\":\"https:\/\/secure.gravatar.com\/avatar\/1bd7bb0ba68e36b218587b72e89e511f?s=96&d=mm&r=g\",\"contentUrl\":\"https:\/\/secure.gravatar.com\/avatar\/1bd7bb0ba68e36b218587b72e89e511f?s=96&d=mm&r=g\",\"caption\":\"Ritesh Das\"},\"url\":\"https:\/\/larapush.com\/blog\/author\/riteshdas\/\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#faq-question-1763371000000\",\"position\":1,\"url\":\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#faq-question-1763371000000\",\"name\":\"Which Python library sends web push notifications?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"pywebpush is the standard choice. It's open source, handles aes128gcm payload encryption and VAPID signing, and works with Flask, Django, FastAPI or plain scripts. It installs py-vapid, which provides the vapid command for creating keys.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#faq-question-1763371001111\",\"position\":2,\"url\":\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#faq-question-1763371001111\",\"name\":\"Why are my pywebpush notifications not arriving?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Check the TTL first. pywebpush defaults to a TTL of 0, so the push service may drop messages for devices that are offline. Also confirm the browser's public key matches your private key, and that the service worker calls showNotification.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#faq-question-1763371002222\",\"position\":3,\"url\":\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#faq-question-1763371002222\",\"name\":\"Can I use Django or FastAPI instead of Flask?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"Yes. pywebpush doesn't depend on any web framework. Save subscriptions with your ORM, then call webpush() from a view, a background task or a management command. For async frameworks, webpush_async sends with aiohttp.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#faq-question-1763371003333\",\"position\":4,\"url\":\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#faq-question-1763371003333\",\"name\":\"Do I need Firebase to send web push from Python?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"No. pywebpush sends directly to each browser's push service using VAPID. The README notes that sending to Firebase Cloud Messaging with an old server key is no longer supported, but standard web push to Chrome isn't affected.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"},{\"@type\":\"Question\",\"@id\":\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#faq-question-1763371004444\",\"position\":5,\"url\":\"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#faq-question-1763371004444\",\"name\":\"Where should I keep the VAPID private key?\",\"answerCount\":1,\"acceptedAnswer\":{\"@type\":\"Answer\",\"text\":\"On the server, outside the web root, in a secrets manager or an environment variable, with a backup. If you lose it, you can't send to existing subscribers, and anyone who gets it can sign messages as your server.\",\"inLanguage\":\"en-US\"},\"inLanguage\":\"en-US\"}]}<\/script>\n<!-- \/ Yoast SEO plugin. -->","yoast_head_json":{"title":"How to Send Web Push Notifications From Python","robots":{"index":"index","follow":"follow","max-snippet":"max-snippet:-1","max-image-preview":"max-image-preview:large","max-video-preview":"max-video-preview:-1"},"canonical":"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/","og_locale":"en_US","og_type":"article","og_title":"How to Send Web Push Notifications From Python","og_description":"How to send web push notifications from Python with pywebpush: VAPID keys, a Flask example, TTL and other options, and error handling.","og_url":"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/","og_site_name":"LaraPush Blog","article_published_time":"2026-11-17T04:42:00+00:00","og_image":[{"width":1200,"height":675,"url":"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/send-web-push-notifications-python.jpg","type":"image\/jpeg"}],"author":"Ritesh Das","twitter_card":"summary_large_image","twitter_misc":{"Written by":"Ritesh Das","Est. reading time":"7 minutes"},"schema":{"@context":"https:\/\/schema.org","@graph":[{"@type":"Article","@id":"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#article","isPartOf":{"@id":"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/"},"author":{"name":"Ritesh Das","@id":"https:\/\/larapush.com\/blog\/#\/schema\/person\/4f23894f98426ea3a6bd617e59f03bbd"},"headline":"How to Send Web Push Notifications From Python","datePublished":"2026-11-17T04:42:00+00:00","dateModified":"2026-11-17T04:42:00+00:00","mainEntityOfPage":{"@id":"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/"},"wordCount":1282,"commentCount":0,"publisher":{"@id":"https:\/\/larapush.com\/blog\/#organization"},"image":{"@id":"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#primaryimage"},"thumbnailUrl":"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/send-web-push-notifications-python.jpg","articleSection":["How to"],"inLanguage":"en-US","potentialAction":[{"@type":"CommentAction","name":"Comment","target":["https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#respond"]}]},{"@type":["WebPage","FAQPage"],"@id":"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/","url":"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/","name":"How to Send Web Push Notifications From Python","isPartOf":{"@id":"https:\/\/larapush.com\/blog\/#website"},"primaryImageOfPage":{"@id":"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#primaryimage"},"image":{"@id":"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#primaryimage"},"thumbnailUrl":"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/send-web-push-notifications-python.jpg","datePublished":"2026-11-17T04:42:00+00:00","dateModified":"2026-11-17T04:42:00+00:00","breadcrumb":{"@id":"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#breadcrumb"},"mainEntity":[{"@id":"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#faq-question-1763371000000"},{"@id":"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#faq-question-1763371001111"},{"@id":"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#faq-question-1763371002222"},{"@id":"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#faq-question-1763371003333"},{"@id":"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#faq-question-1763371004444"}],"inLanguage":"en-US","potentialAction":[{"@type":"ReadAction","target":["https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/"]}]},{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#primaryimage","url":"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/send-web-push-notifications-python.jpg","contentUrl":"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2026\/11\/send-web-push-notifications-python.jpg","width":1200,"height":675,"caption":"Illustration of a Python server sending web push notifications to a browser window"},{"@type":"BreadcrumbList","@id":"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#breadcrumb","itemListElement":[{"@type":"ListItem","position":1,"name":"Home","item":"https:\/\/larapush.com\/blog\/"},{"@type":"ListItem","position":2,"name":"How to Send Web Push Notifications From Python"}]},{"@type":"WebSite","@id":"https:\/\/larapush.com\/blog\/#website","url":"https:\/\/larapush.com\/blog\/","name":"LaraPush Blog","description":"Stay Ahead, Stay Notified with LaraPush!","publisher":{"@id":"https:\/\/larapush.com\/blog\/#organization"},"potentialAction":[{"@type":"SearchAction","target":{"@type":"EntryPoint","urlTemplate":"https:\/\/larapush.com\/blog\/?s={search_term_string}"},"query-input":"required name=search_term_string"}],"inLanguage":"en-US"},{"@type":"Organization","@id":"https:\/\/larapush.com\/blog\/#organization","name":"LaraPush","url":"https:\/\/larapush.com\/blog\/","logo":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/larapush.com\/blog\/#\/schema\/logo\/image\/","url":"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2022\/05\/LARAPUSH.png","contentUrl":"https:\/\/larapush.com\/blog\/wp-content\/uploads\/2022\/05\/LARAPUSH.png","width":280,"height":60,"caption":"LaraPush"},"image":{"@id":"https:\/\/larapush.com\/blog\/#\/schema\/logo\/image\/"}},{"@type":"Person","@id":"https:\/\/larapush.com\/blog\/#\/schema\/person\/4f23894f98426ea3a6bd617e59f03bbd","name":"Ritesh Das","image":{"@type":"ImageObject","inLanguage":"en-US","@id":"https:\/\/larapush.com\/blog\/#\/schema\/person\/image\/","url":"https:\/\/secure.gravatar.com\/avatar\/1bd7bb0ba68e36b218587b72e89e511f?s=96&d=mm&r=g","contentUrl":"https:\/\/secure.gravatar.com\/avatar\/1bd7bb0ba68e36b218587b72e89e511f?s=96&d=mm&r=g","caption":"Ritesh Das"},"url":"https:\/\/larapush.com\/blog\/author\/riteshdas\/"},{"@type":"Question","@id":"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#faq-question-1763371000000","position":1,"url":"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#faq-question-1763371000000","name":"Which Python library sends web push notifications?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"pywebpush is the standard choice. It's open source, handles aes128gcm payload encryption and VAPID signing, and works with Flask, Django, FastAPI or plain scripts. It installs py-vapid, which provides the vapid command for creating keys.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#faq-question-1763371001111","position":2,"url":"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#faq-question-1763371001111","name":"Why are my pywebpush notifications not arriving?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Check the TTL first. pywebpush defaults to a TTL of 0, so the push service may drop messages for devices that are offline. Also confirm the browser's public key matches your private key, and that the service worker calls showNotification.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#faq-question-1763371002222","position":3,"url":"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#faq-question-1763371002222","name":"Can I use Django or FastAPI instead of Flask?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"Yes. pywebpush doesn't depend on any web framework. Save subscriptions with your ORM, then call webpush() from a view, a background task or a management command. For async frameworks, webpush_async sends with aiohttp.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#faq-question-1763371003333","position":4,"url":"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#faq-question-1763371003333","name":"Do I need Firebase to send web push from Python?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"No. pywebpush sends directly to each browser's push service using VAPID. The README notes that sending to Firebase Cloud Messaging with an old server key is no longer supported, but standard web push to Chrome isn't affected.","inLanguage":"en-US"},"inLanguage":"en-US"},{"@type":"Question","@id":"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#faq-question-1763371004444","position":5,"url":"https:\/\/larapush.com\/blog\/send-web-push-notifications-python\/#faq-question-1763371004444","name":"Where should I keep the VAPID private key?","answerCount":1,"acceptedAnswer":{"@type":"Answer","text":"On the server, outside the web root, in a secrets manager or an environment variable, with a backup. If you lose it, you can't send to existing subscribers, and anyone who gets it can sign messages as your server.","inLanguage":"en-US"},"inLanguage":"en-US"}]}},"_links":{"self":[{"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/posts\/3440"}],"collection":[{"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/users\/7"}],"replies":[{"embeddable":true,"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/comments?post=3440"}],"version-history":[{"count":1,"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/posts\/3440\/revisions"}],"predecessor-version":[{"id":3445,"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/posts\/3440\/revisions\/3445"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/media\/3450"}],"wp:attachment":[{"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/media?parent=3440"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/categories?post=3440"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/larapush.com\/blog\/wp-json\/wp\/v2\/tags?post=3440"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}