← Recipes

Render a North or South Indian chart from one API call

Both Indian chart styles draw the same twelve placements. The only difference is what stays fixed on the page - signs in the South, houses in the North - and the response already gives you both numbers.

You build
A South Indian 4x4 grid and North Indian diamond labels from one birth-chart response
Code
Node.js, Python - no SDK, runnable as shown

Updated

What the response gives you

POST /v1/charts/birth returns the ascendant (lagna) and nine planets. Each planet carries both a sign and a house; those two fields are all either chart style needs. Excerpt for the sample birth (24 Apr 1973, 17:25 IST, Mumbai):

json
{
  "ascendant": {
    "sign": "Virgo",
    "degree": 19.759582224440123
  },
  "planets": [
    {
      "name": "Sun",
      "sign": "Aries",
      "house": 8,
      "degree_in_sign": 10.67081886993168,
      "nakshatra": "Ashwini",
      "nakshatra_pada": 4,
      "retrograde": false
    },
    {
      "name": "Moon",
      "sign": "Sagittarius",
      "house": 4,
      "degree_in_sign": 26.789351625095037,
      "nakshatra": "Uttara Ashadha",
      "nakshatra_pada": 1,
      "retrograde": false
    },
    "… 7 more"
  ],
  "meta": {
    "ayanamsa": "lahiri",
    "house_system": "whole_sign",
    "engine_version": "1.2.1"
  }
}

meta.house_system is whole_sign: house 1 is the whole ascendant sign, house 2 the next sign, and so on. So house is always the sign's distance from the lagna plus one - you never have to compute house cusps for an Indian chart, and the North style can place planets by house directly.

South Indian: signs fixed, ascendant marked

In the South Indian layout the twelve signs occupy fixed cells around a 4x4 grid, Pisces top-left and clockwise from there; the middle four cells are empty or hold a title. Rendering is a lookup by sign, plus an Asc marker in the lagna's cell. The program below prints the grid as text so the mapping is visible; in a real UI each cell is a div in a CSS grid or a rect in an SVG.

south-indian.mjs

Node.js
// south-indian.mjs - node south-indian.mjs (Node 18+, no dependencies)
const API = process.env.ASTRONODE_API_URL ?? "https://api.astronode.dev";
const KEY = process.env.ASTRONODE_API_KEY; // server-side only

const birth = { date: "1973-04-24", time: "17:25:00", tz_offset_minutes: 330, lat: 19.076, lng: 72.8777 };

const res = await fetch(`${API}/v1/charts/birth`, {
  method: "POST",
  headers: { authorization: `Bearer ${KEY}`, "content-type": "application/json" },
  body: JSON.stringify(birth),
});
if (!res.ok) throw new Error(`${res.status} ${await res.text()}`);
const { data } = await res.json();

// South Indian layout: signs never move. Pisces is top-left, then clockwise.
const GRID = [
  ["Pisces", "Aries", "Taurus", "Gemini"],
  ["Aquarius", null, null, "Cancer"],
  ["Capricorn", null, null, "Leo"],
  ["Sagittarius", "Scorpio", "Libra", "Virgo"],
];
const ABBR = { Sun: "Su", Moon: "Mo", Mars: "Ma", Mercury: "Me", Jupiter: "Ju", Venus: "Ve", Saturn: "Sa", Rahu: "Ra", Ketu: "Ke" };

const cell = (sign) => {
  if (sign === null) return "";
  const parts = data.planets
    .filter((p) => p.sign === sign)
    .map((p) => ABBR[p.name] + (p.retrograde ? "(R)" : ""));
  if (data.ascendant.sign === sign) parts.unshift("Asc");
  return parts.join(" ");
};

const W = 14;
const line = "+" + ("-".repeat(W) + "+").repeat(4);
console.log(line);
for (const row of GRID) {
  console.log("|" + row.map((s) => (s ? s.slice(0, 3) : "").padEnd(W)).join("|") + "|");
  console.log("|" + row.map((s) => cell(s).padEnd(W)).join("|") + "|");
  console.log(line);
}

Output:

text
+--------------+--------------+--------------+--------------+
|Pis           |Ari           |Tau           |Gem           |
|Me            |Su Ve         |Sa            |Ke(R)         |
+--------------+--------------+--------------+--------------+
|Aqu           |              |              |Can           |
|              |              |              |              |
+--------------+--------------+--------------+--------------+
|Cap           |              |              |Leo           |
|Ma Ju         |              |              |              |
+--------------+--------------+--------------+--------------+
|Sag           |Sco           |Lib           |Vir           |
|Mo Ra(R)      |              |              |Asc           |
+--------------+--------------+--------------+--------------+

North Indian: houses fixed, sign numbers rotate

The North Indian diamond never moves its houses: house 1 is the top-centre diamond and the rest run counter-clockwise. What changes per chart is the sign number printed in each house (1 = Aries ... 12 = Pisces), starting from the lagna's sign. With a Virgo lagna, house 1 shows 6 and house 8 shows 1. Draw the diamond lines once as static SVG and position only the labels:

north_indian.py

Python 3.9+
# north_indian.py - python3 north_indian.py (3.9+, standard library only)
import json, os, urllib.request

API = os.environ.get("ASTRONODE_API_URL", "https://api.astronode.dev")
KEY = os.environ["ASTRONODE_API_KEY"]

SIGNS = ["Aries", "Taurus", "Gemini", "Cancer", "Leo", "Virgo",
         "Libra", "Scorpio", "Sagittarius", "Capricorn", "Aquarius", "Pisces"]

# Centre of each house's cell on a 400x400 North Indian diamond (house 1 = top centre,
# then counter-clockwise). Your SVG draws the lines once; only the labels change.
CENTRES = {1: (200, 100), 2: (100, 45), 3: (45, 100), 4: (100, 200), 5: (45, 300),
           6: (100, 355), 7: (200, 300), 8: (300, 355), 9: (355, 300), 10: (300, 200),
           11: (355, 100), 12: (300, 45)}

birth = {"date": "1973-04-24", "time": "17:25:00", "tz_offset_minutes": 330,
         "lat": 19.076, "lng": 72.8777}
req = urllib.request.Request(
    API + "/v1/charts/birth", data=json.dumps(birth).encode(), method="POST",
    headers={"Authorization": "Bearer " + KEY, "Content-Type": "application/json"})
with urllib.request.urlopen(req) as r:
    chart = json.load(r)["data"]

lagna = SIGNS.index(chart["ascendant"]["sign"])
for house in range(1, 13):
    sign_no = (lagna + house - 1) % 12 + 1          # the number printed in the cell
    planets = [p["name"][:2] + ("(R)" if p["retrograde"] else "")
               for p in chart["planets"] if p["house"] == house]
    x, y = CENTRES[house]
    print(f"house {house:>2}  sign {sign_no:>2}  at ({x},{y})  {' '.join(planets)}")

Output:

text
house  1  sign  6  at (200,100)
house  2  sign  7  at (100,45)
house  3  sign  8  at (45,100)
house  4  sign  9  at (100,200)  Mo Ra(R)
house  5  sign 10  at (45,300)  Ma Ju
house  6  sign 11  at (100,355)
house  7  sign 12  at (200,300)  Me
house  8  sign  1  at (300,355)  Su Ve
house  9  sign  2  at (355,300)  Sa
house 10  sign  3  at (300,200)  Ke(R)
house 11  sign  4  at (355,100)
house 12  sign  5  at (300,45)

Both renderings agree, as they must: the Moon and Rahu sit in Sagittarius, which is house 4 from a Virgo lagna; Mercury in Pisces is house 7.

Details that trip up a first renderer

  • Rahu and Ketu are always `retrograde: true`. The engine uses the mean lunar node, which only moves backwards. Most chart styles omit the (R) for the nodes; filter on name if yours does.
  • Abbreviations collide if you are careless. Ma/Me/Mo and Sa/Su are the traditional two-letter forms; do not derive them from the first letter alone.
  • Several planets per cell is normal. Two or three is common; the sample has two cells with two each. Size cells for four labels, or stack them in a column with a smaller font.
  • Degrees are per sign. degree_in_sign is 0-30 within sign. To show 26°47' write Math.floor(d) and Math.round((d % 1) * 60) minutes - and roll 60' over to the next degree.
  • Divisional charts render the same way. POST /v1/charts/varga with division: 9 returns ascendant_sign and per-planet sign and house, so the same two functions draw the navamsa.

Charts differing from another app by a whole sign is almost always the birth time zone, not the renderer - see ascendant off by a sign.

Questions

What do I end up with?
A South Indian 4x4 grid and North Indian diamond labels from one birth-chart response. The code is in Node.js and Python.
Which endpoints does this recipe call, and in what order?
2 endpoints, in this order: Birth Chart (Kundli) (POST /v1/charts/birth), then Divisional Charts (Navamsa, D1-D60) (POST /v1/charts/varga).