lifeastroapi 0.2.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.
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/CHANGELOG.md +28 -1
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/PKG-INFO +276 -8
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/README.md +273 -5
- lifeastroapi-0.3.0/examples/pdf_report.py +53 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/pyproject.toml +9 -3
- lifeastroapi-0.3.0/scripts/generate_pdf.mjs +1004 -0
- lifeastroapi-0.3.0/scripts/pdf_goldens.mjs +459 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/src/lifeastroapi/__init__.py +2 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/src/lifeastroapi/_version.py +1 -1
- lifeastroapi-0.3.0/src/lifeastroapi/pdf/__init__.py +136 -0
- lifeastroapi-0.3.0/src/lifeastroapi/pdf/_branding.py +115 -0
- lifeastroapi-0.3.0/src/lifeastroapi/pdf/_browser.py +316 -0
- lifeastroapi-0.3.0/src/lifeastroapi/pdf/_chrome.py +349 -0
- lifeastroapi-0.3.0/src/lifeastroapi/pdf/_devtools.py +140 -0
- lifeastroapi-0.3.0/src/lifeastroapi/pdf/_gotenberg.py +180 -0
- lifeastroapi-0.3.0/src/lifeastroapi/pdf/_js.py +754 -0
- lifeastroapi-0.3.0/src/lifeastroapi/pdf/_options.py +178 -0
- lifeastroapi-0.3.0/src/lifeastroapi/pdf/_outline.py +229 -0
- lifeastroapi-0.3.0/src/lifeastroapi/pdf/_print_css.py +90 -0
- lifeastroapi-0.3.0/src/lifeastroapi/pdf/_reports.py +652 -0
- lifeastroapi-0.3.0/src/lifeastroapi/pdf/_templates/__init__.py +1 -0
- lifeastroapi-0.3.0/src/lifeastroapi/pdf/_templates/colors.py +334 -0
- lifeastroapi-0.3.0/src/lifeastroapi/pdf/_templates/dasha_analysis.py +666 -0
- lifeastroapi-0.3.0/src/lifeastroapi/pdf/_templates/horoscope.py +435 -0
- lifeastroapi-0.3.0/src/lifeastroapi/pdf/_templates/kundli_brihad.py +3300 -0
- lifeastroapi-0.3.0/src/lifeastroapi/pdf/_templates/kundli_brihad_sections.py +1609 -0
- lifeastroapi-0.3.0/src/lifeastroapi/pdf/_templates/kundli_detailed.py +624 -0
- lifeastroapi-0.3.0/src/lifeastroapi/pdf/_templates/kundli_lite.py +364 -0
- lifeastroapi-0.3.0/src/lifeastroapi/pdf/_templates/locales.py +376 -0
- lifeastroapi-0.3.0/src/lifeastroapi/pdf/_templates/mangal_dosha.py +977 -0
- lifeastroapi-0.3.0/src/lifeastroapi/pdf/_templates/match_making.py +851 -0
- lifeastroapi-0.3.0/src/lifeastroapi/pdf/_templates/north_indian_chart.py +382 -0
- lifeastroapi-0.3.0/src/lifeastroapi/pdf/_templates/numerology.py +772 -0
- lifeastroapi-0.3.0/src/lifeastroapi/pdf/_templates/planet_glyphs.py +157 -0
- lifeastroapi-0.3.0/src/lifeastroapi/pdf/_templates/sade_sati.py +872 -0
- lifeastroapi-0.3.0/src/lifeastroapi/pdf/_templates/shared.py +582 -0
- lifeastroapi-0.3.0/src/lifeastroapi/pdf/_templates/varshaphal.py +694 -0
- lifeastroapi-0.3.0/src/lifeastroapi/pdf/_threads.py +68 -0
- lifeastroapi-0.3.0/src/lifeastroapi/pdf/_websocket.py +180 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/src/lifeastroapi/types.py +5 -4
- lifeastroapi-0.3.0/tests/pdf_devtools_stub.py +163 -0
- lifeastroapi-0.3.0/tests/pdf_support.py +113 -0
- lifeastroapi-0.3.0/tests/test_pdf_branding_options.py +993 -0
- lifeastroapi-0.3.0/tests/test_pdf_chrome.py +286 -0
- lifeastroapi-0.3.0/tests/test_pdf_engine.py +555 -0
- lifeastroapi-0.3.0/tests/test_pdf_gotenberg.py +164 -0
- lifeastroapi-0.3.0/tests/test_pdf_js.py +125 -0
- lifeastroapi-0.3.0/tests/test_pdf_outline.py +110 -0
- lifeastroapi-0.3.0/tests/test_pdf_settle.py +411 -0
- lifeastroapi-0.3.0/tests/test_pdf_templates.py +483 -0
- lifeastroapi-0.3.0/tests/test_version.py +30 -0
- lifeastroapi-0.2.0/tests/test_version.py +0 -15
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/.gitignore +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/LICENSE +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/examples/async_example.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/examples/error_handling.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/examples/quickstart.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/scripts/costs.json +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/scripts/generate.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/scripts/live_sweep.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/scripts/manifest.json +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/scripts/samples.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/src/lifeastroapi/_client.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/src/lifeastroapi/_core.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/src/lifeastroapi/_http.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/src/lifeastroapi/_params.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/src/lifeastroapi/errors.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/src/lifeastroapi/py.typed +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/__init__.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/ashtakavarga.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/calendar.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/chart.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/dasha.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/eclipses.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/festivals.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/geo.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/horoscope.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/lalkitab.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/meta.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/milan.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/muhurta.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/narrative.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/numerology.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/panchang.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/planet_moments.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/prashna.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/remedies.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/reports.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/tarot.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/transit.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/varshaphal.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/src/lifeastroapi/resources/western.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/tests/conftest.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/tests/fixtures/examples.json +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/tests/test_async_client.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/tests/test_client.py +0 -0
- {lifeastroapi-0.2.0 → lifeastroapi-0.3.0}/tests/test_manifest.py +0 -0
|
@@ -1,5 +1,33 @@
|
|
|
1
1
|
# Changelog
|
|
2
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
|
+
|
|
3
31
|
## 0.2.0 — 2026-11-15
|
|
4
32
|
|
|
5
33
|
- New `prashna.kp_horary(number=..., lat=..., lon=..., tz=..., date=..., time=...)`: the KP horary
|
|
@@ -47,4 +75,3 @@ First release of the official Python SDK.
|
|
|
47
75
|
- `client.request(path, query)` / `client.get(...)` to call any `/v1/*` endpoint directly.
|
|
48
76
|
- Responses are the parsed JSON (`dict` / `list`). Full type hints, `py.typed`, checked with
|
|
49
77
|
`mypy --strict`. Every method's docstring has the endpoint description, credit cost and path.
|
|
50
|
-
- Not in this version: branded PDF rendering of `reports.*` (the Node SDK's `lifeastroapi/pdf`).
|
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
Metadata-Version: 2.5
|
|
2
2
|
Name: lifeastroapi
|
|
3
|
-
Version: 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
|
|
@@ -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
|
|
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 |
|
|
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`,
|
|
@@ -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
|
-
|
|
433
|
-
|
|
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
|
|