lifeastroapi 0.2.0__tar.gz → 1.0.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-1.0.0/CHANGELOG.md +105 -0
  2. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/PKG-INFO +295 -9
  3. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/README.md +291 -5
  4. lifeastroapi-1.0.0/examples/pdf_report.py +53 -0
  5. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/pyproject.toml +10 -4
  6. lifeastroapi-1.0.0/scripts/generate_pdf.mjs +1004 -0
  7. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/scripts/manifest.json +9 -2
  8. lifeastroapi-1.0.0/scripts/pdf_goldens.mjs +459 -0
  9. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/src/lifeastroapi/__init__.py +2 -0
  10. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/src/lifeastroapi/_client.py +2 -0
  11. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/src/lifeastroapi/_http.py +37 -12
  12. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/src/lifeastroapi/_version.py +1 -1
  13. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/src/lifeastroapi/errors.py +18 -0
  14. lifeastroapi-1.0.0/src/lifeastroapi/pdf/__init__.py +136 -0
  15. lifeastroapi-1.0.0/src/lifeastroapi/pdf/_branding.py +115 -0
  16. lifeastroapi-1.0.0/src/lifeastroapi/pdf/_browser.py +316 -0
  17. lifeastroapi-1.0.0/src/lifeastroapi/pdf/_chrome.py +349 -0
  18. lifeastroapi-1.0.0/src/lifeastroapi/pdf/_devtools.py +140 -0
  19. lifeastroapi-1.0.0/src/lifeastroapi/pdf/_gotenberg.py +180 -0
  20. lifeastroapi-1.0.0/src/lifeastroapi/pdf/_js.py +754 -0
  21. lifeastroapi-1.0.0/src/lifeastroapi/pdf/_options.py +178 -0
  22. lifeastroapi-1.0.0/src/lifeastroapi/pdf/_outline.py +229 -0
  23. lifeastroapi-1.0.0/src/lifeastroapi/pdf/_print_css.py +90 -0
  24. lifeastroapi-1.0.0/src/lifeastroapi/pdf/_reports.py +652 -0
  25. lifeastroapi-1.0.0/src/lifeastroapi/pdf/_templates/__init__.py +1 -0
  26. lifeastroapi-1.0.0/src/lifeastroapi/pdf/_templates/colors.py +334 -0
  27. lifeastroapi-1.0.0/src/lifeastroapi/pdf/_templates/dasha_analysis.py +666 -0
  28. lifeastroapi-1.0.0/src/lifeastroapi/pdf/_templates/horoscope.py +435 -0
  29. lifeastroapi-1.0.0/src/lifeastroapi/pdf/_templates/kundli_brihad.py +3300 -0
  30. lifeastroapi-1.0.0/src/lifeastroapi/pdf/_templates/kundli_brihad_sections.py +1609 -0
  31. lifeastroapi-1.0.0/src/lifeastroapi/pdf/_templates/kundli_detailed.py +624 -0
  32. lifeastroapi-1.0.0/src/lifeastroapi/pdf/_templates/kundli_lite.py +364 -0
  33. lifeastroapi-1.0.0/src/lifeastroapi/pdf/_templates/locales.py +376 -0
  34. lifeastroapi-1.0.0/src/lifeastroapi/pdf/_templates/mangal_dosha.py +977 -0
  35. lifeastroapi-1.0.0/src/lifeastroapi/pdf/_templates/match_making.py +851 -0
  36. lifeastroapi-1.0.0/src/lifeastroapi/pdf/_templates/north_indian_chart.py +382 -0
  37. lifeastroapi-1.0.0/src/lifeastroapi/pdf/_templates/numerology.py +772 -0
  38. lifeastroapi-1.0.0/src/lifeastroapi/pdf/_templates/planet_glyphs.py +157 -0
  39. lifeastroapi-1.0.0/src/lifeastroapi/pdf/_templates/sade_sati.py +872 -0
  40. lifeastroapi-1.0.0/src/lifeastroapi/pdf/_templates/shared.py +582 -0
  41. lifeastroapi-1.0.0/src/lifeastroapi/pdf/_templates/varshaphal.py +694 -0
  42. lifeastroapi-1.0.0/src/lifeastroapi/pdf/_threads.py +68 -0
  43. lifeastroapi-1.0.0/src/lifeastroapi/pdf/_websocket.py +180 -0
  44. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/src/lifeastroapi/resources/numerology.py +4 -2
  45. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/src/lifeastroapi/types.py +5 -4
  46. lifeastroapi-1.0.0/tests/pdf_devtools_stub.py +163 -0
  47. lifeastroapi-1.0.0/tests/pdf_support.py +113 -0
  48. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/tests/test_client.py +41 -3
  49. lifeastroapi-1.0.0/tests/test_pdf_branding_options.py +993 -0
  50. lifeastroapi-1.0.0/tests/test_pdf_chrome.py +286 -0
  51. lifeastroapi-1.0.0/tests/test_pdf_engine.py +555 -0
  52. lifeastroapi-1.0.0/tests/test_pdf_gotenberg.py +164 -0
  53. lifeastroapi-1.0.0/tests/test_pdf_js.py +125 -0
  54. lifeastroapi-1.0.0/tests/test_pdf_outline.py +110 -0
  55. lifeastroapi-1.0.0/tests/test_pdf_settle.py +411 -0
  56. lifeastroapi-1.0.0/tests/test_pdf_templates.py +483 -0
  57. lifeastroapi-1.0.0/tests/test_version.py +30 -0
  58. lifeastroapi-0.2.0/CHANGELOG.md +0 -50
  59. lifeastroapi-0.2.0/tests/test_version.py +0 -15
  60. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/.gitignore +0 -0
  61. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/LICENSE +0 -0
  62. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/examples/async_example.py +0 -0
  63. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/examples/error_handling.py +0 -0
  64. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/examples/quickstart.py +0 -0
  65. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/scripts/costs.json +0 -0
  66. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/scripts/generate.py +0 -0
  67. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/scripts/live_sweep.py +0 -0
  68. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/scripts/samples.py +0 -0
  69. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/src/lifeastroapi/_core.py +0 -0
  70. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/src/lifeastroapi/_params.py +0 -0
  71. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/src/lifeastroapi/py.typed +0 -0
  72. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/src/lifeastroapi/resources/__init__.py +0 -0
  73. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/src/lifeastroapi/resources/ashtakavarga.py +0 -0
  74. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/src/lifeastroapi/resources/calendar.py +0 -0
  75. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/src/lifeastroapi/resources/chart.py +0 -0
  76. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/src/lifeastroapi/resources/dasha.py +0 -0
  77. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/src/lifeastroapi/resources/eclipses.py +0 -0
  78. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/src/lifeastroapi/resources/festivals.py +0 -0
  79. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/src/lifeastroapi/resources/geo.py +0 -0
  80. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/src/lifeastroapi/resources/horoscope.py +0 -0
  81. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/src/lifeastroapi/resources/lalkitab.py +0 -0
  82. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/src/lifeastroapi/resources/meta.py +0 -0
  83. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/src/lifeastroapi/resources/milan.py +0 -0
  84. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/src/lifeastroapi/resources/muhurta.py +0 -0
  85. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/src/lifeastroapi/resources/narrative.py +0 -0
  86. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/src/lifeastroapi/resources/panchang.py +0 -0
  87. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/src/lifeastroapi/resources/planet_moments.py +0 -0
  88. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/src/lifeastroapi/resources/prashna.py +0 -0
  89. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/src/lifeastroapi/resources/remedies.py +0 -0
  90. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/src/lifeastroapi/resources/reports.py +0 -0
  91. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/src/lifeastroapi/resources/tarot.py +0 -0
  92. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/src/lifeastroapi/resources/transit.py +0 -0
  93. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/src/lifeastroapi/resources/varshaphal.py +0 -0
  94. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/src/lifeastroapi/resources/western.py +0 -0
  95. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/tests/conftest.py +0 -0
  96. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/tests/fixtures/examples.json +0 -0
  97. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/tests/test_async_client.py +0 -0
  98. {lifeastroapi-0.2.0 → lifeastroapi-1.0.0}/tests/test_manifest.py +0 -0
@@ -0,0 +1,105 @@
1
+ # Changelog
2
+
3
+ ## 1.0.0 — 2026-11-27
4
+
5
+ This is the first stable release. From 1.0.0 on, a change that needs a code change on your side
6
+ only comes with a new major version. The install is the same and has no new dependency.
7
+
8
+ - **Easier key setup.** The API key is trimmed of spaces and line breaks around it, so a key read
9
+ from a file or a quoted `.env` value works as it is.
10
+ - **The key never appears in an error message.** When the HTTP library rejects a request header,
11
+ its message quoted the value. The SDK now replaces the key with `***` before raising
12
+ `LifeAstroConnectionError`.
13
+ - **Clear error for a reply that is not JSON.** Such a reply did not come from the API: a proxy,
14
+ firewall or CDN in between answered, usually with an HTML page. It now raises the error of its
15
+ HTTP status with `code == "non_json_response"`; the message gives the status and the start of
16
+ the body.
17
+ - README: what to do on a Python older than 3.9, the `proxy=` argument on older httpx, and the
18
+ `non_json_response` error.
19
+
20
+ **Changes that may need a code change**
21
+
22
+ - A 200 reply with a body that is not JSON now raises instead of returning the text.
23
+ Before: `text = client.request(path)` gave you the body as a `str`.
24
+ Now: `except LifeAstroError as err:` with `err.code == "non_json_response"`; `err.body` holds
25
+ the text.
26
+ - `numerology.full` requires `dob`. The API always required it; a call without it now raises
27
+ `TypeError` before any request is made, instead of a 400 from the API.
28
+ Before: `client.numerology.full(name="Arjun Mehta")` was accepted by the SDK.
29
+ Now: `client.numerology.full(dob="1990-01-15", name="Arjun Mehta")`
30
+
31
+ ## 0.3.0 — 2026-11-22
32
+
33
+ Upgrading from 0.2.0: your code keeps working. The install is the same and has no new dependency.
34
+
35
+ - **New: PDF reports.** `lifeastroapi.pdf` turns the JSON of every `client.reports.*` method into a
36
+ branded PDF, in all 10 languages, with one call: `kundli_lite_pdf(report, branding)`,
37
+ `match_making_pdf(...)`, and so on.
38
+ - The PDF is made on your machine, with Chrome, Chromium or Microsoft Edge (found
39
+ automatically) or with a Gotenberg service you run. Nothing is sent to LifeAstroAPI for it.
40
+ - Your branding: company name and footer line as you wrote them, logo, colours, and a watermark
41
+ on every page. The Brihad kundli follows your colours in headings, banners, contents, charts,
42
+ header and footer, and is saffron without a brand. A colour too pale to read prints darker.
43
+ - The Brihad kundli PDF has a table of contents with the real page numbers, a running header
44
+ and footer with your company name and footer line, bookmarks in the report's language and the
45
+ document title.
46
+ - `PdfOptions` for margins (side by side), paper size, landscape, printing without backgrounds,
47
+ your own header and footer, and timeouts. They apply to the reports and to your own HTML.
48
+ - For many PDFs, keep one browser open with `ChromePdfEngine`. In `asyncio` code use the
49
+ `*_pdf_async` functions: they do not block, and they stop when the task is cancelled.
50
+ - Only need HTML, for a browser or an app's web view? The `render_*_html` functions need no
51
+ browser and give the same HTML as the Node.js SDK. `A4_PRINT_OPTIONS` has the page size and
52
+ margins.
53
+ - A failed PDF raises `PdfError` (a `LifeAstroError`), whose `code` says what went wrong.
54
+ - **Fixed:** the `HouseSystem` type now has `"whole_sign"`, the name the API reads. The old
55
+ `"whole-sign"` got a 400 error from the API until 2026-11-21. The API now accepts it as an
56
+ alias and the type still lists it, so code that uses it keeps working and type-checking.
57
+ - **Punjabi (`pa`)** is now a complete language, prose included.
58
+
59
+ ## 0.2.0 — 2026-11-15
60
+
61
+ - New `prashna.kp_horary(number=..., lat=..., lon=..., tz=..., date=..., time=...)`: the KP horary
62
+ chart for a number from 1 to 249, cast for the moment and place of judgement. Returns the
63
+ horary ascendant (the first degree of that number's part), the 12 Placidus cusps with star, sub
64
+ and sub-sub lords and significators, the planets with KP lords and houses, planet significators,
65
+ the KP 4-step chain and the ruling planets. Uses the Krishnamurti ayanamsa unless `ayanamsa` is
66
+ sent. 30 credits. Same method as the Node.js SDK 0.13.0.
67
+ - `chart.kp_sublord` now also returns the KP ruling planets (`ruling_planets`), and
68
+ `chart.kp_house_significator` returns each cusp's significator planets, the houses every planet
69
+ signifies and the 4-step chain (new fields from the API; nothing removed).
70
+ - `chart.kp_sublord`'s `planet` and `chart.kp_house_significator`'s `cusp` are now optional. The
71
+ API never read them: it always returns every planet and all 12 cusps. Code that passes them
72
+ keeps working.
73
+ - 323 methods (322 endpoints).
74
+
75
+ ## 0.1.0 — 2026-11-15
76
+
77
+ First release of the official Python SDK.
78
+
79
+ - `LifeAstro` (blocking) and `AsyncLifeAstro` (`asyncio`) clients on `httpx`, the only runtime
80
+ dependency. Both are context managers and have `close()`. The API key comes from `api_key=`
81
+ or the `LIFEASTRO_API_KEY` environment variable.
82
+ - 322 methods in 23 resource groups (`client.panchang.basic(...)`, `client.chart.planets(...)`,
83
+ `client.western.natal.chart(...)`, ...): one method per endpoint, generated from the same
84
+ manifest as the Node.js SDK 0.8.0, with the Node method and argument names in snake_case.
85
+ - Keyword arguments mapped to the API's wire names: unprefixed `date` / `time` / `tz` / `lat` /
86
+ `lon` for a chart, `birth.*` for the natal chart of transit-style methods, `boy.*` / `girl.*`
87
+ for kundli matching and `personA.*` / `personB.*` for Western pairs. Moment methods send
88
+ today's date in the given `tz` when `date` is left out.
89
+ - `lang` on every Vedic method whose response carries names or text, sent as `lang` and
90
+ `locale`. `Locale` lists the 10 codes: `en`, `hi`, `mr`, `gu`, `bn`, `te`, `ta`, `kn`, `ml`
91
+ (complete) and `pa` (names and terms).
92
+ - Typed errors with `status`, `code`, `message` and `request_id`: `BadRequestError`,
93
+ `AuthenticationError`, `PaymentRequiredError`, `PermissionDeniedError`, `NotFoundError`,
94
+ `RateLimitError` (`retry_after`), `ServerError`, `LifeAstroConnectionError` and
95
+ `LifeAstroTimeoutError`.
96
+ - Automatic retries with exponential backoff on 429, 5xx, network errors and timeouts,
97
+ honouring `Retry-After`; per-call `request_options={"timeout": ..., "raw": ...}`.
98
+ - `on_response` hook, as a client argument and per call (`request_options={"on_response": ...}`):
99
+ receives a `ResponseInfo` with the request id, `credits_remaining`, the rate limit
100
+ (`RateLimit(limit, remaining, reset_at)`), the cache result and the answer's language for every
101
+ call, success or error. Exported `ResponseInfo`, `RateLimit` and `ResponseHook`. See "Credits,
102
+ rate limit and request id" in the README. Same as the Node SDK 0.10.0 `onResponse`.
103
+ - `client.request(path, query)` / `client.get(...)` to call any `/v1/*` endpoint directly.
104
+ - Responses are the parsed JSON (`dict` / `list`). Full type hints, `py.typed`, checked with
105
+ `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.2.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: 1.0.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,8 +10,8 @@ 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
14
- Classifier: Development Status :: 4 - Beta
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
+ Classifier: Development Status :: 5 - Production/Stable
15
15
  Classifier: Intended Audience :: Developers
16
16
  Classifier: Operating System :: OS Independent
17
17
  Classifier: Programming Language :: Python
@@ -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.
@@ -59,6 +61,17 @@ location-aware calculations and pay-per-call billing. Free tier: 1,500 credits a
59
61
  pip install lifeastroapi
60
62
  ```
61
63
 
64
+ **Python 3.9 or later is required.** On an older Python, `pip` answers "No matching distribution
65
+ found". There you can call the API with the standard library alone:
66
+
67
+ ```python
68
+ import json, urllib.request
69
+
70
+ url = "https://api.lifeastroapi.com/v1/panchang/basic?lat=19.076&lon=72.8777&tz=Asia/Kolkata&date=2026-11-20"
71
+ req = urllib.request.Request(url, headers={"Authorization": "Bearer dv_live_..."})
72
+ day = json.load(urllib.request.urlopen(req, timeout=30))
73
+ ```
74
+
62
75
  Get an API key at **https://lifeastroapi.com/dashboard/keys**.
63
76
 
64
77
  ## Quick start
@@ -125,7 +138,7 @@ asyncio.run(main())
125
138
  Every method of `LifeAstro` exists on `AsyncLifeAstro` with the same arguments, as a coroutine.
126
139
 
127
140
  More in [examples/](https://github.com/ayanshulife/lifeastroapi-python/tree/main/examples):
128
- quick start, async calls, and error handling.
141
+ quick start, async calls, error handling and PDF reports.
129
142
 
130
143
  ## Authentication
131
144
 
@@ -162,6 +175,9 @@ client = LifeAstro(
162
175
  )
163
176
  ```
164
177
 
178
+ The `proxy=` argument of `httpx.Client` needs httpx 0.26 or later; on an older httpx write
179
+ `httpx.Client(proxies="http://proxy:3128")`.
180
+
165
181
  Both clients are context managers (`with` / `async with`) and have `close()`
166
182
  (a coroutine on `AsyncLifeAstro`). The SDK closes only the httpx client it created itself, never
167
183
  one you pass in.
@@ -249,7 +265,7 @@ chart = client.chart.planets(**arjun, lang="ta")
249
265
  | `ta` | Tamil | complete |
250
266
  | `kn` | Kannada | complete |
251
267
  | `ml` | Malayalam | complete |
252
- | `pa` | Punjabi | names and terms; longer prose is still English |
268
+ | `pa` | Punjabi | complete |
253
269
 
254
270
  - The `Locale` type lists the codes, and `LOCALES` holds them as a tuple.
255
271
  - **Where it works:** `panchang`, `calendar`, `festivals`, `eclipses`, `planet_moments`,
@@ -286,7 +302,7 @@ chart = client.chart.planets(**arjun, lang="ta")
286
302
  | `ashtakavarga` | sarva, bhinna (per planet), kaksha, transit score |
287
303
  | `geo` | place search, reverse geocoding, time zone, place by id |
288
304
  | `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 |
305
+ | `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
306
  | `narrative` | authored Vedic readings (lagna, planets, yogas, doshas, dasha phal, transit phal, prashna, horoscopes, ...) |
291
307
  | `remedies` | remedies by rule id, `for_graha`, mantra, pooja, vrat, daan, rudraksha, yantra, Lal Kitab |
292
308
  | `lalkitab` | Lal Kitab chart and dasha |
@@ -349,6 +365,11 @@ except LifeAstroError as err:
349
365
  | `ServerError` | 5xx |
350
366
  | `LifeAstroConnectionError` | network failure, no response (`status == 0`) |
351
367
  | `LifeAstroTimeoutError` | the request timed out (a `LifeAstroConnectionError`) |
368
+ | `lifeastroapi.pdf.PdfError` | a PDF could not be made (`status == 0`; see [PDF reports](#pdf-reports)) |
369
+
370
+ A response that is not JSON (an HTML page from a proxy or firewall in between, for example)
371
+ raises the error of its status with `code == "non_json_response"`; the message carries the HTTP
372
+ status and the start of the body.
352
373
 
353
374
  All of them extend `LifeAstroError`. Requests are retried automatically (`max_retries`, default
354
375
  2) on 408, 425, 429, 500, 502, 503, 504, network errors and timeouts, with exponential backoff
@@ -429,8 +450,261 @@ data = client.request(
429
450
 
430
451
  ## PDF reports
431
452
 
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.
453
+ `lifeastroapi.pdf` turns the JSON of any `reports.*` method into a branded, print-ready PDF
454
+ (kundli lite, detailed and Brihad, match making, mangal dosha, sade sati, varshaphal, numerology,
455
+ dasha analysis, horoscopes) in all 10 languages. It is part of the normal install.
456
+
457
+ The PDF is made on **your** machine. LifeAstroAPI returns the report JSON (that call costs the
458
+ report's credits); turning it into HTML and PDF costs nothing and sends nothing to LifeAstroAPI.
459
+
460
+ ```python
461
+ from lifeastroapi import LifeAstro
462
+ from lifeastroapi.pdf import kundli_detailed_pdf
463
+
464
+ report = LifeAstro().reports.kundli_detailed(**arjun, name="Arjun Mehta", lang="hi")
465
+ pdf = kundli_detailed_pdf(report, {"company_name": "Acme Astro", "primary_color": "#6b21a8"})
466
+ with open("kundli.pdf", "wb") as file:
467
+ file.write(pdf)
468
+ ```
469
+
470
+ Pass what the client returned: there is nothing to convert. The PDF is in the `lang` you
471
+ requested the report in.
472
+
473
+ | `client.reports.` | HTML | PDF |
474
+ |---|---|---|
475
+ | `kundli_lite` | `render_kundli_lite_html` | `kundli_lite_pdf` |
476
+ | `kundli_detailed` | `render_kundli_detailed_html` | `kundli_detailed_pdf` |
477
+ | `kundli_brihad` | `render_kundli_brihad_html` | `kundli_brihad_pdf` (table of contents, running header, bookmarks) |
478
+ | `match_making` | `render_match_making_html` | `match_making_pdf` |
479
+ | `mangal_dosha` | `render_mangal_dosha_html` | `mangal_dosha_pdf` |
480
+ | `sade_sati` | `render_sade_sati_html` | `sade_sati_pdf` |
481
+ | `varshaphal` | `render_varshaphal_html` | `varshaphal_pdf` |
482
+ | `numerology` | `render_numerology_html` | `numerology_pdf` |
483
+ | `dasha_analysis` | `render_dasha_analysis_html` | `dasha_analysis_pdf` |
484
+ | `horoscope_daily`, `horoscope_weekly`, `horoscope_monthly` | `render_horoscope_html` | `horoscope_pdf` |
485
+
486
+ Every `*_pdf` function has a `*_pdf_async` twin. `html_to_pdf` and `html_to_pdf_async` print your
487
+ own HTML. The `render_*_html` functions are pure Python (no browser, process, file or network
488
+ access) and give the same bytes as the Node.js SDK.
489
+
490
+ ### The browser and fonts
491
+
492
+ A PDF needs Chrome, Chromium or Microsoft Edge on the machine that makes it, and fonts for the
493
+ scripts you print (a missing font shows as empty boxes):
494
+
495
+ | Where it prints | Browser | Fonts for the Indian scripts |
496
+ |---|---|---|
497
+ | Debian, Ubuntu, Docker | `chromium`, or Google Chrome | `fonts-noto-core` |
498
+ | Other Linux | Chrome, Chromium or Edge | Noto Sans for Devanagari, Bengali, Gujarati, Gurmukhi, Tamil, Telugu, Kannada, Malayalam |
499
+ | macOS | Chrome, Chromium or Edge | the system fonts, or Noto Sans |
500
+ | Windows | Chrome, or Microsoft Edge | the system's Nirmala UI, or Noto Sans |
501
+ | Gotenberg | inside its image | inside its image |
502
+
503
+ ```dockerfile
504
+ FROM python:3.12-slim
505
+ RUN apt-get update \
506
+ && apt-get install -y --no-install-recommends chromium fonts-noto-core
507
+ RUN pip install lifeastroapi
508
+ ```
509
+
510
+ The browser is looked up in `LIFEASTRO_CHROME`, `CHROME_PATH` and `PUPPETEER_EXECUTABLE_PATH`,
511
+ then in the usual install locations. You can also pass `ChromePdfEngine(executable=...)`.
512
+ `--no-sandbox` is added only when the process runs as root, where Chrome cannot start without
513
+ it. Set `no_sandbox=` to decide yourself.
514
+
515
+ ### Reuse one browser
516
+
517
+ Without `engine=`, each call starts a browser and closes it. For more than one PDF, keep an
518
+ engine:
519
+
520
+ ```python
521
+ from lifeastroapi.pdf import ChromePdfEngine, kundli_lite_pdf
522
+
523
+ with ChromePdfEngine() as engine:
524
+ pdfs = [kundli_lite_pdf(report, engine=engine) for report in reports]
525
+ ```
526
+
527
+ The engine starts its browser on first use, can be shared between threads and tasks, and can be
528
+ created before a `fork`: each child process starts its own browser. `close()` (or
529
+ `await engine.aclose()`) stops the browser and deletes its temporary profile. Prints still
530
+ running then fail with `PdfError` (code `closed`). If the browser crashes, they fail with
531
+ `browser_failed` and the next call starts a new one. An engine left open is closed when the
532
+ process exits normally.
533
+
534
+ In Python, SIGTERM (`docker stop`, systemd, `timeout`) ends a process without a normal exit. In
535
+ your own script or worker, turn it into one, so that the browser is stopped too:
536
+
537
+ ```python
538
+ import signal
539
+ import sys
540
+
541
+ signal.signal(signal.SIGTERM, lambda *_: sys.exit(0))
542
+ ```
543
+
544
+ ### Django
545
+
546
+ ```python
547
+ # views.py
548
+ from django.http import HttpResponse
549
+ from lifeastroapi import LifeAstro
550
+ from lifeastroapi.pdf import ChromePdfEngine, kundli_lite_pdf
551
+
552
+ client = LifeAstro()
553
+ engine = ChromePdfEngine() # starts on first use
554
+
555
+
556
+ def kundli_pdf(request):
557
+ q = request.GET
558
+ report = client.reports.kundli_lite(
559
+ date=q["date"], time=q["time"], tz=q["tz"], lat=float(q["lat"]), lon=float(q["lon"])
560
+ )
561
+ pdf = kundli_lite_pdf(report, {"company_name": "Acme Astro"}, engine=engine)
562
+ response = HttpResponse(pdf, content_type="application/pdf")
563
+ response["Content-Disposition"] = 'attachment; filename="kundli.pdf"'
564
+ return response
565
+ ```
566
+
567
+ ### FastAPI
568
+
569
+ ```python
570
+ from contextlib import asynccontextmanager
571
+
572
+ from fastapi import FastAPI, Response
573
+ from lifeastroapi import AsyncLifeAstro
574
+ from lifeastroapi.pdf import ChromePdfEngine, kundli_lite_pdf_async
575
+
576
+
577
+ @asynccontextmanager
578
+ async def lifespan(app: FastAPI):
579
+ async with AsyncLifeAstro() as client, ChromePdfEngine() as engine:
580
+ app.state.client, app.state.engine = client, engine
581
+ yield
582
+
583
+
584
+ app = FastAPI(lifespan=lifespan)
585
+
586
+
587
+ @app.get("/kundli.pdf")
588
+ async def kundli(date: str, time: str, tz: str, lat: float, lon: float) -> Response:
589
+ report = await app.state.client.reports.kundli_lite(
590
+ date=date, time=time, tz=tz, lat=lat, lon=lon
591
+ )
592
+ pdf = await kundli_lite_pdf_async(report, engine=app.state.engine) # the loop stays free
593
+ return Response(pdf, media_type="application/pdf")
594
+ ```
595
+
596
+ ### Celery (and other job queues)
597
+
598
+ The Brihad kundli runs to a few hundred pages and prints twice, so make it in a background job:
599
+
600
+ ```python
601
+ from pathlib import Path
602
+
603
+ from celery import shared_task
604
+ from celery.signals import worker_process_shutdown
605
+ from lifeastroapi import LifeAstro
606
+ from lifeastroapi.pdf import ChromePdfEngine, PdfOptions, kundli_brihad_pdf
607
+
608
+ engine = ChromePdfEngine() # each worker process starts its own browser on first use
609
+ worker_process_shutdown.connect(lambda **_: engine.close(), weak=False)
610
+
611
+
612
+ @shared_task
613
+ def brihad_pdf(birth: dict, path: str) -> None:
614
+ with LifeAstro(timeout=120) as client:
615
+ report = client.reports.kundli_brihad(**birth)
616
+ pdf = kundli_brihad_pdf(report, engine=engine, options=PdfOptions(timeout=90))
617
+ Path(path).write_bytes(pdf)
618
+ ```
619
+
620
+ ### Without a browser: Gotenberg
621
+
622
+ Run [Gotenberg](https://gotenberg.dev) anywhere you control
623
+ (`docker run --rm -p 3000:3000 gotenberg/gotenberg:8`) and print through it:
624
+
625
+ ```python
626
+ from lifeastroapi.pdf import GotenbergPdfEngine, match_making_pdf
627
+
628
+ engine = GotenbergPdfEngine("http://localhost:3000") # headers={...} for auth
629
+ pdf = match_making_pdf(report, engine=engine)
630
+ ```
631
+
632
+ ### Desktop, mobile and the browser
633
+
634
+ Let your backend call the API and render, and print the HTML in the app's web view or in the
635
+ user's browser (Print, then "Save as PDF"). The API key stays on your server. The HTML sets A4
636
+ pages and margins in its own CSS. For print APIs that ignore CSS `@page` (iOS), send the
637
+ geometry along:
638
+
639
+ ```python
640
+ from lifeastroapi.pdf import A4_PRINT_OPTIONS, render_kundli_lite_html
641
+
642
+ payload = {"html": render_kundli_lite_html(report), "print": A4_PRINT_OPTIONS} # in points
643
+ ```
644
+
645
+ The Brihad table of contents, running header and bookmarks are added by `kundli_brihad_pdf`.
646
+
647
+ ### Branding
648
+
649
+ Every key is optional. What you pass wins over the `Branding` inside the report JSON.
650
+
651
+ ```python
652
+ from lifeastroapi.pdf import Branding
653
+
654
+ branding: Branding = {
655
+ "company_name": "Acme Astro",
656
+ "logo_url": "https://acme.example/logo.png", # https, or a data:image/... URI
657
+ "primary_color": "#6b21a8", # headings, banners, table headers, charts
658
+ "secondary_color": "#9333ea", # meta text, footer, gold details
659
+ "footer_text": "Acme Astro · www.acme.example",
660
+ "watermark_text": "SAMPLE", # on every page, behind the content
661
+ }
662
+ ```
663
+
664
+ Colours take any CSS form (`#6b21a8`, `rebeccapurple`, `rgb(...)`, `hsl(...)`). One that is too
665
+ pale to read on paper is printed darker. The Brihad kundli is saffron until you or the report give
666
+ a brand colour, and then follows it in headings, banners, contents, charts, header and footer. The
667
+ API's default colours in a report do not count as a brand. The company name and footer line print
668
+ as you wrote them. A blank value counts as not set.
669
+
670
+ The browser fetches the logo while it prints. If the branding comes from your own customers,
671
+ check the logo URL first, or run the browser without access to your internal network.
672
+
673
+ ### Options, timeouts and errors
674
+
675
+ ```python
676
+ import threading
677
+
678
+ from lifeastroapi.pdf import PdfError, PdfOptions, numerology_pdf
679
+
680
+ options = PdfOptions(
681
+ timeout=30, # seconds for the page, images and fonts to load
682
+ print_timeout=180, # seconds for each print; raise it for a long Brihad on a slow machine
683
+ )
684
+ cancel = threading.Event() # set it from another thread to stop the job
685
+ try:
686
+ pdf = numerology_pdf(report, options=options, cancel=cancel)
687
+ except PdfError as err:
688
+ print(err.code, err.message)
689
+ ```
690
+
691
+ The reports set A4 and their margins themselves. What you set in `PdfOptions` wins over that:
692
+
693
+ | Option | Effect |
694
+ |---|---|
695
+ | `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 |
696
+ | `format="Letter"` | `A3`, `A4`, `A5`, `Letter`, `Legal` or `Tabloid` paper |
697
+ | `landscape=True` | Landscape paper |
698
+ | `prefer_css_page_size` | `True` keeps the HTML's own page size, `False` scales the page to the paper |
699
+ | `print_background=False` | No background colours; text that is white on colour prints dark |
700
+ | `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 |
701
+ | `scale=0.9` | Render scale, 0.1 to 2 |
702
+
703
+ With the default options your HTML is printed untouched.
704
+
705
+ `err.code` is one of `browser_not_found`, `browser_failed`, `timeout`, `cancelled`, `closed`,
706
+ `gotenberg_failed` or `invalid_pdf`. The `*_pdf_async` functions stop when their task is
707
+ cancelled.
434
708
 
435
709
  ## Development
436
710
 
@@ -447,6 +721,18 @@ python3 -m venv .venv && .venv/bin/pip install -e ".[dev]"
447
721
  through its `scripts/manifest.mjs`, so it needs `node`), so both SDKs always have the same
448
722
  methods. `--costs-url <base url>` refreshes the credit costs from `GET /v1/meta/endpoints`.
449
723
 
724
+ The PDF templates in `src/lifeastroapi/pdf/_templates` are generated from the Node SDK's
725
+ TypeScript templates, so do not edit them by hand:
726
+
727
+ ```bash
728
+ node scripts/generate_pdf.mjs # regenerate the templates (needs the Node SDK's dev dependencies)
729
+ node scripts/pdf_goldens.mjs # regenerate tests/fixtures/pdf from the Node SDK
730
+ ```
731
+
732
+ The PDF tests compare the HTML byte for byte with Node. With `LIFEASTRO_PDF_WORK` pointing at the
733
+ shared PDF reference they also check every full report; that test is skipped without it, and the
734
+ browser tests are skipped without a browser.
735
+
450
736
  `scripts/live_sweep.py` calls every method once against a real server and lists the calls the
451
737
  API rejects. It spends credits (one call per endpoint) and has no default URL:
452
738