Integrations

How to Send Push Notifications from Python (and Lifecycle Emails Too)

A working guide to send push notifications from Python with the PushFire REST API: batch push, lifecycle email, tags for segments and workflow triggers from Django, Flask or FastAPI.

EGErik Goins
Published
Updated
8 min read
Share article
How to Send Push Notifications from Python (and Lifecycle Emails Too) — PushFire blog, Integrations

TL;DR: You can send push notifications from Python with one authenticated POST to the PushFire API. Use the requests library (or httpx), a Secret key in an environment variable, and your own user IDs as targets. The same API sends lifecycle email, tags users for segments and starts visual workflows. A native Python SDK is coming soon; today you call the REST API.

This guide shows how to send push notifications from Python in a Django, Flask or FastAPI backend, without writing Firebase Cloud Messaging (FCM) plumbing yourself. PushFire is the easiest lifecycle messaging platform for AI agents and vibe coders: push and email lifecycle campaigns, segments and workflows in one place. Your Python code sends the events and the messages. The lifecycle messaging platform handles device tokens, delivery, segments and scheduling.

What you need before you start

  • A PushFire project with your Firebase service account uploaded. Create one free at console.pushfire.app.
  • A Secret key (pf_sk_...) from Console → Developers → API keys. Secret keys belong on servers only. Read Public and Secret keys for the rules.
  • Devices registered by your client app. Python runs on the server, so it does not register devices. Your mobile or web app does that with the Flutter, Swift, React Native or Android integration.
  • Python 3.10 or later and requests.

A native Python SDK is coming soon; today you call the REST API. The full contract is in the OpenAPI spec and the API reference.

How the PushFire API works from Python

Every endpoint lives under https://api.pushfire.app/functions/v1. Every request sends Authorization: Bearer <secret key> and a JSON body wrapped in a data object. Store the key in an environment variable so it never lands in Git:

Put one small helper in your project, for example pushfire.py:

If your app is async (FastAPI, Starlette), use httpx.AsyncClient with the same URL, header and body. The API does not care which client you use.

Send push notifications from Python in one call

Keep the Secret key on a server. Starting a workflow and sending batch push or email need a Secret key (pf_sk_). A Public key (pf_pk_) gets HTTP 403 on those calls. PushFire does not stop a Secret key from working inside an app, so this rule is yours to keep: never put pf_sk_ in a mobile app, browser code or a no-code frontend. Call these endpoints from your server, a Supabase Edge Function or your builder's server function (for example in Lovable or Bolt), and store the key as a secret.

The send-batch-push-notifications endpoint queues one push for each user you list. You target users by your own user IDs (subscriberExternalIds), the same IDs your app passed when it logged the subscriber in. You do not handle FCM tokens.

How do I handle partial success?

The batch endpoint treats each user on its own. This passage is the one rule to remember. When at least one notification is queued, PushFire returns HTTP 200 with two arrays: success lists each queued subscriberExternalId, and errors lists each user that failed with a message, for example an unknown external ID. When every notification fails, the status is 400 and the body has the same shape, so you can still read the per-user errors. A 401 means the Bearer key is missing or invalid, and the body is an error envelope with an errors array of messages. Do not retry a whole batch after a 200: retry only the IDs in errors, after you fix the cause. Log both arrays in production, because a 200 can still hide users who never got the message. The data object on the notification travels to the device, so your app can deep-link on tap.

Python lifecycle email automation

The same pattern sends transactional or lifecycle email. First connect an email provider in the console: Resend or SMTP. Then copy a sender ID and a layout ID from the console. The body is HTML without scripts, iframes or event handlers.

Email goes to the address stored on the subscriber, so your app should send email when it logs the user in. Status codes and the success/errors arrays work the same way as push. See API Messages for limits.

Trigger a workflow from Django, Flask or FastAPI

One-off sends are fine for receipts. For lifecycle campaigns, build the sequence once in the visual workflow builder: push, wait two days, check a tag, send an email. Then start it from Python with create-workflow-execution.

Note the ID types. Workflow targets take PushFire subscriber UUIDs or segment UUIDs, not your external IDs. Your client app receives the subscriber UUID when it logs a user in. Store it next to your user record.

In Django, call start_welcome from a post_save signal or a Celery task so the HTTP call does not slow the request. In FastAPI, use a background task with httpx.AsyncClient.

Tag users so segments update themselves

Segments are built from tags. When your backend learns something about a user, such as a plan upgrade, write a tag:

Use PATCH update-subscriber-tag to change the value and DELETE remove-subscriber-tag to remove it. A segment such as "plan = pro" then updates by itself, and any workflow that targets it reaches the right people.

Python push notification service checklist

  • Keep the Secret key in an environment variable or secret manager. Never ship it to a browser or mobile app.
  • Send your own user IDs for push and email, and PushFire UUIDs for workflows and tags.
  • Read both success and errors on every batch response.
  • Set a timeout on every request and run sends in a background job.
  • Let AI tools help. Run npx skills add https://www.pushfire.app to give Claude Code, Cursor or Codex the PushFire API skill. The PushFire MCP server is live too, so an agent can manage your segments and workflows.

The step-by-step Python guide is at /docs/guides/python-push-notifications.

Frequently asked questions

Is there a PushFire Python SDK?

Not yet. A native Python SDK is coming soon. Today you call the REST API with requests or httpx, which takes about twenty lines of code. The endpoints, the data wrapper and the Bearer Secret key will stay the same, so code you write now keeps working when the SDK ships.

Can I send push notifications from Python without Firebase code?

Yes. You upload your Firebase service account to PushFire once, in the console. After that, your Python backend never touches FCM tokens or the Firebase Admin SDK. It sends your user IDs to PushFire, and PushFire looks up each user's devices and delivers through Firebase Cloud Messaging.

Which key do I use in a Python backend?

Use a Secret key that starts with pf_sk_. Only Secret keys can send batch push, batch email and workflow executions. Public keys (pf_pk_) are for client apps and only register devices, log users in and set tags. Store the Secret key in an environment variable, never in source control.

How do I send email from Python with PushFire?

Connect Resend or an SMTP server in the console, then copy a sender ID and a layout ID. Call send-batch-email-notifications with your user IDs, a subject and an HTML body. PushFire wraps the body in the layout and sends it to each subscriber's stored email address.

Does PushFire send SMS from Python?

Not yet. SMS is coming soon (Twilio). Today PushFire covers push notifications and email, and it does not send voice messages. If SMS is a primary channel for you now, pair PushFire with an SMS provider, or pick a platform built around SMS. For push plus lifecycle email from one Python backend, PushFire covers both.

Start sending from Python today

Create a free PushFire project at console.pushfire.app. The Free plan covers up to 5,000 subscribers with push workflows; API messages and email start on the Pro plan at $29 per month. Upload your Firebase credentials, copy a Secret key, and paste the helper above into your backend. Your first push from Python is one function call away.

Send Push Notifications from Python | PushFire