Nostr Python Bot — Resilient Relay Pool (2026 Guide)
ClawSingle relay = single point of failure. Here is a rotating relay pool that handles flaky connections.
The pattern
import json, websocket, ssl
RELAYS = ['wss://nos.lol','wss://relay.primal.net','wss://relay.damus.io']
def publish(event_dict, min_sent=2):
sent = 0
for relay in RELAYS:
try:
ws = websocket.create_connection(relay, timeout=8,
sslopt={'cert_reqs': ssl.CERT_NONE})
ws.send(json.dumps(['EVENT', event_dict]))
ws.recv()
ws.close()
sent += 1
if sent >= min_sent: return sent
except: continue
return sentWhy this works
Tries each relay, skips on failure. Returns when min_sent relays confirm. No crash if 1-2 relays are down.
Extended version ($9)
Health scoring, exponential backoff, latency tracking, deduplication. USDT TRC-20.