Integrations
Python

Python

Send events from any Python application using the built-in urllib or the popular requests library.

Using requests

import os
import requests
 
def send_alert(event: str, title: str, body: str = "", priority: str = "NORMAL") -> None:
    resp = requests.post(
        "https://api.flowalert.io/v1/events",
        headers={"X-Api-Key": os.environ["FLOWALERT_API_KEY"]},
        json={"event": event, "title": title, "body": body, "priority": priority},
        timeout=5,
    )
    resp.raise_for_status()
 
# Usage
send_alert("booking.created", "New Booking — John Smith", "Sunset Cruise · 4 guests")
send_alert("payment.failed", "Payment failed", "Order #5512 — card declined", "HIGH")

Using urllib (no dependencies)

import json
import os
import urllib.request
 
def send_alert(event: str, title: str, body: str = "") -> None:
    payload = json.dumps({"event": event, "title": title, "body": body, "priority": "NORMAL"}).encode()
    req = urllib.request.Request(
        "https://api.flowalert.io/v1/events",
        data=payload,
        headers={
            "Content-Type": "application/json",
            "X-Api-Key": os.environ["FLOWALERT_API_KEY"],
        },
        method="POST",
    )
    with urllib.request.urlopen(req, timeout=5) as resp:
        return json.loads(resp.read())

Django / Flask example

import os
import requests
from django.db.models.signals import post_save
from django.dispatch import receiver
from .models import Booking
 
@receiver(post_save, sender=Booking)
def notify_flowalert(sender, instance, created, **kwargs):
    if not created:
        return
    try:
        requests.post(
            "https://api.flowalert.io/v1/events",
            headers={"X-Api-Key": os.environ["FLOWALERT_API_KEY"]},
            json={
                "event": "booking.created",
                "title": f"New Booking — {instance.customer_name}",
                "body": f"{instance.tour} · {instance.guests} guests",
                "priority": "NORMAL",
                "data": {"booking_id": str(instance.id)},
            },
            timeout=3,
        )
    except requests.RequestException as e:
        logger.error(f"FlowAlert notify failed: {e}")
💡

Use timeout on every request so a FlowAlert outage never blocks your application.