weblitz 2.0.0b10__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.
Potentially problematic release.
This version of weblitz might be problematic. Click here for more details.
- weblitz-2.0.0b10/PKG-INFO +49 -0
- weblitz-2.0.0b10/README.md +32 -0
- weblitz-2.0.0b10/pyproject.toml +32 -0
- weblitz-2.0.0b10/setup.cfg +4 -0
- weblitz-2.0.0b10/src/weblitz/__init__.py +109 -0
- weblitz-2.0.0b10/src/weblitz/_calls.py +117 -0
- weblitz-2.0.0b10/src/weblitz/_engine.py +518 -0
- weblitz-2.0.0b10/src/weblitz/_frames.py +207 -0
- weblitz-2.0.0b10/src/weblitz/_requests.py +188 -0
- weblitz-2.0.0b10/src/weblitz/_resolve.py +63 -0
- weblitz-2.0.0b10/src/weblitz/_types.py +105 -0
- weblitz-2.0.0b10/src/weblitz/_worker.py +494 -0
- weblitz-2.0.0b10/src/weblitz/errors.py +49 -0
- weblitz-2.0.0b10/src/weblitz/py.typed +0 -0
- weblitz-2.0.0b10/src/weblitz.egg-info/PKG-INFO +49 -0
- weblitz-2.0.0b10/src/weblitz.egg-info/SOURCES.txt +16 -0
- weblitz-2.0.0b10/src/weblitz.egg-info/dependency_links.txt +1 -0
- weblitz-2.0.0b10/src/weblitz.egg-info/top_level.txt +1 -0
|
@@ -0,0 +1,49 @@
|
|
|
1
|
+
Metadata-Version: 2.4
|
|
2
|
+
Name: weblitz
|
|
3
|
+
Version: 2.0.0b10
|
|
4
|
+
Summary: HTML, URLs, RDLC reports and Markdown to PDF, Word, Excel and PowerPoint, as Chrome prints them, with no browser.
|
|
5
|
+
Author: SSRS2
|
|
6
|
+
License: Proprietary: see LICENSE.md
|
|
7
|
+
Project-URL: Homepage, https://weblitzpdf.com
|
|
8
|
+
Keywords: pdf,html-to-pdf,rdlc,report,playwright,print,docx,xlsx,pptx
|
|
9
|
+
Classifier: Programming Language :: Python :: 3
|
|
10
|
+
Classifier: Operating System :: POSIX :: Linux
|
|
11
|
+
Classifier: Operating System :: MacOS
|
|
12
|
+
Classifier: Operating System :: Microsoft :: Windows
|
|
13
|
+
Classifier: Topic :: Printing
|
|
14
|
+
Classifier: Topic :: Office/Business
|
|
15
|
+
Requires-Python: >=3.9
|
|
16
|
+
Description-Content-Type: text/markdown
|
|
17
|
+
|
|
18
|
+
# weblitz
|
|
19
|
+
|
|
20
|
+
HTML, URLs, RDLC reports and Markdown to PDF, Word, Excel and PowerPoint, as Chrome prints them, with no browser.
|
|
21
|
+
|
|
22
|
+
```python
|
|
23
|
+
import weblitz
|
|
24
|
+
|
|
25
|
+
weblitz.render_html("<h1>Hello</h1>", format="A4", margin={"top": "2cm"}).save("hello.pdf")
|
|
26
|
+
weblitz.render_url("https://example.com", print_background=True, path="example.pdf")
|
|
27
|
+
weblitz.render_html(page, output="xlsx").save("page.xlsx")
|
|
28
|
+
weblitz.render_url("https://example.com", output="png", viewport={"width": 1280, "device_scale_factor": 2}, path="example.png")
|
|
29
|
+
```
|
|
30
|
+
|
|
31
|
+
The options of `render_html` and `render_url` are Playwright's `page.pdf()` options by their Python names. Every call
|
|
32
|
+
answers a `Result` (`file`, `content_type`, `extension`, `pages`, `notes`, `trial`) or raises `WeblitzError`, whose
|
|
33
|
+
`code` says why.
|
|
34
|
+
|
|
35
|
+
`output="png"` (or `"jpeg"`, `"webp"`, `"tiff"`) draws the page instead of printing it, with Playwright's screenshot
|
|
36
|
+
names: by default the whole page as a screen shows it, in one image, laid out in an 800 by 600 window in screen media;
|
|
37
|
+
`capture="viewport"` (or `full_page=False`) the window alone; `capture="pages"` each printed page as the PDF prints it
|
|
38
|
+
(paper, margins, `page_ranges`), answered as a ZIP of `page-1.png`, `page-2.png`... (a TIFF holds every page in one
|
|
39
|
+
file). `viewport={"width": ..., "height": ..., "device_scale_factor": 2}` sets the window and the image's pixels per
|
|
40
|
+
CSS pixel, `quality` a JPEG's or WebP's (0 to 100).
|
|
41
|
+
|
|
42
|
+
Calls go to a pool of worker processes kept warm, started on first use. `weblitz.configure(...)` sets its options
|
|
43
|
+
(`workers`, `concurrency`, `license`, `timeout` in milliseconds...); `weblitz.Engine` is a pool of your own and
|
|
44
|
+
`weblitz.AsyncEngine` the same for asyncio (cancelling the awaiting task cancels the render).
|
|
45
|
+
|
|
46
|
+
Without a licence key (`license=` or the environment's `SSRS2_LICENSE`) PDF and image pages carry a trial watermark.
|
|
47
|
+
|
|
48
|
+
Wheels exist for Linux with glibc (x64, arm64) and macOS on Apple silicon; Alpine and other musl systems are not
|
|
49
|
+
supported yet.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
# weblitz
|
|
2
|
+
|
|
3
|
+
HTML, URLs, RDLC reports and Markdown to PDF, Word, Excel and PowerPoint, as Chrome prints them, with no browser.
|
|
4
|
+
|
|
5
|
+
```python
|
|
6
|
+
import weblitz
|
|
7
|
+
|
|
8
|
+
weblitz.render_html("<h1>Hello</h1>", format="A4", margin={"top": "2cm"}).save("hello.pdf")
|
|
9
|
+
weblitz.render_url("https://example.com", print_background=True, path="example.pdf")
|
|
10
|
+
weblitz.render_html(page, output="xlsx").save("page.xlsx")
|
|
11
|
+
weblitz.render_url("https://example.com", output="png", viewport={"width": 1280, "device_scale_factor": 2}, path="example.png")
|
|
12
|
+
```
|
|
13
|
+
|
|
14
|
+
The options of `render_html` and `render_url` are Playwright's `page.pdf()` options by their Python names. Every call
|
|
15
|
+
answers a `Result` (`file`, `content_type`, `extension`, `pages`, `notes`, `trial`) or raises `WeblitzError`, whose
|
|
16
|
+
`code` says why.
|
|
17
|
+
|
|
18
|
+
`output="png"` (or `"jpeg"`, `"webp"`, `"tiff"`) draws the page instead of printing it, with Playwright's screenshot
|
|
19
|
+
names: by default the whole page as a screen shows it, in one image, laid out in an 800 by 600 window in screen media;
|
|
20
|
+
`capture="viewport"` (or `full_page=False`) the window alone; `capture="pages"` each printed page as the PDF prints it
|
|
21
|
+
(paper, margins, `page_ranges`), answered as a ZIP of `page-1.png`, `page-2.png`... (a TIFF holds every page in one
|
|
22
|
+
file). `viewport={"width": ..., "height": ..., "device_scale_factor": 2}` sets the window and the image's pixels per
|
|
23
|
+
CSS pixel, `quality` a JPEG's or WebP's (0 to 100).
|
|
24
|
+
|
|
25
|
+
Calls go to a pool of worker processes kept warm, started on first use. `weblitz.configure(...)` sets its options
|
|
26
|
+
(`workers`, `concurrency`, `license`, `timeout` in milliseconds...); `weblitz.Engine` is a pool of your own and
|
|
27
|
+
`weblitz.AsyncEngine` the same for asyncio (cancelling the awaiting task cancels the render).
|
|
28
|
+
|
|
29
|
+
Without a licence key (`license=` or the environment's `SSRS2_LICENSE`) PDF and image pages carry a trial watermark.
|
|
30
|
+
|
|
31
|
+
Wheels exist for Linux with glibc (x64, arm64) and macOS on Apple silicon; Alpine and other musl systems are not
|
|
32
|
+
supported yet.
|
|
@@ -0,0 +1,32 @@
|
|
|
1
|
+
[build-system]
|
|
2
|
+
requires = ["setuptools>=68"]
|
|
3
|
+
build-backend = "setuptools.build_meta"
|
|
4
|
+
|
|
5
|
+
[project]
|
|
6
|
+
name = "weblitz"
|
|
7
|
+
version = "2.0.0b10"
|
|
8
|
+
description = "HTML, URLs, RDLC reports and Markdown to PDF, Word, Excel and PowerPoint, as Chrome prints them, with no browser."
|
|
9
|
+
readme = "README.md"
|
|
10
|
+
requires-python = ">=3.9"
|
|
11
|
+
license = { text = "Proprietary: see LICENSE.md" }
|
|
12
|
+
authors = [{ name = "SSRS2" }]
|
|
13
|
+
keywords = ["pdf", "html-to-pdf", "rdlc", "report", "playwright", "print", "docx", "xlsx", "pptx"]
|
|
14
|
+
classifiers = [
|
|
15
|
+
"Programming Language :: Python :: 3",
|
|
16
|
+
"Operating System :: POSIX :: Linux",
|
|
17
|
+
"Operating System :: MacOS",
|
|
18
|
+
"Operating System :: Microsoft :: Windows",
|
|
19
|
+
"Topic :: Printing",
|
|
20
|
+
"Topic :: Office/Business",
|
|
21
|
+
]
|
|
22
|
+
dependencies = []
|
|
23
|
+
|
|
24
|
+
[project.urls]
|
|
25
|
+
Homepage = "https://weblitzpdf.com"
|
|
26
|
+
|
|
27
|
+
[tool.setuptools.packages.find]
|
|
28
|
+
where = ["src"]
|
|
29
|
+
|
|
30
|
+
[tool.setuptools.package-data]
|
|
31
|
+
# A platform wheel carries the worker under weblitz/_worker/: scripts/build_wheels.py writes it (setuptools builds the sdist only).
|
|
32
|
+
weblitz = ["_worker/**/*", "py.typed"]
|
|
@@ -0,0 +1,109 @@
|
|
|
1
|
+
"""
|
|
2
|
+
HTML, URLs, RDLC reports and Markdown to PDF, Word, Excel and PowerPoint, as Chrome prints them, with no browser.
|
|
3
|
+
|
|
4
|
+
import weblitz
|
|
5
|
+
weblitz.render_html("<h1>Hello</h1>", format="A4").save("hello.pdf")
|
|
6
|
+
|
|
7
|
+
The functions below use one engine (a pool of worker processes kept warm) started on first use; ``configure`` sets its
|
|
8
|
+
options. ``Engine`` and ``AsyncEngine`` are pools of your own.
|
|
9
|
+
"""
|
|
10
|
+
|
|
11
|
+
from __future__ import annotations
|
|
12
|
+
|
|
13
|
+
import threading
|
|
14
|
+
from typing import Any, Dict, Mapping, Optional, Sequence, Tuple
|
|
15
|
+
|
|
16
|
+
from ._engine import AsyncEngine, Engine, default_workers
|
|
17
|
+
from ._requests import FileInput
|
|
18
|
+
from ._resolve import PLATFORMS, platform_key, resolve_worker
|
|
19
|
+
from ._types import Answer, CheckResult, Note, Result
|
|
20
|
+
from ._worker import PROTOCOL
|
|
21
|
+
from .errors import WeblitzError
|
|
22
|
+
|
|
23
|
+
__version__ = "2.0.0b10"
|
|
24
|
+
|
|
25
|
+
__all__ = [
|
|
26
|
+
"AsyncEngine",
|
|
27
|
+
"Answer",
|
|
28
|
+
"CheckResult",
|
|
29
|
+
"Engine",
|
|
30
|
+
"FileInput",
|
|
31
|
+
"Note",
|
|
32
|
+
"PLATFORMS",
|
|
33
|
+
"PROTOCOL",
|
|
34
|
+
"Result",
|
|
35
|
+
"WeblitzError",
|
|
36
|
+
"check_report",
|
|
37
|
+
"configure",
|
|
38
|
+
"default_engine",
|
|
39
|
+
"default_workers",
|
|
40
|
+
"import_report",
|
|
41
|
+
"info",
|
|
42
|
+
"markdown_to",
|
|
43
|
+
"platform_key",
|
|
44
|
+
"render_html",
|
|
45
|
+
"render_report",
|
|
46
|
+
"render_url",
|
|
47
|
+
"resolve_worker",
|
|
48
|
+
]
|
|
49
|
+
|
|
50
|
+
_lock = threading.Lock()
|
|
51
|
+
_shared: Optional[Engine] = None
|
|
52
|
+
_options: Dict[str, Any] = {}
|
|
53
|
+
|
|
54
|
+
|
|
55
|
+
def default_engine() -> Engine:
|
|
56
|
+
"""The engine the functions below use, started on first use with the options of ``configure``."""
|
|
57
|
+
global _shared
|
|
58
|
+
with _lock:
|
|
59
|
+
if _shared is None or _shared.closed:
|
|
60
|
+
_shared = Engine(**_options)
|
|
61
|
+
return _shared
|
|
62
|
+
|
|
63
|
+
|
|
64
|
+
def configure(**options: Any) -> None:
|
|
65
|
+
"""The default engine's options (workers, license, timeout, worker_path...): Engine's. Its workers so far end
|
|
66
|
+
once their calls have."""
|
|
67
|
+
global _shared, _options
|
|
68
|
+
Engine(**options)._pool.close() # the options checked now, not at the first call
|
|
69
|
+
with _lock:
|
|
70
|
+
_options = dict(options)
|
|
71
|
+
old, _shared = _shared, None
|
|
72
|
+
if old is not None:
|
|
73
|
+
old._pool.close()
|
|
74
|
+
|
|
75
|
+
|
|
76
|
+
def render_html(html: str, **options: Any) -> Result:
|
|
77
|
+
"""HTML to a PDF, as Chrome prints it, with no browser (or a picture, an Excel, Word or PowerPoint file: ``output``).
|
|
78
|
+
Options are Playwright's ``page.pdf()`` and screenshot ones: Engine.render_html's."""
|
|
79
|
+
return default_engine().render_html(html, **options)
|
|
80
|
+
|
|
81
|
+
|
|
82
|
+
def render_url(url: str, **options: Any) -> Result:
|
|
83
|
+
"""A web page to a PDF, after its scripts ran, as Chrome prints it."""
|
|
84
|
+
return default_engine().render_url(url, **options)
|
|
85
|
+
|
|
86
|
+
|
|
87
|
+
def render_report(definition: FileInput, **options: Any) -> Result:
|
|
88
|
+
"""An RDLC or RDL report with its rows to PDF, Word, Excel, PowerPoint, images, HTML, CSV or XML."""
|
|
89
|
+
return default_engine().render_report(definition, **options)
|
|
90
|
+
|
|
91
|
+
|
|
92
|
+
def check_report(definition: FileInput, **options: Any) -> CheckResult:
|
|
93
|
+
"""A report's problems without rendering it."""
|
|
94
|
+
return default_engine().check_report(definition, **options)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def markdown_to(markdown: FileInput, format: str, **options: Any) -> Result:
|
|
98
|
+
"""Markdown to a PowerPoint deck, a Word document or a PDF."""
|
|
99
|
+
return default_engine().markdown_to(markdown, format, **options)
|
|
100
|
+
|
|
101
|
+
|
|
102
|
+
def import_report(file: FileInput, file_name: Optional[str] = None, **options: Any) -> Result:
|
|
103
|
+
"""Another tool's report as an RDLC."""
|
|
104
|
+
return default_engine().import_report(file, file_name, **options)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def info() -> Dict[str, Any]:
|
|
108
|
+
"""What the worker says of itself."""
|
|
109
|
+
return default_engine().info()
|
|
@@ -0,0 +1,117 @@
|
|
|
1
|
+
"""Each operation as a request, its parts and how its answer reads: shared by Engine and AsyncEngine."""
|
|
2
|
+
|
|
3
|
+
from __future__ import annotations
|
|
4
|
+
|
|
5
|
+
from dataclasses import dataclass
|
|
6
|
+
from typing import Any, Callable, Dict, List, Mapping, Optional, Tuple
|
|
7
|
+
|
|
8
|
+
from . import _requests as R
|
|
9
|
+
from ._types import Answer, CheckResult, Result
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
@dataclass
|
|
13
|
+
class Call:
|
|
14
|
+
request: Dict[str, Any]
|
|
15
|
+
parts: List[Tuple[str, bytes]]
|
|
16
|
+
read: Callable[[Answer], Any]
|
|
17
|
+
timeout: Optional[float] = None
|
|
18
|
+
path: Any = None
|
|
19
|
+
|
|
20
|
+
|
|
21
|
+
def _result(answer: Answer) -> Result:
|
|
22
|
+
return Result.of(answer)
|
|
23
|
+
|
|
24
|
+
|
|
25
|
+
def html(source: Dict[str, Any], *, timeout=None, path=None, base_url=None, output=None, **options: Any) -> Call:
|
|
26
|
+
request: Dict[str, Any] = {"op": "html", **source}
|
|
27
|
+
if base_url is not None:
|
|
28
|
+
request["baseUrl"] = base_url
|
|
29
|
+
if output is not None:
|
|
30
|
+
request["output"] = output
|
|
31
|
+
engine_options = R.html_options(options)
|
|
32
|
+
if engine_options:
|
|
33
|
+
request["options"] = engine_options
|
|
34
|
+
return Call(request, [], _result, timeout, path)
|
|
35
|
+
|
|
36
|
+
|
|
37
|
+
def report(
|
|
38
|
+
definition: R.FileInput,
|
|
39
|
+
*,
|
|
40
|
+
format: str = "PDF",
|
|
41
|
+
datasets: Optional[Mapping[str, Any]] = None,
|
|
42
|
+
parameters: Optional[Mapping[str, Any]] = None,
|
|
43
|
+
device_info: Optional[Mapping[str, Any]] = None,
|
|
44
|
+
subreports: Optional[Mapping[str, R.FileInput]] = None,
|
|
45
|
+
restricted_code: Optional[bool] = None,
|
|
46
|
+
timeout=None,
|
|
47
|
+
path=None,
|
|
48
|
+
**rest: Any,
|
|
49
|
+
) -> Call:
|
|
50
|
+
R.refuse_unknown(rest, "render_report")
|
|
51
|
+
parts = R.Parts()
|
|
52
|
+
request: Dict[str, Any] = {"op": "report", "definition": parts.file("definition", definition), "format": format or "PDF"}
|
|
53
|
+
if datasets is not None:
|
|
54
|
+
request["datasets"] = R.datasets(datasets)
|
|
55
|
+
if parameters is not None:
|
|
56
|
+
request["parameters"] = R.jsonable(dict(parameters))
|
|
57
|
+
if device_info is not None:
|
|
58
|
+
request["deviceInfo"] = R.jsonable(dict(device_info))
|
|
59
|
+
if subreports is not None:
|
|
60
|
+
request["subreports"] = parts.files("subreport", subreports)
|
|
61
|
+
if restricted_code is not None:
|
|
62
|
+
request["restrictedCode"] = bool(restricted_code)
|
|
63
|
+
return Call(request, parts.list, _result, timeout, path)
|
|
64
|
+
|
|
65
|
+
|
|
66
|
+
def check(definition: R.FileInput, *, subreports: Optional[Mapping[str, R.FileInput]] = None, timeout=None, **rest: Any) -> Call:
|
|
67
|
+
R.refuse_unknown(rest, "check_report")
|
|
68
|
+
parts = R.Parts()
|
|
69
|
+
request: Dict[str, Any] = {"op": "check", "definition": parts.file("definition", definition)}
|
|
70
|
+
if subreports is not None:
|
|
71
|
+
request["subreports"] = parts.files("subreport", subreports)
|
|
72
|
+
return Call(request, parts.list, CheckResult.of, timeout)
|
|
73
|
+
|
|
74
|
+
|
|
75
|
+
def markdown(
|
|
76
|
+
markdown: R.FileInput,
|
|
77
|
+
format: str,
|
|
78
|
+
*,
|
|
79
|
+
datasets: Optional[Mapping[str, Any]] = None,
|
|
80
|
+
parameters: Optional[Mapping[str, Any]] = None,
|
|
81
|
+
timeout=None,
|
|
82
|
+
path=None,
|
|
83
|
+
**rest: Any,
|
|
84
|
+
) -> Call:
|
|
85
|
+
R.refuse_unknown(rest, "markdown_to")
|
|
86
|
+
if not isinstance(format, str) or not format:
|
|
87
|
+
raise TypeError("markdown_to() takes a format: pptx, docx, pdf...")
|
|
88
|
+
parts = R.Parts()
|
|
89
|
+
request: Dict[str, Any] = {"op": "markdown", "markdown": parts.file("markdown", markdown), "format": format}
|
|
90
|
+
if datasets is not None:
|
|
91
|
+
request["datasets"] = R.datasets(datasets)
|
|
92
|
+
if parameters is not None:
|
|
93
|
+
request["parameters"] = R.jsonable(dict(parameters))
|
|
94
|
+
return Call(request, parts.list, _result, timeout, path)
|
|
95
|
+
|
|
96
|
+
|
|
97
|
+
def import_(file: R.FileInput, file_name: Optional[str] = None, *, timeout=None, path=None, **rest: Any) -> Call:
|
|
98
|
+
R.refuse_unknown(rest, "import_report")
|
|
99
|
+
name = file_name if file_name is not None else R.file_name_of(file)
|
|
100
|
+
if not name:
|
|
101
|
+
raise TypeError("import_report() takes the file's name (its extension says its format)")
|
|
102
|
+
parts = R.Parts()
|
|
103
|
+
request = {"op": "import", "file": parts.add("file", R.read_file(file)), "fileName": name}
|
|
104
|
+
return Call(request, parts.list, _result, timeout, path)
|
|
105
|
+
|
|
106
|
+
|
|
107
|
+
def info(*, timeout=None) -> Call:
|
|
108
|
+
def read(answer: Answer) -> Dict[str, Any]:
|
|
109
|
+
return {k: v for k, v in answer.result.items() if k != "ok"}
|
|
110
|
+
|
|
111
|
+
return Call({"op": "info"}, [], read, timeout)
|
|
112
|
+
|
|
113
|
+
|
|
114
|
+
def raw(request: Mapping[str, Any], parts=(), *, timeout=None) -> Call:
|
|
115
|
+
if not isinstance(request, Mapping) or not isinstance(request.get("op"), str):
|
|
116
|
+
raise TypeError('a request is a mapping with an "op"')
|
|
117
|
+
return Call(dict(request), [(str(n), R.read_file(b)) for n, b in parts], lambda a: a, timeout)
|