Pillar B — Build guides
Published 2026-06-05 · Updated 2026-06-19 · By Avinash Chandan, Founder, Navamsha
Build a Kundli API Backend in Python (FastAPI) with Navamsha
A Kundli API backend accepts birth details from your app, calls Navamsha's calculation engine server-side, and returns structured chart JSON. FastAPI is a strong fit: async httpx calls, Pydantic request models, and OpenAPI docs for your own mobile clients.
Project setup
- Python 3.11+ with FastAPI and httpx.
- NAVAMSHA_API_KEY in environment — never expose in mobile or browser bundles.
- Optional: pydantic-settings for typed config.
FastAPI route — Kundali proxy
from fastapi import FastAPI, HTTPException
import httpx, os
app = FastAPI()
NAVAMSHA = "https://api.navamsha.in"
@app.get("/v1/kundli")
async def kundli(date: str, time: str, latitude: float, longitude: float):
async with httpx.AsyncClient(timeout=30.0) as client:
r = await client.get(
f"{NAVAMSHA}/api/v1/kundali/basic",
headers={"X-API-Key": os.environ["NAVAMSHA_API_KEY"]},
params={"date": date, "time": time, "latitude": latitude, "longitude": longitude},
)
if r.status_code != 200:
raise HTTPException(status_code=r.status_code, detail=r.text)
return r.json()Production tips
- Cache responses by birth hash (date + time + lat/lng rounded) to stay within free tier limits.
- Surface meta.ayanamsa and meta.engine in your API response for client-side audit labels.
- Add rate limiting per user session — Navamsha enforces 10 req/sec on the free tier.
FAQ
Should I call Navamsha from the browser?
No — keep the API key on your FastAPI server. Mobile and web clients call your backend, not api.navamsha.in directly.
Does FastAPI need async for Navamsha?
Async httpx is recommended for concurrent chart requests under load, but sync httpx works for MVPs.