Back to Docs

Examples

Real-world code examples for common use cases.

Daily Panchang Widget

Display today's Tithi, Nakshatra, and auspicious timings on your website.

javascript
const res = await fetch(
  "https://vedic-astrology-production-a045.up.railway.app/api/v1/calculate/panchang",
  {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "X-API-Key": process.env.VEDASTRO_API_KEY
    },
    body: JSON.stringify({
      date: new Date().toISOString().split("T")[0],
      location: "Mumbai, India"
    })
  }
);

const { payload } = await res.json();
// payload.tithi    → "Ekadashi"
// payload.nakshatra → "Pushya"
// payload.yoga     → "Siddha"

Birth Chart for User Profile

Generate a Kundali / birth chart when a user enters their birth details.

python
import requests

def get_kundali(name, dob, tob, place):
    response = requests.post(
        "https://vedic-astrology-production-a045.up.railway.app/api/v1/calculate/chart",
        headers={"X-API-Key": os.environ["VEDASTRO_API_KEY"]},
        json={
            "name": name,
            "date": dob,   # "YYYY-MM-DD"
            "time": tob,   # "HH:MM"
            "location": place
        }
    )
    return response.json()["payload"]

kundali = get_kundali("Priya", "1995-03-22", "14:45", "Chennai, India")
print(f"Ascendant: {kundali['ascendant']}")
print(f"Moon Sign: {kundali['moonSign']}")

Muhurta Finder

Find auspicious timing for events like weddings or business launches.

python
# Check if a date/time is auspicious for a specific activity
import requests

def check_muhurta(date, time, location, activity="marriage"):
    res = requests.post(
        "https://vedic-astrology-production-a045.up.railway.app/api/v1/calculate/muhurta",
        headers={"X-API-Key": os.environ["VEDASTRO_API_KEY"]},
        json={
            "date": date,
            "time": time,
            "location": location,
            "activity": activity
        }
    )
    data = res.json()["payload"]
    return {
        "is_auspicious": data["isAuspicious"],
        "score": data["score"],
        "notes": data["notes"]
    }

Current Dasa Period

Show a user's current Vimshottari Dasa / Bhukti / Antara period.

javascript
const response = await fetch(
  "https://vedic-astrology-production-a045.up.railway.app/api/v1/calculate/dasa",
  {
    method: "POST",
    headers: {
      "Content-Type": "application/json",
      "X-API-Key": process.env.VEDASTRO_API_KEY
    },
    body: JSON.stringify({
      name: user.name,
      date: user.birthDate,
      time: user.birthTime,
      location: user.birthPlace
    })
  }
);

const { payload } = await response.json();
const current = payload.periods.find(p => p.isCurrent);
console.log(`Running: ${current.mahadasa} / ${current.antardasa}`);
console.log(`Ends: ${current.endDate}`);

Try these live

All examples can be tested interactively in the API Playground — no code required.