Python SDK
The norq Python package provides a client for sending and linting notification templates from Python applications.
Install
pip install norqThe package includes the norq binary for your platform (bundled in the wheel, same pattern as ruff).
Quick start
from norq import Norq
notif = Norq()
# Send
result = notif.send("transactional/order-shipped",
to={"email": "gaurav@example.com"},
data={"user": {"first_name": "Gaurav"}, "order": {"id": "ORD-123"}},
)Constructor
notif = Norq(
config="./norq.config.yaml", # config file path
binary_path="/usr/local/bin/norq", # explicit binary path
cwd="/path/to/project", # working directory
logger=my_logger, # structured logger
recipient_resolver=my_resolver, # user ID -> Recipient
)API
send(notification, *, to, data=None, sample=None, channels=None, dry_run=False)
result = notif.send("transactional/welcome",
to={"email": "user@example.com"},
data={"user": {"first_name": "Gaurav"}},
channels=["email"],
dry_run=False,
)
for r in result.results:
print(f"{r.channel}: {'OK' if r.success else r.error}")
for s in result.skipped:
print(f"Skipped {s.channel}: {s.reason}")lint(notification=None)
results = notif.lint() # all
results = notif.lint("transactional/welcome") # one
for result in results:
for diag in result.diagnostics:
print(f"{diag.severity}: {diag.message} [{diag.rule}]")Recipient
from norq.types import Recipient
recipient = Recipient(
email="user@example.com",
phone="+1234567890",
)
# Or pass a dict:
result = notif.send("transactional/welcome", to={"email": "user@example.com"}, data={...})RecipientResolver
class MyResolver:
def resolve(self, user_id: str) -> Recipient:
user = db.users.get(user_id)
return Recipient(email=user.email, phone=user.phone)
notif = Norq(recipient_resolver=MyResolver())
notif.send("transactional/welcome", to="user-123", data={...})Error handling
from norq.binary import NorqError
try:
notif.send("transactional/welcome", to="user-123", data={...})
except NorqError as e:
print(f"Norq error: {e}")Codegen
norq codegen --lang python --out src/generated/norq_types.pyGenerates typed dataclasses for each notification's data shape.