lifeastroapi 0.1.0__tar.gz → 0.3.0__tar.gz

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
Files changed (98) hide show
  1. lifeastroapi-0.3.0/CHANGELOG.md +77 -0
  2. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/PKG-INFO +279 -11
  3. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/README.md +276 -8
  4. lifeastroapi-0.3.0/examples/pdf_report.py +53 -0
  5. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/pyproject.toml +9 -3
  6. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/scripts/costs.json +2 -1
  7. lifeastroapi-0.3.0/scripts/generate_pdf.mjs +1004 -0
  8. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/scripts/manifest.json +109 -4
  9. lifeastroapi-0.3.0/scripts/pdf_goldens.mjs +459 -0
  10. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/scripts/samples.py +1 -0
  11. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/src/lifeastroapi/__init__.py +2 -0
  12. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/src/lifeastroapi/_version.py +1 -1
  13. lifeastroapi-0.3.0/src/lifeastroapi/pdf/__init__.py +136 -0
  14. lifeastroapi-0.3.0/src/lifeastroapi/pdf/_branding.py +115 -0
  15. lifeastroapi-0.3.0/src/lifeastroapi/pdf/_browser.py +316 -0
  16. lifeastroapi-0.3.0/src/lifeastroapi/pdf/_chrome.py +349 -0
  17. lifeastroapi-0.3.0/src/lifeastroapi/pdf/_devtools.py +140 -0
  18. lifeastroapi-0.3.0/src/lifeastroapi/pdf/_gotenberg.py +180 -0
  19. lifeastroapi-0.3.0/src/lifeastroapi/pdf/_js.py +754 -0
  20. lifeastroapi-0.3.0/src/lifeastroapi/pdf/_options.py +178 -0
  21. lifeastroapi-0.3.0/src/lifeastroapi/pdf/_outline.py +229 -0
  22. lifeastroapi-0.3.0/src/lifeastroapi/pdf/_print_css.py +90 -0
  23. lifeastroapi-0.3.0/src/lifeastroapi/pdf/_reports.py +652 -0
  24. lifeastroapi-0.3.0/src/lifeastroapi/pdf/_templates/__init__.py +1 -0
  25. lifeastroapi-0.3.0/src/lifeastroapi/pdf/_templates/colors.py +334 -0
  26. lifeastroapi-0.3.0/src/lifeastroapi/pdf/_templates/dasha_analysis.py +666 -0
  27. lifeastroapi-0.3.0/src/lifeastroapi/pdf/_templates/horoscope.py +435 -0
  28. lifeastroapi-0.3.0/src/lifeastroapi/pdf/_templates/kundli_brihad.py +3300 -0
  29. lifeastroapi-0.3.0/src/lifeastroapi/pdf/_templates/kundli_brihad_sections.py +1609 -0
  30. lifeastroapi-0.3.0/src/lifeastroapi/pdf/_templates/kundli_detailed.py +624 -0
  31. lifeastroapi-0.3.0/src/lifeastroapi/pdf/_templates/kundli_lite.py +364 -0
  32. lifeastroapi-0.3.0/src/lifeastroapi/pdf/_templates/locales.py +376 -0
  33. lifeastroapi-0.3.0/src/lifeastroapi/pdf/_templates/mangal_dosha.py +977 -0
  34. lifeastroapi-0.3.0/src/lifeastroapi/pdf/_templates/match_making.py +851 -0
  35. lifeastroapi-0.3.0/src/lifeastroapi/pdf/_templates/north_indian_chart.py +382 -0
  36. lifeastroapi-0.3.0/src/lifeastroapi/pdf/_templates/numerology.py +772 -0
  37. lifeastroapi-0.3.0/src/lifeastroapi/pdf/_templates/planet_glyphs.py +157 -0
  38. lifeastroapi-0.3.0/src/lifeastroapi/pdf/_templates/sade_sati.py +872 -0
  39. lifeastroapi-0.3.0/src/lifeastroapi/pdf/_templates/shared.py +582 -0
  40. lifeastroapi-0.3.0/src/lifeastroapi/pdf/_templates/varshaphal.py +694 -0
  41. lifeastroapi-0.3.0/src/lifeastroapi/pdf/_threads.py +68 -0
  42. lifeastroapi-0.3.0/src/lifeastroapi/pdf/_websocket.py +180 -0
  43. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/chart.py +22 -12
  44. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/prashna.py +70 -0
  45. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/src/lifeastroapi/types.py +5 -4
  46. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/tests/fixtures/examples.json +465 -380
  47. lifeastroapi-0.3.0/tests/pdf_devtools_stub.py +163 -0
  48. lifeastroapi-0.3.0/tests/pdf_support.py +113 -0
  49. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/tests/test_manifest.py +4 -2
  50. lifeastroapi-0.3.0/tests/test_pdf_branding_options.py +993 -0
  51. lifeastroapi-0.3.0/tests/test_pdf_chrome.py +286 -0
  52. lifeastroapi-0.3.0/tests/test_pdf_engine.py +555 -0
  53. lifeastroapi-0.3.0/tests/test_pdf_gotenberg.py +164 -0
  54. lifeastroapi-0.3.0/tests/test_pdf_js.py +125 -0
  55. lifeastroapi-0.3.0/tests/test_pdf_outline.py +110 -0
  56. lifeastroapi-0.3.0/tests/test_pdf_settle.py +411 -0
  57. lifeastroapi-0.3.0/tests/test_pdf_templates.py +483 -0
  58. lifeastroapi-0.3.0/tests/test_version.py +30 -0
  59. lifeastroapi-0.1.0/CHANGELOG.md +0 -34
  60. lifeastroapi-0.1.0/tests/test_version.py +0 -15
  61. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/.gitignore +0 -0
  62. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/LICENSE +0 -0
  63. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/examples/async_example.py +0 -0
  64. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/examples/error_handling.py +0 -0
  65. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/examples/quickstart.py +0 -0
  66. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/scripts/generate.py +0 -0
  67. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/scripts/live_sweep.py +0 -0
  68. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/src/lifeastroapi/_client.py +0 -0
  69. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/src/lifeastroapi/_core.py +0 -0
  70. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/src/lifeastroapi/_http.py +0 -0
  71. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/src/lifeastroapi/_params.py +0 -0
  72. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/src/lifeastroapi/errors.py +0 -0
  73. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/src/lifeastroapi/py.typed +0 -0
  74. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/__init__.py +0 -0
  75. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/ashtakavarga.py +0 -0
  76. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/calendar.py +0 -0
  77. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/dasha.py +0 -0
  78. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/eclipses.py +0 -0
  79. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/festivals.py +0 -0
  80. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/geo.py +0 -0
  81. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/horoscope.py +0 -0
  82. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/lalkitab.py +0 -0
  83. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/meta.py +0 -0
  84. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/milan.py +0 -0
  85. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/muhurta.py +0 -0
  86. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/narrative.py +0 -0
  87. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/numerology.py +0 -0
  88. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/panchang.py +0 -0
  89. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/planet_moments.py +0 -0
  90. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/remedies.py +0 -0
  91. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/reports.py +0 -0
  92. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/tarot.py +0 -0
  93. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/transit.py +0 -0
  94. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/varshaphal.py +0 -0
  95. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/western.py +0 -0
  96. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/tests/conftest.py +0 -0
  97. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/tests/test_async_client.py +0 -0
  98. {lifeastroapi-0.1.0 → lifeastroapi-0.3.0}/tests/test_client.py +0 -0
@@ -0,0 +1,77 @@
1
+ # Changelog
2
+
3
+ ## 0.3.0 — 2026-11-22
4
+
5
+ Upgrading from 0.2.0: your code keeps working. The install is the same and has no new dependency.
6
+
7
+ - **New: PDF reports.** `lifeastroapi.pdf` turns the JSON of every `client.reports.*` method into a
8
+ branded PDF, in all 10 languages, with one call: `kundli_lite_pdf(report, branding)`,
9
+ `match_making_pdf(...)`, and so on.
10
+ - The PDF is made on your machine, with Chrome, Chromium or Microsoft Edge (found
11
+ automatically) or with a Gotenberg service you run. Nothing is sent to LifeAstroAPI for it.
12
+ - Your branding: company name and footer line as you wrote them, logo, colours, and a watermark
13
+ on every page. The Brihad kundli follows your colours in headings, banners, contents, charts,
14
+ header and footer, and is saffron without a brand. A colour too pale to read prints darker.
15
+ - The Brihad kundli PDF has a table of contents with the real page numbers, a running header
16
+ and footer with your company name and footer line, bookmarks in the report's language and the
17
+ document title.
18
+ - `PdfOptions` for margins (side by side), paper size, landscape, printing without backgrounds,
19
+ your own header and footer, and timeouts. They apply to the reports and to your own HTML.
20
+ - For many PDFs, keep one browser open with `ChromePdfEngine`. In `asyncio` code use the
21
+ `*_pdf_async` functions: they do not block, and they stop when the task is cancelled.
22
+ - Only need HTML, for a browser or an app's web view? The `render_*_html` functions need no
23
+ browser and give the same HTML as the Node.js SDK. `A4_PRINT_OPTIONS` has the page size and
24
+ margins.
25
+ - A failed PDF raises `PdfError` (a `LifeAstroError`), whose `code` says what went wrong.
26
+ - **Fixed:** the `HouseSystem` type now has `"whole_sign"`, the name the API reads. The old
27
+ `"whole-sign"` got a 400 error from the API until 2026-11-21. The API now accepts it as an
28
+ alias and the type still lists it, so code that uses it keeps working and type-checking.
29
+ - **Punjabi (`pa`)** is now a complete language, prose included.
30
+
31
+ ## 0.2.0 — 2026-11-15
32
+
33
+ - New `prashna.kp_horary(number=..., lat=..., lon=..., tz=..., date=..., time=...)`: the KP horary
34
+ chart for a number from 1 to 249, cast for the moment and place of judgement. Returns the
35
+ horary ascendant (the first degree of that number's part), the 12 Placidus cusps with star, sub
36
+ and sub-sub lords and significators, the planets with KP lords and houses, planet significators,
37
+ the KP 4-step chain and the ruling planets. Uses the Krishnamurti ayanamsa unless `ayanamsa` is
38
+ sent. 30 credits. Same method as the Node.js SDK 0.13.0.
39
+ - `chart.kp_sublord` now also returns the KP ruling planets (`ruling_planets`), and
40
+ `chart.kp_house_significator` returns each cusp's significator planets, the houses every planet
41
+ signifies and the 4-step chain (new fields from the API; nothing removed).
42
+ - `chart.kp_sublord`'s `planet` and `chart.kp_house_significator`'s `cusp` are now optional. The
43
+ API never read them: it always returns every planet and all 12 cusps. Code that passes them
44
+ keeps working.
45
+ - 323 methods (322 endpoints).
46
+
47
+ ## 0.1.0 — 2026-11-15
48
+
49
+ First release of the official Python SDK.
50
+
51
+ - `LifeAstro` (blocking) and `AsyncLifeAstro` (`asyncio`) clients on `httpx`, the only runtime
52
+ dependency. Both are context managers and have `close()`. The API key comes from `api_key=`
53
+ or the `LIFEASTRO_API_KEY` environment variable.
54
+ - 322 methods in 23 resource groups (`client.panchang.basic(...)`, `client.chart.planets(...)`,
55
+ `client.western.natal.chart(...)`, ...): one method per endpoint, generated from the same
56
+ manifest as the Node.js SDK 0.8.0, with the Node method and argument names in snake_case.
57
+ - Keyword arguments mapped to the API's wire names: unprefixed `date` / `time` / `tz` / `lat` /
58
+ `lon` for a chart, `birth.*` for the natal chart of transit-style methods, `boy.*` / `girl.*`
59
+ for kundli matching and `personA.*` / `personB.*` for Western pairs. Moment methods send
60
+ today's date in the given `tz` when `date` is left out.
61
+ - `lang` on every Vedic method whose response carries names or text, sent as `lang` and
62
+ `locale`. `Locale` lists the 10 codes: `en`, `hi`, `mr`, `gu`, `bn`, `te`, `ta`, `kn`, `ml`
63
+ (complete) and `pa` (names and terms).
64
+ - Typed errors with `status`, `code`, `message` and `request_id`: `BadRequestError`,
65
+ `AuthenticationError`, `PaymentRequiredError`, `PermissionDeniedError`, `NotFoundError`,
66
+ `RateLimitError` (`retry_after`), `ServerError`, `LifeAstroConnectionError` and
67
+ `LifeAstroTimeoutError`.
68
+ - Automatic retries with exponential backoff on 429, 5xx, network errors and timeouts,
69
+ honouring `Retry-After`; per-call `request_options={"timeout": ..., "raw": ...}`.
70
+ - `on_response` hook, as a client argument and per call (`request_options={"on_response": ...}`):
71
+ receives a `ResponseInfo` with the request id, `credits_remaining`, the rate limit
72
+ (`RateLimit(limit, remaining, reset_at)`), the cache result and the answer's language for every
73
+ call, success or error. Exported `ResponseInfo`, `RateLimit` and `ResponseHook`. See "Credits,
74
+ rate limit and request id" in the README. Same as the Node SDK 0.10.0 `onResponse`.
75
+ - `client.request(path, query)` / `client.get(...)` to call any `/v1/*` endpoint directly.
76
+ - Responses are the parsed JSON (`dict` / `list`). Full type hints, `py.typed`, checked with
77
+ `mypy --strict`. Every method's docstring has the endpoint description, credit cost and path.
@@ -1,7 +1,7 @@
1
1
  Metadata-Version: 2.5
2
2
  Name: lifeastroapi
3
- Version: 0.1.0
4
- Summary: Official Python SDK for LifeAstroAPI: Vedic astrology and Hindu calendar API (panchang, festivals, kundli, dasha, kundli matching, muhurat, horoscopes, numerology, tarot, Western astrology) in 10 languages.
3
+ Version: 0.3.0
4
+ Summary: Official Python SDK for LifeAstroAPI: Vedic astrology and Hindu calendar API (panchang, festivals, kundli, dasha, kundli matching, muhurat, horoscopes, numerology, tarot, Western astrology) in 10 languages, with branded PDF reports.
5
5
  Project-URL: Homepage, https://lifeastroapi.com
6
6
  Project-URL: Documentation, https://lifeastroapi.com/docs/
7
7
  Project-URL: Repository, https://github.com/ayanshulife/lifeastroapi-python
@@ -10,7 +10,7 @@ Project-URL: Changelog, https://github.com/ayanshulife/lifeastroapi-python/blob/
10
10
  Author-email: Ayanshu Life <support@lifeastroapi.com>
11
11
  License-Expression: MIT
12
12
  License-File: LICENSE
13
- Keywords: astrology,astrology-api,festivals,hindu-calendar,horoscope,jyotish,kundli,kundli-matching,lifeastroapi,muhurat,numerology,panchang,tarot,vedic-astrology,western-astrology
13
+ Keywords: astrology,astrology-api,festivals,hindu-calendar,horoscope,jyotish,kundli,kundli-matching,kundli-pdf,lifeastroapi,muhurat,numerology,panchang,pdf-reports,tarot,vedic-astrology,western-astrology
14
14
  Classifier: Development Status :: 4 - Beta
15
15
  Classifier: Intended Audience :: Developers
16
16
  Classifier: Operating System :: OS Independent
@@ -42,7 +42,7 @@ kundli, kundli matching, muhurat, dashas, horoscopes, numerology, tarot and West
42
42
  location-aware calculations and pay-per-call billing. Free tier: 1,500 credits a month, no card.
43
43
  [Get a key](https://lifeastroapi.com/signup/).
44
44
 
45
- - **Every endpoint**: all 321 endpoints (322 methods, with a shortcut for the navamsa chart) across 23 resource groups (panchang, chart, dasha, milan,
45
+ - **Every endpoint**: all 322 endpoints (323 methods, with a shortcut for the navamsa chart) across 23 resource groups (panchang, chart, dasha, milan,
46
46
  transit, horoscope, numerology, muhurta, reports, narrative, remedies, a complete Western
47
47
  module and more). Same methods as the official Node.js SDK, generated from the same manifest.
48
48
  - **Sync and async**: `LifeAstro` and `AsyncLifeAstro`, both on [httpx](https://www.python-httpx.org/),
@@ -51,6 +51,8 @@ location-aware calculations and pay-per-call billing. Free tier: 1,500 credits a
51
51
  and `pa` with `lang=`.
52
52
  - **Typed**: full type hints and `py.typed`; keyword arguments with `Literal` types for
53
53
  languages, ayanamsas and house systems. Passes `mypy --strict`.
54
+ - **Branded PDF reports**: `lifeastroapi.pdf` turns the report JSON into HTML and PDF on your
55
+ own machine, with no extra dependency ([PDF reports](#pdf-reports)).
54
56
  - Typed errors, automatic retries (429, 5xx and network errors) that honour `Retry-After`,
55
57
  timeouts, and an escape hatch for any endpoint.
56
58
  - Python 3.9 and later.
@@ -125,7 +127,7 @@ asyncio.run(main())
125
127
  Every method of `LifeAstro` exists on `AsyncLifeAstro` with the same arguments, as a coroutine.
126
128
 
127
129
  More in [examples/](https://github.com/ayanshulife/lifeastroapi-python/tree/main/examples):
128
- quick start, async calls, and error handling.
130
+ quick start, async calls, error handling and PDF reports.
129
131
 
130
132
  ## Authentication
131
133
 
@@ -249,7 +251,7 @@ chart = client.chart.planets(**arjun, lang="ta")
249
251
  | `ta` | Tamil | complete |
250
252
  | `kn` | Kannada | complete |
251
253
  | `ml` | Malayalam | complete |
252
- | `pa` | Punjabi | names and terms; longer prose is still English |
254
+ | `pa` | Punjabi | complete |
253
255
 
254
256
  - The `Locale` type lists the codes, and `LOCALES` holds them as a tuple.
255
257
  - **Where it works:** `panchang`, `calendar`, `festivals`, `eclipses`, `planet_moments`,
@@ -270,7 +272,7 @@ chart = client.chart.planets(**arjun, lang="ta")
270
272
  | Group | What it covers |
271
273
  |-------|----------------|
272
274
  | `panchang` | tithi, nakshatra, yoga, karana, vara, sunrise/sunset, rahu kaal, choghadiya, hora, muhurtas, monthly calendar, composite `basic` / `advanced` |
273
- | `chart` | planets, ascendant, houses, divisional (D1-D60), dignity, aspects, shadbala, ashtakvarga, avakhada, KP, astro details; data bundles `kundli_facts`, `yogas`, `doshas`, birth-time `sensitivity` |
275
+ | `chart` | planets, ascendant, houses, divisional (D1-D60), dignity, aspects, shadbala, ashtakvarga, avakhada, KP (sub lords, ruling planets, significators, 4-step chain), astro details; data bundles `kundli_facts`, `yogas`, `doshas`, birth-time `sensitivity` |
274
276
  | `dasha` | Vimshottari (full, current, 5-level drill-down), Yogini and Chara dashas |
275
277
  | `milan` | Ashtakoota (total, full, per koota), mangal / nadi / shani dosha, navamsa and dasha compatibility, `overlay`, `summary` |
276
278
  | `transit` | positions, sade sati, ashtakavarga, tarabala, vedha, double transit, small panoti, `sade_sati_windows`, `windows` |
@@ -278,7 +280,7 @@ chart = client.chart.planets(**arjun, lang="ta")
278
280
  | `numerology` | driver, conductor, soul, personality, destiny, full, advanced, challenges, personal periods |
279
281
  | `muhurta` | vivah, naamkaran, griha pravesh, vyapar, yatra, best time, chandra / tara bala |
280
282
  | `varshaphal` | annual chart, lord, muntha, mudda dasha, harsha bala, tajika yogas |
281
- | `prashna` | horary answer, chart, arudha, significators |
283
+ | `prashna` | horary answer, chart, arudha, significators, KP horary (1-249) |
282
284
  | `eclipses` | solar, lunar, all (date range, local contacts and sutak) |
283
285
  | `calendar` | Hindu month, ritu, samvatsara, adhik maas, solstices |
284
286
  | `festivals` | Hindu festivals by month, on a date, or by vrat family; `lang`, `month_system` (amanta / purnimanta) |
@@ -286,7 +288,7 @@ chart = client.chart.planets(**arjun, lang="ta")
286
288
  | `ashtakavarga` | sarva, bhinna (per planet), kaksha, transit score |
287
289
  | `geo` | place search, reverse geocoding, time zone, place by id |
288
290
  | `tarot` | cards, one card, daily card, spread, yes / no |
289
- | `reports` | JSON reports: kundli (lite, detailed, brihad), match making, mangal dosha, sade sati, varshaphal, numerology, horoscopes |
291
+ | `reports` | JSON reports, which [`lifeastroapi.pdf`](#pdf-reports) turns into PDF: kundli (lite, detailed, brihad), match making, mangal dosha, sade sati, varshaphal, numerology, horoscopes |
290
292
  | `narrative` | authored Vedic readings (lagna, planets, yogas, doshas, dasha phal, transit phal, prashna, horoscopes, ...) |
291
293
  | `remedies` | remedies by rule id, `for_graha`, mantra, pooja, vrat, daan, rudraksha, yantra, Lal Kitab |
292
294
  | `lalkitab` | Lal Kitab chart and dasha |
@@ -349,6 +351,7 @@ except LifeAstroError as err:
349
351
  | `ServerError` | 5xx |
350
352
  | `LifeAstroConnectionError` | network failure, no response (`status == 0`) |
351
353
  | `LifeAstroTimeoutError` | the request timed out (a `LifeAstroConnectionError`) |
354
+ | `lifeastroapi.pdf.PdfError` | a PDF could not be made (`status == 0`; see [PDF reports](#pdf-reports)) |
352
355
 
353
356
  All of them extend `LifeAstroError`. Requests are retried automatically (`max_retries`, default
354
357
  2) on 408, 425, 429, 500, 502, 503, 504, network errors and timeouts, with exponential backoff
@@ -429,8 +432,261 @@ data = client.request(
429
432
 
430
433
  ## PDF reports
431
434
 
432
- The `reports.*` methods return the report JSON. Branded PDF rendering of those reports, which
433
- the Node SDK offers in `lifeastroapi/pdf`, is planned for a later version of this package.
435
+ `lifeastroapi.pdf` turns the JSON of any `reports.*` method into a branded, print-ready PDF
436
+ (kundli lite, detailed and Brihad, match making, mangal dosha, sade sati, varshaphal, numerology,
437
+ dasha analysis, horoscopes) in all 10 languages. It is part of the normal install.
438
+
439
+ The PDF is made on **your** machine. LifeAstroAPI returns the report JSON (that call costs the
440
+ report's credits); turning it into HTML and PDF costs nothing and sends nothing to LifeAstroAPI.
441
+
442
+ ```python
443
+ from lifeastroapi import LifeAstro
444
+ from lifeastroapi.pdf import kundli_detailed_pdf
445
+
446
+ report = LifeAstro().reports.kundli_detailed(**arjun, name="Arjun Mehta", lang="hi")
447
+ pdf = kundli_detailed_pdf(report, {"company_name": "Acme Astro", "primary_color": "#6b21a8"})
448
+ with open("kundli.pdf", "wb") as file:
449
+ file.write(pdf)
450
+ ```
451
+
452
+ Pass what the client returned: there is nothing to convert. The PDF is in the `lang` you
453
+ requested the report in.
454
+
455
+ | `client.reports.` | HTML | PDF |
456
+ |---|---|---|
457
+ | `kundli_lite` | `render_kundli_lite_html` | `kundli_lite_pdf` |
458
+ | `kundli_detailed` | `render_kundli_detailed_html` | `kundli_detailed_pdf` |
459
+ | `kundli_brihad` | `render_kundli_brihad_html` | `kundli_brihad_pdf` (table of contents, running header, bookmarks) |
460
+ | `match_making` | `render_match_making_html` | `match_making_pdf` |
461
+ | `mangal_dosha` | `render_mangal_dosha_html` | `mangal_dosha_pdf` |
462
+ | `sade_sati` | `render_sade_sati_html` | `sade_sati_pdf` |
463
+ | `varshaphal` | `render_varshaphal_html` | `varshaphal_pdf` |
464
+ | `numerology` | `render_numerology_html` | `numerology_pdf` |
465
+ | `dasha_analysis` | `render_dasha_analysis_html` | `dasha_analysis_pdf` |
466
+ | `horoscope_daily`, `horoscope_weekly`, `horoscope_monthly` | `render_horoscope_html` | `horoscope_pdf` |
467
+
468
+ Every `*_pdf` function has a `*_pdf_async` twin. `html_to_pdf` and `html_to_pdf_async` print your
469
+ own HTML. The `render_*_html` functions are pure Python (no browser, process, file or network
470
+ access) and give the same bytes as the Node.js SDK.
471
+
472
+ ### The browser and fonts
473
+
474
+ A PDF needs Chrome, Chromium or Microsoft Edge on the machine that makes it, and fonts for the
475
+ scripts you print (a missing font shows as empty boxes):
476
+
477
+ | Where it prints | Browser | Fonts for the Indian scripts |
478
+ |---|---|---|
479
+ | Debian, Ubuntu, Docker | `chromium`, or Google Chrome | `fonts-noto-core` |
480
+ | Other Linux | Chrome, Chromium or Edge | Noto Sans for Devanagari, Bengali, Gujarati, Gurmukhi, Tamil, Telugu, Kannada, Malayalam |
481
+ | macOS | Chrome, Chromium or Edge | the system fonts, or Noto Sans |
482
+ | Windows | Chrome, or Microsoft Edge | the system's Nirmala UI, or Noto Sans |
483
+ | Gotenberg | inside its image | inside its image |
484
+
485
+ ```dockerfile
486
+ FROM python:3.12-slim
487
+ RUN apt-get update \
488
+ && apt-get install -y --no-install-recommends chromium fonts-noto-core
489
+ RUN pip install lifeastroapi
490
+ ```
491
+
492
+ The browser is looked up in `LIFEASTRO_CHROME`, `CHROME_PATH` and `PUPPETEER_EXECUTABLE_PATH`,
493
+ then in the usual install locations. You can also pass `ChromePdfEngine(executable=...)`.
494
+ `--no-sandbox` is added only when the process runs as root, where Chrome cannot start without
495
+ it. Set `no_sandbox=` to decide yourself.
496
+
497
+ ### Reuse one browser
498
+
499
+ Without `engine=`, each call starts a browser and closes it. For more than one PDF, keep an
500
+ engine:
501
+
502
+ ```python
503
+ from lifeastroapi.pdf import ChromePdfEngine, kundli_lite_pdf
504
+
505
+ with ChromePdfEngine() as engine:
506
+ pdfs = [kundli_lite_pdf(report, engine=engine) for report in reports]
507
+ ```
508
+
509
+ The engine starts its browser on first use, can be shared between threads and tasks, and can be
510
+ created before a `fork`: each child process starts its own browser. `close()` (or
511
+ `await engine.aclose()`) stops the browser and deletes its temporary profile. Prints still
512
+ running then fail with `PdfError` (code `closed`). If the browser crashes, they fail with
513
+ `browser_failed` and the next call starts a new one. An engine left open is closed when the
514
+ process exits normally.
515
+
516
+ In Python, SIGTERM (`docker stop`, systemd, `timeout`) ends a process without a normal exit. In
517
+ your own script or worker, turn it into one, so that the browser is stopped too:
518
+
519
+ ```python
520
+ import signal
521
+ import sys
522
+
523
+ signal.signal(signal.SIGTERM, lambda *_: sys.exit(0))
524
+ ```
525
+
526
+ ### Django
527
+
528
+ ```python
529
+ # views.py
530
+ from django.http import HttpResponse
531
+ from lifeastroapi import LifeAstro
532
+ from lifeastroapi.pdf import ChromePdfEngine, kundli_lite_pdf
533
+
534
+ client = LifeAstro()
535
+ engine = ChromePdfEngine() # starts on first use
536
+
537
+
538
+ def kundli_pdf(request):
539
+ q = request.GET
540
+ report = client.reports.kundli_lite(
541
+ date=q["date"], time=q["time"], tz=q["tz"], lat=float(q["lat"]), lon=float(q["lon"])
542
+ )
543
+ pdf = kundli_lite_pdf(report, {"company_name": "Acme Astro"}, engine=engine)
544
+ response = HttpResponse(pdf, content_type="application/pdf")
545
+ response["Content-Disposition"] = 'attachment; filename="kundli.pdf"'
546
+ return response
547
+ ```
548
+
549
+ ### FastAPI
550
+
551
+ ```python
552
+ from contextlib import asynccontextmanager
553
+
554
+ from fastapi import FastAPI, Response
555
+ from lifeastroapi import AsyncLifeAstro
556
+ from lifeastroapi.pdf import ChromePdfEngine, kundli_lite_pdf_async
557
+
558
+
559
+ @asynccontextmanager
560
+ async def lifespan(app: FastAPI):
561
+ async with AsyncLifeAstro() as client, ChromePdfEngine() as engine:
562
+ app.state.client, app.state.engine = client, engine
563
+ yield
564
+
565
+
566
+ app = FastAPI(lifespan=lifespan)
567
+
568
+
569
+ @app.get("/kundli.pdf")
570
+ async def kundli(date: str, time: str, tz: str, lat: float, lon: float) -> Response:
571
+ report = await app.state.client.reports.kundli_lite(
572
+ date=date, time=time, tz=tz, lat=lat, lon=lon
573
+ )
574
+ pdf = await kundli_lite_pdf_async(report, engine=app.state.engine) # the loop stays free
575
+ return Response(pdf, media_type="application/pdf")
576
+ ```
577
+
578
+ ### Celery (and other job queues)
579
+
580
+ The Brihad kundli runs to a few hundred pages and prints twice, so make it in a background job:
581
+
582
+ ```python
583
+ from pathlib import Path
584
+
585
+ from celery import shared_task
586
+ from celery.signals import worker_process_shutdown
587
+ from lifeastroapi import LifeAstro
588
+ from lifeastroapi.pdf import ChromePdfEngine, PdfOptions, kundli_brihad_pdf
589
+
590
+ engine = ChromePdfEngine() # each worker process starts its own browser on first use
591
+ worker_process_shutdown.connect(lambda **_: engine.close(), weak=False)
592
+
593
+
594
+ @shared_task
595
+ def brihad_pdf(birth: dict, path: str) -> None:
596
+ with LifeAstro(timeout=120) as client:
597
+ report = client.reports.kundli_brihad(**birth)
598
+ pdf = kundli_brihad_pdf(report, engine=engine, options=PdfOptions(timeout=90))
599
+ Path(path).write_bytes(pdf)
600
+ ```
601
+
602
+ ### Without a browser: Gotenberg
603
+
604
+ Run [Gotenberg](https://gotenberg.dev) anywhere you control
605
+ (`docker run --rm -p 3000:3000 gotenberg/gotenberg:8`) and print through it:
606
+
607
+ ```python
608
+ from lifeastroapi.pdf import GotenbergPdfEngine, match_making_pdf
609
+
610
+ engine = GotenbergPdfEngine("http://localhost:3000") # headers={...} for auth
611
+ pdf = match_making_pdf(report, engine=engine)
612
+ ```
613
+
614
+ ### Desktop, mobile and the browser
615
+
616
+ Let your backend call the API and render, and print the HTML in the app's web view or in the
617
+ user's browser (Print, then "Save as PDF"). The API key stays on your server. The HTML sets A4
618
+ pages and margins in its own CSS. For print APIs that ignore CSS `@page` (iOS), send the
619
+ geometry along:
620
+
621
+ ```python
622
+ from lifeastroapi.pdf import A4_PRINT_OPTIONS, render_kundli_lite_html
623
+
624
+ payload = {"html": render_kundli_lite_html(report), "print": A4_PRINT_OPTIONS} # in points
625
+ ```
626
+
627
+ The Brihad table of contents, running header and bookmarks are added by `kundli_brihad_pdf`.
628
+
629
+ ### Branding
630
+
631
+ Every key is optional. What you pass wins over the `Branding` inside the report JSON.
632
+
633
+ ```python
634
+ from lifeastroapi.pdf import Branding
635
+
636
+ branding: Branding = {
637
+ "company_name": "Acme Astro",
638
+ "logo_url": "https://acme.example/logo.png", # https, or a data:image/... URI
639
+ "primary_color": "#6b21a8", # headings, banners, table headers, charts
640
+ "secondary_color": "#9333ea", # meta text, footer, gold details
641
+ "footer_text": "Acme Astro · www.acme.example",
642
+ "watermark_text": "SAMPLE", # on every page, behind the content
643
+ }
644
+ ```
645
+
646
+ Colours take any CSS form (`#6b21a8`, `rebeccapurple`, `rgb(...)`, `hsl(...)`). One that is too
647
+ pale to read on paper is printed darker. The Brihad kundli is saffron until you or the report give
648
+ a brand colour, and then follows it in headings, banners, contents, charts, header and footer. The
649
+ API's default colours in a report do not count as a brand. The company name and footer line print
650
+ as you wrote them. A blank value counts as not set.
651
+
652
+ The browser fetches the logo while it prints. If the branding comes from your own customers,
653
+ check the logo URL first, or run the browser without access to your internal network.
654
+
655
+ ### Options, timeouts and errors
656
+
657
+ ```python
658
+ import threading
659
+
660
+ from lifeastroapi.pdf import PdfError, PdfOptions, numerology_pdf
661
+
662
+ options = PdfOptions(
663
+ timeout=30, # seconds for the page, images and fonts to load
664
+ print_timeout=180, # seconds for each print; raise it for a long Brihad on a slow machine
665
+ )
666
+ cancel = threading.Event() # set it from another thread to stop the job
667
+ try:
668
+ pdf = numerology_pdf(report, options=options, cancel=cancel)
669
+ except PdfError as err:
670
+ print(err.code, err.message)
671
+ ```
672
+
673
+ The reports set A4 and their margins themselves. What you set in `PdfOptions` wins over that:
674
+
675
+ | Option | Effect |
676
+ |---|---|
677
+ | `margin=PdfMargin(top="30mm")` | Each side you set (`mm`, `cm`, `in`, `px`, or a number of pixels). The other sides keep the report's margin. `"0"` is zero |
678
+ | `format="Letter"` | `A3`, `A4`, `A5`, `Letter`, `Legal` or `Tabloid` paper |
679
+ | `landscape=True` | Landscape paper |
680
+ | `prefer_css_page_size` | `True` keeps the HTML's own page size, `False` scales the page to the paper |
681
+ | `print_background=False` | No background colours; text that is white on colour prints dark |
682
+ | `display_header_footer=True` | Prints your `header_template` and `footer_template` instead of the report's footer line. The Brihad kundli prints its own unless you give templates; `False` turns them off |
683
+ | `scale=0.9` | Render scale, 0.1 to 2 |
684
+
685
+ With the default options your HTML is printed untouched.
686
+
687
+ `err.code` is one of `browser_not_found`, `browser_failed`, `timeout`, `cancelled`, `closed`,
688
+ `gotenberg_failed` or `invalid_pdf`. The `*_pdf_async` functions stop when their task is
689
+ cancelled.
434
690
 
435
691
  ## Development
436
692
 
@@ -447,6 +703,18 @@ python3 -m venv .venv && .venv/bin/pip install -e ".[dev]"
447
703
  through its `scripts/manifest.mjs`, so it needs `node`), so both SDKs always have the same
448
704
  methods. `--costs-url <base url>` refreshes the credit costs from `GET /v1/meta/endpoints`.
449
705
 
706
+ The PDF templates in `src/lifeastroapi/pdf/_templates` are generated from the Node SDK's
707
+ TypeScript templates, so do not edit them by hand:
708
+
709
+ ```bash
710
+ node scripts/generate_pdf.mjs # regenerate the templates (needs the Node SDK's dev dependencies)
711
+ node scripts/pdf_goldens.mjs # regenerate tests/fixtures/pdf from the Node SDK
712
+ ```
713
+
714
+ The PDF tests compare the HTML byte for byte with Node. With `LIFEASTRO_PDF_WORK` pointing at the
715
+ shared PDF reference they also check every full report; that test is skipped without it, and the
716
+ browser tests are skipped without a browser.
717
+
450
718
  `scripts/live_sweep.py` calls every method once against a real server and lists the calls the
451
719
  API rejects. It spends credits (one call per endpoint) and has no default URL:
452
720