Skip to main content
All Integrations
Python & Data Science Guide

Python Integration
for Four Pillars Calculations

Integrate structured BaZi charts into Python AI pipelines, LangChain chains, FastAPI backends, and Jupyter data analysis workflows.

Production Ready via REST: The REST endpoint accepts standard JSON payloads and can be called from Python using httpx, requests, or aiohttp today. The official PyPI client is currently in Beta preview.

1. Production Standard: HTTPX / Requests

Lightweight, clean, and compatible with both synchronous scripts and asynchronous event loops:

import httpx
import os

url = "https://api.baziapi.pro/api/v2/bazi/calculate"
headers = {
    "x-api-key": os.getenv("BAZI_API_KEY"),
    "Content-Type": "application/json"
}
payload = {
    "birthDate": "1990-11-04",
    "birthTime": "15:20",
    "gender": "female",
    "timezone": "America/New_York",
    "language": "en"
}

with httpx.Client() as client:
    response = client.post(url, headers=headers, json=payload)
    response.raise_for_status()
    data = response.json()["data"]

print("Day Master:", data["dayMaster"])
print("Pillars:", data["pillars"])

2. Async Python Client

Developer Beta

Typed Pydantic v2 models for FastAPI and LangChain agents:

$ pip install baziapi # Beta preview
from bazi import AsyncBaziClient  # Official package
import asyncio

async def main():
    client = AsyncBaziClient(api_key="bazi_live_your_key")
    
    chart = await client.calculate(
        birth_date="1990-11-04",
        birth_time="15:20",
        gender="female",
        timezone="America/New_York"
    )
    
    print("Dominant Element:", chart.traditional_interpretations.strongest_element)
    print("Year Pillar:", chart.four_pillars.year_pillar)

asyncio.run(main())

Explore Python SDK Reference

View full model definitions, parameters, and error handling patterns.