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
Release history Release notifications | RSS feed
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.2.1.tar.gz
(7.4 kB
view details)
Built Distribution
Filter files by name, interpreter, ABI, and platform.
If you're not sure about the file name format, learn more about wheel file names.
Copy a direct link to the current filters
File details
Details for the file notifsh-0.2.1.tar.gz.
File metadata
- Download URL: notifsh-0.2.1.tar.gz
- Upload date:
- Size: 7.4 kB
- Tags: Source
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
6ef0f7088fc830d4899cae4572ec19e2c62be9e1ffb18cc45aba5251152ca1cb
|
|
| MD5 |
2d176cf8c4a04bbad548b27adb07bc55
|
|
| BLAKE2b-256 |
16736391825da079bf934715810e37ddd1184bb64e23e3323a0d548c1fd8a871
|
File details
Details for the file notifsh-0.2.1-py3-none-any.whl.
File metadata
- Download URL: notifsh-0.2.1-py3-none-any.whl
- Upload date:
- Size: 9.1 kB
- Tags: Python 3
- Uploaded using Trusted Publishing? No
- Uploaded via: twine/6.2.0 CPython/3.11.8
File hashes
| Algorithm | Hash digest | |
|---|---|---|
| SHA256 |
8b22726959d6046cffa6e50addab5f49ce718c0de70edad79536c2233c6f5fea
|
|
| MD5 |
4adab5d44f2f22d47464568cccc72ca0
|
|
| BLAKE2b-256 |
6273434f346df3af35bbc811f5745f3216c36dba756f57ce43dca2db4803eaa1
|