Skip to main content

Python SDK for notif.sh event hub

Project description

notifsh

Python SDK for notif.sh event hub.

Installation

pip install notifsh

Quick Start

import asyncio
from notifsh import Notif

async def main():
    # Uses NOTIF_API_KEY env var by default
    async with Notif() as n:
        # Emit an event
        await n.emit('leads.new', {'name': 'John', 'email': 'john@example.com'})

        # Subscribe to events (auto-ack by default)
        async for event in n.subscribe('leads.*'):
            print(f"Received: {event.topic} - {event.data}")

asyncio.run(main())

Configuration

from notifsh import Notif

# Using environment variable (recommended)
# Set NOTIF_API_KEY=nsh_your_api_key
client = Notif()

# Or pass API key directly
client = Notif(api_key='nsh_your_api_key')

# With custom server
client = Notif(server='http://localhost:8080')

Emitting Events

async with Notif() as n:
    result = await n.emit('orders.created', {
        'order_id': '12345',
        'amount': 99.99,
    })
    print(f"Event ID: {result.id}")

Subscribing to Events

async with Notif() as n:
    # Subscribe to multiple topics
    async for event in n.subscribe('orders.*', 'payments.*'):
        print(f"{event.topic}: {event.data}")

    # Manual acknowledgment
    async for event in n.subscribe('orders.*', auto_ack=False):
        try:
            process(event.data)
            await event.ack()
        except Exception:
            await event.nack('5m')  # Retry in 5 minutes

    # Consumer groups (load-balanced)
    async for event in n.subscribe('jobs.*', group='worker-pool'):
        await process_job(event.data)

    # Start from beginning
    async for event in n.subscribe('orders.*', from_='beginning'):
        print(event.data)

Error Handling

from notifsh import Notif, AuthError, APIError, ConnectionError

try:
    async with Notif() as n:
        await n.emit('test', {'data': 'value'})
except AuthError:
    print("Invalid API key")
except APIError as e:
    print(f"API error ({e.status_code}): {e}")
except ConnectionError as e:
    print(f"Connection failed: {e}")

Requirements

  • Python 3.11+
  • httpx
  • websockets

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

notifsh-0.1.0.tar.gz (6.1 kB view details)

Uploaded Source

Built Distribution

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

notifsh-0.1.0-py3-none-any.whl (7.7 kB view details)

Uploaded Python 3

File details

Details for the file notifsh-0.1.0.tar.gz.

File metadata

  • Download URL: notifsh-0.1.0.tar.gz
  • Upload date:
  • Size: 6.1 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.8

File hashes

Hashes for notifsh-0.1.0.tar.gz
Algorithm Hash digest
SHA256 6b147da58bcc43c2105e6240a5cb2b0d2a9a8cc479389b38897981e90a04c522
MD5 95a331f012e3abea9540fd9e3e8cbad2
BLAKE2b-256 ad24e72d31d555d8e3dc75fbf320e5d0db0118c87e76328726a7b7ea432b7bff

See more details on using hashes here.

File details

Details for the file notifsh-0.1.0-py3-none-any.whl.

File metadata

  • Download URL: notifsh-0.1.0-py3-none-any.whl
  • Upload date:
  • Size: 7.7 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: twine/6.2.0 CPython/3.11.8

File hashes

Hashes for notifsh-0.1.0-py3-none-any.whl
Algorithm Hash digest
SHA256 6094e4c11274b4467debf558604738e96ad658410dac7746ec49a5cf5495b1d2
MD5 029bd86ab8ae39031c9584b1cadaaa71
BLAKE2b-256 5462a0865464814b08d7802e26eff6a0cec6e42316169924e58db92a6e8d40f4

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