Create notification in App using Python fastapi as backend
novu The open-source notification infrastructure for developers
assuming have python installed in your pc.
install fastapi and novu
pip install fastapi uvicorn novu
create main.py
from fastapi import FastAPI app = FastAPI() @app.get("/") async def root(): return {"message": "Hello World"} create novu.py from novu.api import EventApi class Novu: def __init__(self, api_key): self.event_api = EventApi("https://api.novu.co", api_key) def trigger(self, name, recipients, payload): return self.event_api.trigger(name, recipients, payload)
Run server
uvicorn main:app --reload
Open your browser at http://127.0.0.1:8000
You will see the JSON response as:
{"message": "Hello World"}
- after signup and login go to your dashboard and setting
- copy and paste to .env file
- Goto Workflows tab add In-App and create new workflow
- add content template example {{ content }}
- create main.py
@app.post("/notification" async def notification(): res = novu.Novu(settings.novu_apikey).trigger( "your workflows", "random_id_subsribe", "your content" ) return res.data
- Testing your notification
curl -X POST http://localhost:8000/notification
- See your result in Activity Feed
- Next we will integate to notification in frontend