Python quickstart

You need Python 3.8 or later. The client has no dependencies.

1. Install

The client is not on PyPI yet, so install this release from our site:

pip install https://developers.astrologics.in/downloads/sdks/astrologics-python-0.1.0.tar.gz

2. Set your key

Create a test key. Test keys run the real engine and are never charged.

export ASTROLOGICS_API_KEY=al_test_YOUR_KEY

Use a secret key only on a server, never in a web page or a mobile app.

3. Make your first call

Save as first_call.py and run python3 first_call.py.

import os
from astrologics import AstroLogics

client = AstroLogics(api_key=os.environ["ASTROLOGICS_API_KEY"])

result = client.get_kundli(birth={"date": "1990-08-13", "time": "06:30", "place": {"latitude": 28.6139, "longitude": 77.209}})
print(result["data"]["lagna"]["sign"], result["meta"]["mode"], result["meta"]["credits_charged"])

It prints the lagna's sign, then test 0: the call ran in test mode and cost no credits. A place can also be a place_id or free text; see the birth object.

4. Save a chart

Save as save_chart.py. An SVG operation returns a string, and a PNG or PDF operation returns bytes.

import os
from astrologics import AstroLogics

client = AstroLogics(api_key=os.environ["ASTROLOGICS_API_KEY"])

svg = client.get_chart_svg(varga="D1", birth={"date": "1990-08-13", "time": "06:30", "place": {"latitude": 28.6139, "longitude": 77.209}})
with open("chart.svg", "w", encoding="utf-8") as f:
    f.write(svg)

5. Handle errors

Save as handle_errors.py. Any failed call raises an ApiError. Branch on code, not on the message, and quote request_id when you write to us. See errors.

import os
from astrologics import ApiError, AstroLogics

client = AstroLogics(api_key=os.environ["ASTROLOGICS_API_KEY"])

try:
    client.get_kundli(birth={"date": "1990-13-45"})
except ApiError as e:
    print(e.status, e.code, e.request_id)
    for issue in e.issues:
        print(issue["param"], issue["message"])

ApiError also carries candidates for an ambiguous place and suggestions for an unknown path.

Retries and timeouts

429 and 5xx answers are retried twice by default, honouring Retry-After. quota_exhausted is not retried. To change this, pass max_retries and timeout (in seconds, default 60) to the constructor.

Find a method

Each method is the operation's id from the API reference in snake case, so getKundli is get_kundli. Its keyword arguments are the operation's parameters and body, side by side. There is one method per public operation: 133 today.

Go live

Swap in a live key (al_live_) when you are ready. Live keys spend your plan's credits, and only successful calls are charged.

Next: SDKs · TypeScript · PHP