Skip to content

Commit 8dbf492

Browse files
committed
add python paper muncher package
1 parent cd0f588 commit 8dbf492

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

54 files changed

+2659
-153
lines changed
19.2 KB
Binary file not shown.
16.2 KB
Binary file not shown.
3.7 KB
Binary file not shown.
2.47 KB
Binary file not shown.
27.2 KB
Binary file not shown.
Lines changed: 15 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,15 @@
1+
extensions = [
2+
"myst_parser",
3+
"sphinx.ext.autodoc",
4+
"sphinx.ext.napoleon",
5+
]
6+
extensions.append("sphinx_markdown_builder")
7+
source_suffix = {
8+
'.rst': 'restructuredtext',
9+
'.md': 'markdown',
10+
}
11+
master_doc = 'readme'
12+
exclude_patterns = [
13+
'examples.rst',
14+
'framework_examples.rst'
15+
]
Lines changed: 70 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,70 @@
1+
================
2+
Functional Usage
3+
================
4+
Paper Muncher includes both synchronous and asynchronous functional APIs.
5+
6+
.. literalinclude:: ../examples/sync_example.py
7+
:language: python
8+
:linenos:
9+
:lines: 1-13
10+
:caption: Synchronous example
11+
:name: sync_example
12+
13+
**N.B.** The synchronous API is based on a per-OS integration for IO timeouts.
14+
15+
#. For POSIX systems, it relies on `selectors`.
16+
#. For Windows with Python 3.12+, it puts the file in non-blocking mode.
17+
#. For Windows with Python < 3.12, it falls back to a potentially blocking read without timeout.
18+
19+
.. literalinclude:: ../examples/async_example.py
20+
:language: python
21+
:linenos:
22+
:lines: 1-13
23+
:caption: Asynchronous example
24+
:name: async_example
25+
26+
In addition to that it also includes a context based approach to automatically
27+
handle synchronous and asynchronous code execution.
28+
29+
.. literalinclude:: ../examples/auto_mode_example.py
30+
:language: python
31+
:linenos:
32+
:lines: 1-22
33+
:caption: Auto Switching example
34+
:name: auto_example
35+
36+
37+
=====================
38+
Context Manager Usage
39+
=====================
40+
Paper Muncher includes both synchronous and asynchronous context manager APIs.
41+
42+
.. literalinclude:: ../examples/sync_cm_example.py
43+
:language: python
44+
:linenos:
45+
:lines: 1-14
46+
:caption: Synchronous Context Manager example
47+
:name: sync_cm_example
48+
49+
**N.B.** The synchronous API is based on a per-OS integration for IO timeouts.
50+
51+
#. For POSIX systems, it relies on `selectors`.
52+
#. For Windows with Python 3.12+, it puts the file in non-blocking mode.
53+
#. For Windows with Python < 3.12, it falls back to a potentially blocking read without timeout.
54+
55+
.. literalinclude:: ../examples/async_cm_example.py
56+
:language: python
57+
:linenos:
58+
:lines: 1-15
59+
:caption: Asynchronous Context Manager example
60+
:name: async_cm_example
61+
62+
In addition to that it also includes a context based approach to automatically
63+
handle synchronous and asynchronous code execution.
64+
65+
.. literalinclude:: ../examples/auto_mode_cm_example.py
66+
:language: python
67+
:linenos:
68+
:lines: 1-26
69+
:caption: Auto Switching example
70+
:name: auto_cm_example
Lines changed: 66 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,66 @@
1+
Paper Muncher comes with pre-made integration with some
2+
of the most popular frameworks as well!
3+
4+
* Flask
5+
* Quart
6+
* Fast API
7+
* Django
8+
9+
Your favorite framework is not in the list?
10+
No worries! Some general implementation are also
11+
present!
12+
13+
* agnostic WSGI integration
14+
* agnostic ASGI integration
15+
16+
17+
=====
18+
Flask
19+
=====
20+
.. literalinclude:: ../examples/flask_example.py
21+
:language: python
22+
:linenos:
23+
:lines: 1-12
24+
:caption: Flask example
25+
:name: flask_example
26+
27+
=====
28+
Quart
29+
=====
30+
.. literalinclude:: ../examples/quart_example.py
31+
:language: python
32+
:linenos:
33+
:lines: 1-12
34+
:caption: Quart example
35+
:name: quart_example
36+
37+
=======
38+
FastAPI
39+
=======
40+
.. literalinclude:: ../examples/fastapi_example.py
41+
:language: python
42+
:linenos:
43+
:lines: 1-12
44+
:caption: Fast API example
45+
:name: fastapi_example
46+
47+
======
48+
Django
49+
======
50+
WSGI.
51+
52+
.. literalinclude:: ../examples/django_wsgi_example.py
53+
:language: python
54+
:linenos:
55+
:lines: 1-36
56+
:caption: Django (WSGI) example
57+
:name: django_wsgi_example
58+
59+
ASGI.
60+
61+
.. literalinclude:: ../examples/django_asgi_example.py
62+
:language: python
63+
:linenos:
64+
:lines: 1-39
65+
:caption: Django (ASGI) example
66+
:name: django_asgi_example
Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
Paper Muncher Python Bindings
2+
=============================
3+
4+
5+
Usage examples
6+
--------------
7+
.. include:: examples.rst
8+
.. include:: framework_examples.rst
Lines changed: 20 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,20 @@
1+
from paper_muncher.asynchronous import rendered
2+
3+
4+
html = """
5+
<h1>Hello, Paper Muncher!</h1>
6+
<p>This is a simple example of using Paper Muncher in an asynchronous context.</p>
7+
"""
8+
9+
10+
async def main():
11+
async with rendered(html, mode="print") as (pdf_stream_reader, std_err):
12+
pdf = await pdf_stream_reader.read()
13+
14+
with open("output_async.pdf", "wb") as f:
15+
f.write(pdf)
16+
17+
18+
if __name__ == "__main__":
19+
import asyncio
20+
asyncio.run(main())

0 commit comments

Comments
 (0)