PYTHON TUTORIAL
Vedic Astrology API Python Guide
Complete Python tutorial for integrating Vedic astrology calculations. Birth charts, dashas, doshas, and AI chatbot with production-ready code.
January 7, 2026
-
20 min read
Installation
# Install the official Vedika Python SDK
pip install vedika-sdk
Quick Start
from vedika import VedikaClient
# Initialize client
client = VedikaClient(api_key='YOUR_API_KEY')
# Generate birth chart (V2 route; the response payload is under "data")
result = client.get_birth_chart_v2('birth-chart', {
'datetime': '1990-05-15T14:30:00',
'latitude': 28.6139,
'longitude': 77.2090,
'timezone': '+05:30'
})
chart = result['data']
print(f"Ascendant: {chart['ascendant']['sign']}")
print(f"Moon Sign: {chart['moonSign']}")
print(f"Sun Sign: {chart['sunSign']}")
# Access all planets
for planet in chart['planets']:
print(f"{planet['name']}: {planet['sign']} at {planet['degree']}°")
Birth Chart Analysis
from vedika import VedikaClient
client = VedikaClient(api_key='YOUR_API_KEY')
def analyze_birth_chart(dob, tob, place_lat, place_lng, timezone='+05:30'):
"""Generate and analyze a complete birth chart."""
birth_details = {
'datetime': f"{dob}T{tob}",
'latitude': place_lat,
'longitude': place_lng,
'timezone': timezone
}
# Get full birth chart (Lahiri ayanamsa)
chart = client.get_birth_chart_v2('birth-chart', birth_details)['data']
analysis = {
'ascendant': chart['ascendant']['sign'],
'planets': {},
'yogas': [],
'doshas': []
}
# Analyze each planet
for planet in chart['planets']:
analysis['planets'][planet['name']] = {
'sign': planet['sign'],
'house': planet['house'],
'nakshatra': planet['nakshatra']['name'],
'degree': planet['degree'],
'retrograde': planet['isRetrograde']
}
# Yogas (Jaimini rajayogas) and doshas (Mangal, Kaal Sarp, Pitru)
# each have their own route, so they are fetched separately
analysis['yogas'] = client.detect_yogas(birth_details).raw
analysis['doshas'] = client.analyze_doshas(birth_details).raw
return analysis
# Example usage
result = analyze_birth_chart(
dob='1990-05-15',
tob='14:30:00',
place_lat=28.6139,
place_lng=77.2090
)
print(f"Moon in {result['planets']['Moon']['sign']}")
print(f"Yogas: {result['yogas']}")
print(f"Doshas: {result['doshas']}")
Dasha Calculations
from vedika import VedikaClient
client = VedikaClient(api_key='YOUR_API_KEY')
def get_dasha_timeline(birth_datetime, lat, lng, timezone='+05:30'):
"""Get the Vimshottari dasha timeline."""
result = client.get_vimshottari_dasha({
'datetime': birth_datetime,
'latitude': lat,
'longitude': lng,
'timezone': timezone
})
return result['data']
# Get dasha for someone born in 1990
dasha_info = get_dasha_timeline(
'1990-05-15T14:30:00',
28.6139,
77.2090
)
# Mahadashas, antardashas and the current period, as returned by the API
print(dasha_info)
Async Support
import asyncio
from vedika import VedikaClient
client = VedikaClient(api_key='YOUR_API_KEY')
async def main():
# Run several requests concurrently in worker threads
chart, panchang = await asyncio.gather(
asyncio.to_thread(
client.request, 'POST', '/v2/astrology/birth-chart',
json={'datetime': '1990-05-15T14:30:00', 'latitude': 28.6139, 'longitude': 77.2090, 'timezone': '+05:30'},
),
asyncio.to_thread(client.get_panchang, date='2026-01-15', latitude=28.6139, longitude=77.2090),
)
print(chart)
print(panchang)
asyncio.run(main())
AI Chatbot Integration
import json
from vedika import VedikaClient
client = VedikaClient(api_key='YOUR_API_KEY')
def ask_vedika(question, birth_details):
"""Ask Vedika AI about astrology."""
response = client.ask_question(
question=question,
birth_details=birth_details
)
return response.answer
# Example: Natural language astrology query
answer = ask_vedika(
question="What career paths suit me based on my birth chart?",
birth_details={
'datetime': '1990-05-15T14:30:00',
'latitude': 28.6139,
'longitude': 77.2090,
'timezone': '+05:30'
}
)
print(answer)
# Streaming responses: each chunk is one server-sent event payload (a JSON
# string); the answer text is in the "response" field of the "completed" event
for chunk in client.ask_question_stream(
question="Tell me about my upcoming Jupiter Mahadasha",
birth_details={
'datetime': '1990-05-15T14:30:00',
'latitude': 28.6139,
'longitude': 77.2090,
'timezone': '+05:30'
}
):
try:
event = json.loads(chunk)
except ValueError:
continue
if isinstance(event, dict) and event.get('response'):
print(event['response'], end='', flush=True)
Flask Integration
from flask import Flask, request, jsonify
from vedika import VedikaClient
app = Flask(__name__)
vedika = VedikaClient(api_key='YOUR_API_KEY')
@app.route('/api/horoscope', methods=['POST'])
def get_horoscope():
data = request.json
chart = vedika.get_birth_chart_v2('birth-chart', {
'datetime': data['datetime'],
'latitude': data['latitude'],
'longitude': data['longitude'],
'timezone': data.get('timezone', '+05:30')
})['data']
return jsonify({
'sun_sign': chart['sunSign'],
'moon_sign': chart['moonSign'],
'ascendant': chart['ascendant']['sign'],
'planets': [
{'name': p['name'], 'sign': p['sign'], 'house': p['house']}
for p in chart['planets']
]
})
@app.route('/api/match', methods=['POST'])
def match_kundli():
data = request.json
match = vedika.get_guna_milan(
male=data['male'],
female=data['female']
)['data']
return jsonify({
'score': match['total_points'],
'out_of': match['maximum_points'],
'percentage': match['percentage'],
'recommendation': match['recommendation']
})
if __name__ == '__main__':
app.run(debug=True)
Pandas Integration
import pandas as pd
from vedika import VedikaClient
client = VedikaClient(api_key='YOUR_API_KEY')
def birth_chart(datetime, lat, lng, timezone='+05:30'):
return client.get_birth_chart_v2('birth-chart', {
'datetime': datetime,
'latitude': lat,
'longitude': lng,
'timezone': timezone
})['data']
# Convert birth chart to DataFrame
chart = birth_chart('1990-05-15T14:30:00', 28.6139, 77.2090)
planets_df = pd.DataFrame([
{
'planet': p['name'],
'sign': p['sign'],
'degree': p['degree'],
'house': p['house'],
'nakshatra': p['nakshatra']['name'],
'retrograde': p['isRetrograde']
}
for p in chart['planets']
])
print(planets_df)
# Analyze multiple charts
birth_data = [
{'datetime': '1990-05-15T14:30:00', 'lat': 28.61, 'lng': 77.21},
{'datetime': '1992-08-20T09:15:00', 'lat': 19.07, 'lng': 72.87},
{'datetime': '1988-12-10T18:45:00', 'lat': 13.08, 'lng': 80.27},
]
charts = [birth_chart(d['datetime'], d['lat'], d['lng']) for d in birth_data]
analysis_df = pd.DataFrame([
{
'moon_sign': c['moonSign'],
'sun_sign': c['sunSign'],
'ascendant': c['ascendant']['sign'],
'moon_nakshatra': c['nakshatra']
}
for c in charts
])
print(analysis_df.describe())
Start Building with Python
The Vedika Python SDK provides type hints, async support, and comprehensive documentation. Install with pip and start building in minutes.