Back to Documentation

Python Integration

Send push notifications from Python using the requests library. Perfect for scripts, automation, Django/Flask backends, or data pipelines.

Installation

pip install requests

Basic Example

import requests

response = requests.post(
    'https://thenotification.app/api/sendNotification',
    headers={
        'app_key': 'YOUR_API_KEY',
        'Content-Type': 'application/json'
    },
    json={
        'title': 'New Message',
        'body': 'Check out this notification',
        'link': 'https://example.com/page',
        'image': 'https://picsum.photos/400/200'
    }
)

print(response.json())

Reusable Function

import requests
import os

def send_notification(title: str, body: str, link: str = None, image: str = None) -> dict:
    """Send a push notification via thenotification.app API."""

    payload = {
        'title': title,
        'body': body
    }

    if link:
        payload['link'] = link
    if image:
        payload['image'] = image

    response = requests.post(
        'https://thenotification.app/api/sendNotification',
        headers={
            'app_key': os.environ.get('NOTIFICATION_API_KEY'),
            'Content-Type': 'application/json'
        },
        json=payload
    )

    return response.json()

# Usage
result = send_notification(
    title='Deployment Complete',
    body='Your app has been deployed successfully!'
)
print(result)

Response

{
  "success": True,
  "message": "Notification sent to 1 device(s)",
  "devices_sent": 1,
  "failed_count": 0
}