Send push notifications from Python
This guide shows how to send push notifications from Python with PushFire. You call the PushFire REST API with the requests library from Django, Flask, FastAPI, a worker or a cron job. PushFire is the easiest lifecycle messaging platform for AI agents and vibe coders: push and email lifecycle campaigns, segments and workflows behind one small API.
A native Python SDK is coming soon. Until it ships, the REST API is the supported path, and every call below runs today. The full contract is in the API Reference and the OpenAPI spec.
Prerequisites
- A PushFire account and project. Create one at console.pushfire.app.
- Firebase credentials uploaded to the project, so PushFire can deliver push through FCM. See Create your first project.
- A Secret key (pf_sk_...) from Developers → API keys. Keep it on the server. See Public and Secret keys.
- Python 3.9 or later.
- For email: an active email connector (Resend or SMTP). See Connectors.
Warning: never ship a Secret key (pf_sk_) in a mobile app, browser bundle or no-code frontend. PushFire does not block a Secret key on a client, so the call works, but anyone can extract the key from your app and message all your users. Start workflows and send messages from your server, a Supabase Edge Function or your app builder's server function.
Install requests
Initialize the PushFire client in Python
Every endpoint lives under https://api.pushfire.app/functions/v1. Every request sends Authorization: Bearer <key> and a JSON body that wraps its fields in a data object. Put the key in an environment variable, not in code.
Register a device
Your mobile or web app gets an FCM token from Firebase Messaging. If the app sends that token to your Python backend, register it there. PushFire creates the device and an anonymous subscriber, and returns both IDs. Store them with your user record.
Send every device field. osVersion, appVersion, manufacturer, model and language may be null, but the keys must be present, or the API returns a 400.
PushFire rejects a second registration of the same FCM token. When the token rotates, update the existing device with PATCH update-device and its id instead.
Identify a subscriber
Log the subscriber in to replace the anonymous subscriber on that device with your own user. externalId is your user ID. Batch push and email target this value later.
To change profile fields later from the server, send a partial update. PushFire finds the subscriber by externalId, so you do not need the subscriber UUID here. Login ignores metadata; set it with this call.
Add, update and remove tags
Tags drive segments and workflow conditions. Create the tag in Audience → Tags first. The API takes the tag's UUID, not its name, and the subscriber's PushFire UUID. A value is a string, a number of 1 or more, or null.
Trigger a workflow from Python
Build the journey once in the visual workflow builder, then start it from code. A workflow targets PushFire subscriber UUIDs or segment UUIDs. Scheduled runs need scheduledFor as an ISO 8601 date-time.
Send a push notification from Python
Batch push sends one notification to each externalId in the list, with no workflow. data is an optional key-value payload your app receives with the notification. Use string values only: PushFire passes data to FCM, and FCM rejects numbers, booleans and nested objects.
A partial success returns HTTP 200 with both lists filled. If every recipient fails, the API returns HTTP 400 with the same shape, so pushfire() raises and err.body holds the lists.
Send an email from Python
Batch email needs an active connector. Copy the Connector ID and a Sender ID from Connectors → Resend (or SMTP). emailLayoutId is optional. The body must be HTML without scripts, iframes or on... event handlers. mergeData fills custom {{token}} placeholders.
Verify delivery
- Run send_push.py and check that result["success"] lists your test user.
- Open Developers → API Messages → Push Notifications in the console. Each API send shows its status: Pending, In progress, Completed, Retrying or Failed.
- Open Audience → Subscribers and search for user_123. Confirm the device, tags and profile fields.
- For email, check Developers → API Messages → Email Notifications.
Troubleshooting
- 401 "Missing or invalid token": the header is not Authorization: Bearer <key>, or the key was rotated or revoked.
- 403 "Client key cannot perform this action": you used a Public key (pf_pk_) for push, email or a workflow. Public keys can only manage devices, subscribers and tags. Use a Secret key.
- 403 "API key is missing required scope": a Restricted key lacks the scope for that endpoint. Create a key with the scope.
- 400 with "path": "data.osVersion": a device field is missing. Send the key with None.
- 400 "Device with FCM token already exists": the token is already registered. Update the stored device instead.
- Push shows Failed in API Messages with a Firebase error about data: a value in notification.data is not a string. Convert numbers and booleans to strings.
- 400 "Invalid tag ID": you sent the tag name. Send the tag UUID from the console.
- Push returns an error for a user: that externalId has no logged-in subscriber, or the subscriber has no device with push enabled.
- 400 on email with data.notification.connectorId: send connectorId and connectorSenderId. Older docs used emailSenderId, which the API no longer accepts.
FAQ
Is there an official PushFire Python SDK?
Not yet. A native Python SDK is planned and shows as coming soon in the SDK list. Today you call the PushFire REST API with requests or httpx. The API is small, eleven endpoints, and the helper in this guide covers all of them in about twenty lines of code.
Can I send push notifications from Django, Flask or FastAPI?
Yes. The helper is framework-free, so call it from a Django view, a Flask route, a FastAPI endpoint or a Celery task. For FastAPI or other async code, swap requests for httpx.AsyncClient with the same URL, header and JSON body. Keep the Secret key in your settings or environment.
Do I need Firebase to send push notifications with PushFire?
Yes for push. PushFire delivers push through Firebase Cloud Messaging, so you upload a Firebase service account to your project and your apps register FCM tokens. You do not call FCM from Python yourself. Email works without Firebase through a Resend or SMTP connector.
Which key should my Python backend use?
Use a Secret key (pf_sk_). It can send push, send email and start workflows. A Public key (pf_pk_) is for apps on user devices and can only register devices, identify subscribers and manage tags. For least privilege, create a Restricted key (pf_rk_) with only the scopes your service needs.
How do I target users who have not logged in?
Batch push and email target externalId, so they reach only identified subscribers. For anonymous devices, start a workflow with target.type set to Subscribers and the subscriber UUID from register-device, or target a segment.
Next steps
- Build the journey your code triggers: Workflows.
- Group users with Tags and Segments.
- Read every field in the API Reference.
- Let your coding agent do the wiring: PushFire AI agent skill.
- See every SDK and its status: PushFire SDKs and libraries.