Skip to main content

Official NotifyKit SDK for Python - Send notifications from your apps

Project description

NotifyKit Python SDK

Official NotifyKit SDK for Python. Send notifications from your apps with a simple, non-blocking API.

Features

  • Python 3.8+ support
  • Works with FastAPI, Flask, Django, and any Python app
  • Async support with notify_async() for async frameworks
  • Fire-and-forget - notifications are sent in background threads
  • Silent failures - logs errors but never crashes your app
  • Type hints included (PEP 561 compatible)

Installation

# pip
pip install notifykitdev

# uv
uv add notifykitdev

# poetry
poetry add notifykitdev

# pipenv
pipenv install notifykitdev

Quick Start

from notifykit import NotifyKit

# Initialize once at startup
NotifyKit.init("nsk_your_api_key")

# Send notifications anywhere in your app
NotifyKit.notify("User signed up!")

API Reference

NotifyKit.init(api_key, **options)

Initialize the SDK with your API key. Call this once at application startup.

# Simple initialization
NotifyKit.init("nsk_your_api_key")

# With options
NotifyKit.init(
    "nsk_your_api_key",
    base_url="https://api.notifykit.dev",  # optional, custom API URL
    timeout=10.0,  # optional, request timeout in seconds
    debug=True,  # optional, enable debug logging
)

NotifyKit.notify(message, **options)

Send a notification using a background thread. Returns immediately without blocking.

# Simple message
NotifyKit.notify("Hello world!")

# With topic for categorization
NotifyKit.notify("New order received", topic="orders")

# With idempotency key to prevent duplicates
NotifyKit.notify(
    "Welcome email sent",
    topic="onboarding",
    idempotency_key=f"welcome-{user_id}",
)

NotifyKit.notify_async(message, **options)

Send a notification using async/await. Use this in async frameworks like FastAPI.

await NotifyKit.notify_async("Hello from async!")

Options:

Option Type Description
topic str Categorize notifications for filtering
idempotency_key str Prevent duplicate notifications

NotifyKit.is_initialized()

Check if the SDK has been initialized.

if not NotifyKit.is_initialized():
    NotifyKit.init("nsk_your_api_key")

Framework Examples

FastAPI

from fastapi import FastAPI
from notifykit import NotifyKit
import os

app = FastAPI()

# Initialize at startup
@app.on_event("startup")
def startup():
    NotifyKit.init(os.environ["NOTIFYKIT_API_KEY"])

@app.post("/api/orders")
async def create_order(order: dict):
    # Create order logic...
    order_id = "12345"

    # Fire-and-forget async notification
    await NotifyKit.notify_async(
        f"New order #{order_id}",
        topic="orders",
    )

    return {"id": order_id}

Flask

from flask import Flask, request
from notifykit import NotifyKit
import os

app = Flask(__name__)

# Initialize at startup
NotifyKit.init(os.environ["NOTIFYKIT_API_KEY"])

@app.route("/api/signup", methods=["POST"])
def signup():
    email = request.json["email"]
    # Create user logic...

    # Fire-and-forget notification (uses background thread)
    NotifyKit.notify(
        f"New signup: {email}",
        topic="signups",
    )

    return {"success": True}

if __name__ == "__main__":
    app.run()

Django

# settings.py - Initialize at Django startup
import os
from notifykit import NotifyKit

NotifyKit.init(os.environ["NOTIFYKIT_API_KEY"])

# views.py
from django.http import JsonResponse
from notifykit import NotifyKit

def create_order(request):
    # Create order logic...
    order_id = "12345"

    # Fire-and-forget notification
    NotifyKit.notify(
        f"New order #{order_id}",
        topic="orders",
    )

    return JsonResponse({"id": order_id})

Django with Async Views

# views.py
from django.http import JsonResponse
from notifykit import NotifyKit

async def create_order_async(request):
    # Create order logic...
    order_id = "12345"

    # Async notification
    await NotifyKit.notify_async(
        f"New order #{order_id}",
        topic="orders",
    )

    return JsonResponse({"id": order_id})

Background Tasks (Celery, RQ, etc.)

# tasks.py
from celery import Celery
from notifykit import NotifyKit
import os

app = Celery("tasks")

# Initialize in worker
NotifyKit.init(os.environ["NOTIFYKIT_API_KEY"])

@app.task
def process_payment(payment_id: str):
    # Process payment logic...

    NotifyKit.notify(
        f"Payment {payment_id} processed",
        topic="payments",
    )

CLI Scripts

#!/usr/bin/env python3
import os
from notifykit import NotifyKit
import time

NotifyKit.init(os.environ["NOTIFYKIT_API_KEY"])

def main():
    # Your script logic...
    NotifyKit.notify("Script completed!", topic="scripts")

    # Give background thread time to send before exit
    time.sleep(1)

if __name__ == "__main__":
    main()

Error Handling

The SDK is designed to never throw errors or crash your app. All errors are logged but won't interrupt your code:

# This won't throw even if the API is down
NotifyKit.notify("Hello world!")

# Enable debug mode for more detailed logging
NotifyKit.init(
    "nsk_your_api_key",
    debug=True,
)

Type Hints

Full type hint support is included. The package is PEP 561 compatible with a py.typed marker.

from notifykit import NotifyKit

# IDE will show correct types and autocomplete
NotifyKit.init("nsk_your_api_key")
NotifyKit.notify("Hello!", topic="greetings")

License

MIT

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

notifykitdev-1.0.0.tar.gz (5.0 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

notifykitdev-1.0.0-py3-none-any.whl (6.2 kB view details)

Uploaded Python 3

File details

Details for the file notifykitdev-1.0.0.tar.gz.

File metadata

  • Download URL: notifykitdev-1.0.0.tar.gz
  • Upload date:
  • Size: 5.0 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for notifykitdev-1.0.0.tar.gz
Algorithm Hash digest
SHA256 2d1db38fa0d56410303f2d9d9a4b7d5671a97504178eca6414f3fed6b4a16919
MD5 f249411e402bf12089e3e9951367bce5
BLAKE2b-256 298a595da56964d9a72425d0b9de0e9027b7e41cd349002b0fe88f29d4a226f2

See more details on using hashes here.

File details

Details for the file notifykitdev-1.0.0-py3-none-any.whl.

File metadata

  • Download URL: notifykitdev-1.0.0-py3-none-any.whl
  • Upload date:
  • Size: 6.2 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.12.7

File hashes

Hashes for notifykitdev-1.0.0-py3-none-any.whl
Algorithm Hash digest
SHA256 a06f6740336ae18c40f6e9234bece38e0ac0995ff50e573012304dbce23975b1
MD5 6c591ca36198edda8ac4eeab1d1e6222
BLAKE2b-256 0f341ab994f72d6a4091229f8483c63d588cb31965ad52089f633165a8897f55

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page